Skip to content

Requested shared memory is always less than captured #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maksm90 opened this issue Mar 24, 2022 · 4 comments
Closed

Requested shared memory is always less than captured #41

maksm90 opened this issue Mar 24, 2022 · 4 comments

Comments

@maksm90
Copy link
Collaborator

maksm90 commented Mar 24, 2022

Starting from commit postgres/postgres@cdbc0ca48ca shared preload libraries are become to initialize before MaxBackends global variable setup. This might lead to invalid calculation of requested shared memory size if this calculation is based on max number of possible backend processes in postgres instance. For pg_wait_sampling module the size calculation of queryId shared memory follows this rule, i.e. it uses MaxBackends value. As result, for this shared memory fragment we request zero size (UPD. not zero but NUM_AUXILIARY_PROCS + max_prepared_xacts size) but later we assign non-zero memory (with already initialized MaxBackends value) for this purpose. Such behavior might incur future occurrences of out of shared memory errors.

The hackers thread have to help in finding of possible solution.

@rjuju
Copy link
Contributor

rjuju commented Mar 24, 2022

FTR I noticed this problem a few days ago, which is mostly why I sent this email. I was waiting for an agreement on a new hook on the mailing list to send a PR here.

Note that even with the new hook the memory requested during _PG_init will still be wrong on pre pg15 version, so I can send a patch for that already if you want (which would be computing what should be MaxBackends, even if it can be underestimated if later modules changes some GUC, as I'm already doing in e.g. https://github.com/powa-team/pg_stat_kcache/blob/master/pg_stat_kcache.c#L672-L673)

@maksm90
Copy link
Collaborator Author

maksm90 commented Mar 25, 2022

Hi @rjuju !

FTR I noticed this problem a few days ago, which is mostly why I sent this email. I was waiting for an agreement on a new hook on the mailing list to send a PR here.

Thanks for working on this.

Note that even with the new hook the memory requested during _PG_init will still be wrong on pre pg15 version, so I can send a patch for that already if you want (which would be computing what should be MaxBackends, even if it can be underestimated if later modules changes some GUC, as I'm already doing in e.g. https://github.com/powa-team/pg_stat_kcache/blob/master/pg_stat_kcache.c#L672-L673)

Yes, you can if this doesn't bother you.

@rjuju
Copy link
Contributor

rjuju commented Mar 25, 2022

Sure!

Note that we're now two people thinking that the current GetMaxBackends() approach doesn't provide a clean basis to fix this problem so I don't think that there will be something available in pg15 for entirely fix the problem.

@keremet
Copy link
Contributor

keremet commented Mar 31, 2022

merged 277a4e5

@keremet keremet closed this as completed Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants