Skip to content

Commit 7215efd

Browse files
committed
Fix rare dsa_allocate() failures due to freepage.c corruption.
In a corner case, a btree page was allocated during a clean-up operation that could cause the tracking of the largest contiguous span of free space to get out of whack. That was supposed to be prevented by the use of the "soft" flag to avoid allocating internal pages during incidental clean-up work, but the flag was ignored in the case where the FPM was promoted from singleton format to btree format. Repair. Remove an obsolete comment in passing. Back-patch to 10, where freepage.c arrived (as support for dsa.c). Author: Robert Haas Diagnosed-by: Thomas Munro and Robert Haas Reported-by: Justin Pryzby, Rick Otten, Sand Stone, Arne Roland and others Discussion: https://postgr.es/m/CAMAYy4%2Bw3NTBM5JLWFi8twhWK4%3Dk_5L4nV5%2BbYDSPu8r4b97Zg%40mail.gmail.com
1 parent 75c4614 commit 7215efd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/backend/utils/mmgr/freepage.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,7 @@ FreePageManagerGetInternal(FreePageManager *fpm, Size npages, Size *first_page)
14701470
* pages; if false, do it always. Returns 0 if the soft flag caused the
14711471
* insertion to be skipped, or otherwise the size of the contiguous span
14721472
* created by the insertion. This may be larger than npages if we're able
1473-
* to consolidate with an adjacent range. *internal_pages_used is set to
1474-
* true if the btree allocated pages for internal purposes, which might
1475-
* invalidate the current largest run requiring it to be recomputed.
1473+
* to consolidate with an adjacent range.
14761474
*/
14771475
static Size
14781476
FreePageManagerPutInternal(FreePageManager *fpm, Size first_page, Size npages,
@@ -1526,6 +1524,8 @@ FreePageManagerPutInternal(FreePageManager *fpm, Size first_page, Size npages,
15261524

15271525
if (!relptr_is_null(fpm->btree_recycle))
15281526
root = FreePageBtreeGetRecycled(fpm);
1527+
else if (soft)
1528+
return 0; /* Should not allocate if soft. */
15291529
else if (FreePageManagerGetInternal(fpm, 1, &root_page))
15301530
root = (FreePageBtree *) fpm_page_to_pointer(base, root_page);
15311531
else

0 commit comments

Comments
 (0)