chunk.diff

application/octet-stream

Filename: chunk.diff
Type: application/octet-stream
Part: 0
Message: Re: Bad COMPACT_ALLOC_CHUNK size in tsearch/spell.c?

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/tsearch/spell.c 1 1
src/backend/utils/mmgr/aset.c 7 1
diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c
index 8c0eaa7..bdbc913 100644
--- a/src/backend/tsearch/spell.c
+++ b/src/backend/tsearch/spell.c
@@ -75,7 +75,7 @@ NIFinishBuild(IspellDict *Conf)
  * doesn't need that.  The cpalloc and cpalloc0 macros are just documentation
  * to indicate which allocations actually require zeroing.
  */
-#define COMPACT_ALLOC_CHUNK 8192	/* must be > aset.c's allocChunkLimit */
+#define COMPACT_ALLOC_CHUNK 8192	
 #define COMPACT_MAX_REQ		1024	/* must be < COMPACT_ALLOC_CHUNK */
 
 static void *
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index e95dcb6..4289153 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -96,6 +96,7 @@
 #define ALLOC_MINBITS		3	/* smallest chunk size is 8 bytes */
 #define ALLOCSET_NUM_FREELISTS	11
 #define ALLOC_CHUNK_LIMIT	(1 << (ALLOCSET_NUM_FREELISTS-1+ALLOC_MINBITS))
+#define ALLOC_CHUNK_LIMIT_RATIO 8       /* chunk is at most 1/8 of maxBlockSize */
 /* Size of largest chunk that we use a fixed size for */
 
 /*--------------------
@@ -385,10 +386,15 @@ AllocSetContextCreate(MemoryContext parent,
 	 * allocChunkLimit a power of two, because the requested and
 	 * actually-allocated sizes of any chunk must be on the same side of the
 	 * limit, else we get confused about whether the chunk is "big".
+	 * 
+	 * In order to reduce wasted space in a malloc'd blocks, the allocation
+	 * chunk size limit is futher constrained to an eighth of the maxBlockSize,
+	 * so that for an 8k malloc block at most 1kb of space could be wasted.
 	 */
 	context->allocChunkLimit = ALLOC_CHUNK_LIMIT;
 	while (context->allocChunkLimit >
-		   (Size) (maxBlockSize - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ))
+		   ((Size) (maxBlockSize - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ) / 
+			ALLOC_CHUNK_LIMIT_RATIO ))
 		context->allocChunkLimit >>= 1;
 
 	/*