Release the mapped memory at the end of PrepareHugePages()#7
Open
caims0315 wants to merge 2 commits into
Open
Conversation
added 2 commits
March 2, 2026 13:50
Key changes: - Refactor ShmemResizeStructInSegment() to verify internally: Instead of returning the shared memory location pointer for the caller to verify, the function now validates pointer consistency internally via a new helper VerifyAfterShmemUpdateInSegment(), which fatals on mismatch. - Align buffer block pointer before verification in ShmemResizeStructInSegment(): When the target segment is BUFFERS_SHMEM_SEGMENT, align the stored shared memory location pointer to PG_IO_ALIGN_SIZE (via TYPEALIGN) before passing it to the verification helper, matching the alignment applied during initial allocation. - Unify round_off_mapping_sizes() and round_off_mapping_sizes_for_hugepages() into a single round_off_mapping_sizes(): The merged function takes a pagesize parameter (rounds up both shmem_req_size and shmem_reserved to multiples of pagesize, no-op when pagesize is 0). After this change, round_off_mapping_sizes() is only invoked by BufferManagerShmemSize() (for non-main segments) and CalculateShmemSize() (for the main segment). - Refine BufferManagerShmemSize(): Introduce a padsize (header + spinlock aligned to PG_IO_ALIGN_SIZE) as the base offset for each segment's size calculation. For every segment except MAIN_SHMEM_SEGMENT, compute both shmem_req_size and shmem_reserved, then round off to both BLCKSZ and huge page size via round_off_mapping_sizes(). After this change, BufferManagerShmemSize() is only called from CalculateShmemSize() — the previous direct call in pg_resize_shared_buffers() is replaced with a CalculateShmemSize() call. - Refine CalculateShmemSize(): Round off MAIN_SHMEM_SEGMENT sizes to both BLCKSZ and huge page size via round_off_mapping_sizes(). - Parameterize PrepareHugePages(): Remove its internal CalculateShmemSize() call and local mapping_sizes array. The caller now passes pre-computed sizes. - Extract a new method UpdateShmemGUCs(Size size_b): It updates all internal configurations related with Shared Memory. This allows pg_resize_shared_buffers() to call it after a live shared memory resize. - Downgrade ftruncate failure in AnonymousShmemResize(): Change from ereport(ERROR) to elog(WARNING) + return false, making the failure non-fatal so the caller can handle it gracefully.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.