Make slab allocator work on platforms with MAXIMUM_ALIGNOF < sizeof(int).
authorHeikki Linnakangas
Thu, 18 May 2017 19:22:13 +0000 (22:22 +0300)
committerHeikki Linnakangas
Thu, 18 May 2017 19:22:13 +0000 (22:22 +0300)
Notably, m68k only needs 2-byte alignment. Per report from Christoph Berg.

Discussion: https://www.postgresql.org/message-id/20170517193957[email protected]

src/backend/utils/mmgr/slab.c

index 0fcfcb4c786e2b2f1046258470fbf0479f004ed5..e59154ddda4bd113e056463740c07a200cbef80a 100644 (file)
@@ -194,9 +194,9 @@ SlabContextCreate(MemoryContext parent,
                     MAXALIGN(sizeof(SlabChunk)),
                     "padding calculation in SlabChunk is wrong");
 
-   /* otherwise the linked list inside freed chunk isn't guaranteed to fit */
-   StaticAssertStmt(MAXIMUM_ALIGNOF >= sizeof(int),
-                    "MAXALIGN too small to fit int32");
+   /* Make sure the linked list node fits inside a freed chunk */
+   if (chunkSize < sizeof(int))
+       chunkSize = sizeof(int);
 
    /* chunk, including SLAB header (both addresses nicely aligned) */
    fullChunkSize = MAXALIGN(sizeof(SlabChunk) + MAXALIGN(chunkSize));