|
58 | 58 | #include "utils/memutils_memorychunk.h"
|
59 | 59 | #include "utils/memutils_internal.h"
|
60 | 60 |
|
| 61 | +#define Slab_BLOCKHDRSZ MAXALIGN(sizeof(SlabBlock)) |
| 62 | + |
61 | 63 | /*
|
62 | 64 | * SlabContext is a specialized implementation of MemoryContext.
|
63 | 65 | */
|
@@ -102,10 +104,10 @@ typedef struct SlabBlock
|
102 | 104 | #define SlabChunkGetPointer(chk) \
|
103 | 105 | ((void *)(((char *)(chk)) + sizeof(MemoryChunk)))
|
104 | 106 | #define SlabBlockGetChunk(slab, block, idx) \
|
105 |
| - ((MemoryChunk *) ((char *) (block) + sizeof(SlabBlock) \ |
| 107 | + ((MemoryChunk *) ((char *) (block) + Slab_BLOCKHDRSZ \ |
106 | 108 | + (idx * slab->fullChunkSize)))
|
107 | 109 | #define SlabBlockStart(block) \
|
108 |
| - ((char *) block + sizeof(SlabBlock)) |
| 110 | + ((char *) block + Slab_BLOCKHDRSZ) |
109 | 111 | #define SlabChunkIndex(slab, block, chunk) \
|
110 | 112 | (((char *) chunk - SlabBlockStart(block)) / slab->fullChunkSize)
|
111 | 113 |
|
@@ -146,12 +148,12 @@ SlabContextCreate(MemoryContext parent,
|
146 | 148 | fullChunkSize = Slab_CHUNKHDRSZ + MAXALIGN(chunkSize);
|
147 | 149 |
|
148 | 150 | /* Make sure the block can store at least one chunk. */
|
149 |
| - if (blockSize < fullChunkSize + sizeof(SlabBlock)) |
| 151 | + if (blockSize < fullChunkSize + Slab_BLOCKHDRSZ) |
150 | 152 | elog(ERROR, "block size %zu for slab is too small for %zu chunks",
|
151 | 153 | blockSize, chunkSize);
|
152 | 154 |
|
153 | 155 | /* Compute maximum number of chunks per block */
|
154 |
| - chunksPerBlock = (blockSize - sizeof(SlabBlock)) / fullChunkSize; |
| 156 | + chunksPerBlock = (blockSize - Slab_BLOCKHDRSZ) / fullChunkSize; |
155 | 157 |
|
156 | 158 | /* The freelist starts with 0, ends with chunksPerBlock. */
|
157 | 159 | freelistSize = sizeof(dlist_head) * (chunksPerBlock + 1);
|
@@ -744,7 +746,7 @@ SlabCheck(MemoryContext context)
|
744 | 746 |
|
745 | 747 | /* there might be sentinel (thanks to alignment) */
|
746 | 748 | if (slab->chunkSize < (slab->fullChunkSize - Slab_CHUNKHDRSZ))
|
747 |
| - if (!sentinel_ok(chunk, slab->chunkSize)) |
| 749 | + if (!sentinel_ok(chunk, Slab_CHUNKHDRSZ + slab->chunkSize)) |
748 | 750 | elog(WARNING, "problem in slab %s: detected write past chunk end in block %p, chunk %p",
|
749 | 751 | name, block, chunk);
|
750 | 752 | }
|
|
0 commit comments