mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix relptr's encoding of the base address.
Previously, we encoded both NULL and the first byte at the base address as 0. That confusion led to the assertion in commite07d4ddc
, which failed when min_dynamic_shared_memory was used. Give them distinct encodings, by switching to 1-based offsets for non-NULL pointers. Also improve macro hygiene in passing (missing/misplaced parentheses), and remove open-coded access to the raw offset value from freepage.c/h. Althoughe07d4ddc
was back-patched to 10, the only code that actually makes use of relptr at the base address arrived in84b1c63a
, so no need to back-patch further than 14 for now. Reported-by: Justin Pryzby <pryzby@telsasoft.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/20220519193839.GT19626%40telsasoft.com
This commit is contained in:
@ -434,7 +434,7 @@ FreePageManagerDump(FreePageManager *fpm)
|
||||
|
||||
/* Dump general stuff. */
|
||||
appendStringInfo(&buf, "metadata: self %zu max contiguous pages = %zu\n",
|
||||
fpm->self.relptr_off, fpm->contiguous_pages);
|
||||
relptr_offset(fpm->self), fpm->contiguous_pages);
|
||||
|
||||
/* Dump btree. */
|
||||
if (fpm->btree_depth > 0)
|
||||
@ -1269,7 +1269,7 @@ FreePageManagerDumpBtree(FreePageManager *fpm, FreePageBtree *btp,
|
||||
if (btp->hdr.magic == FREE_PAGE_INTERNAL_MAGIC)
|
||||
appendStringInfo(buf, " %zu->%zu",
|
||||
btp->u.internal_key[index].first_page,
|
||||
btp->u.internal_key[index].child.relptr_off / FPM_PAGE_SIZE);
|
||||
relptr_offset(btp->u.internal_key[index].child) / FPM_PAGE_SIZE);
|
||||
else
|
||||
appendStringInfo(buf, " %zu(%zu)",
|
||||
btp->u.leaf_key[index].first_page,
|
||||
@ -1859,7 +1859,7 @@ FreePagePopSpanLeader(FreePageManager *fpm, Size pageno)
|
||||
{
|
||||
Size f = Min(span->npages, FPM_NUM_FREELISTS) - 1;
|
||||
|
||||
Assert(fpm->freelist[f].relptr_off == pageno * FPM_PAGE_SIZE);
|
||||
Assert(relptr_offset(fpm->freelist[f]) == pageno * FPM_PAGE_SIZE);
|
||||
relptr_copy(fpm->freelist[f], span->next);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user