Hacking. aset_changes
authorRobert Haas <rhaas@postgresql.org>
Tue, 29 Dec 2015 01:08:48 +0000 (17:08 -0800)
committerRobert Haas <rhaas@postgresql.org>
Tue, 29 Dec 2015 01:08:48 +0000 (17:08 -0800)
src/backend/utils/mmgr/aset.c
src/include/utils/memutils.h

index e13072849d610b740f5a92ddb28ae60999dc7795..962eea350aac5952927c6ac6f7a8445c944baacb 100644 (file)
@@ -181,7 +181,7 @@ typedef struct AllocSetContext
        Size            maxBlockSize;   /* maximum block size */
        Size            nextBlockSize;  /* next block size to allocate */
        Size            allocChunkLimit;        /* effective chunk size limit */
-       AllocBlock      keeper;                 /* if not NULL, keep this block over resets */
+       AllocBlock      keeper;                 /* keep this block over resets */
 } AllocSetContext;
 
 typedef AllocSetContext *AllocSet;
@@ -210,19 +210,16 @@ typedef struct AllocBlockData
  * AllocChunk
  *             The prefix of each piece of memory in an AllocBlock
  *
- * NB: this MUST match StandardChunkHeader as defined by utils/memutils.h.
+ * NB: The last element of this structure MUST be a StandardChunkHeader.
  */
 typedef struct AllocChunkData
 {
-       /* aset is the owning aset if allocated, or the freelist link if free */
-       void       *aset;
-       /* size is always the size of the usable space in the chunk */
-       Size            size;
 #ifdef MEMORY_CONTEXT_CHECKING
        /* when debugging memory usage, also store actual requested size */
        /* this is zero in a free chunk */
        Size            requested_size;
 #endif
+       StandardChunkHeader     standard_header;
 }      AllocChunkData;
 
 /*
@@ -283,13 +280,11 @@ static const unsigned char LogTable256[256] =
 };
 
 /*
- * Whenever we allocate an AllocSetContext, we pad it out to 2kB and use
+ * Whenever we allocate an AllocSetContext, we pad it out to 1kB and use
  * the space not required by the context itself to store the context name
- * and the first few allocations.  (The AllocSetContext structure itself
- * is ~200 bytes, so making this only 1kB would leave barely any room for
- * actual allocations.)
+ * and the first few allocations.
  */
-#define ALLOCSET_PADDED_SIZE           2048
+#define ALLOCSET_PADDED_SIZE           1024
 typedef union AllocSetContextPadded
 {
        AllocSetContext context;
@@ -487,7 +482,7 @@ AllocSetContextCreate(MemoryContext parent,
        else if (AllocSetFreelist != NULL)
        {
                /*
-                * An ordinary AllocSetPadded is adequate for our purposes, and
+                * An ordinary AllocSetContextPadded is adequate for our purposes, and
                 * there's one available on the freelist.  Pop it off and use it!
                 * This is expected to be the normal case.
                 */
@@ -501,7 +496,7 @@ AllocSetContextCreate(MemoryContext parent,
                int             i;
 
                /*
-                * An ordinary AllocSetPadded is adequate for our purposes, but
+                * An ordinary AllocSetContextPadded is adequate for our purposes, but
                 * there aren't any on the freelist.  Allocate space for a bunch
                 * more contexts, put all but the first one on the freelist, and
                 * use the first one.  This will happen when creating
index 4d105793d9e69f703cfe76b1f4307cf69020e00c..597ffc9b56bdbf7c242fb017e66492c47d92146b 100644 (file)
@@ -68,9 +68,9 @@
  * On systems with 8-byte alignment, we allow 29 bits for the context ID and
  * 32 bits for the size.  This allows for up to half a billion context IDs and
  * sizes of up to 1 byte less than 4GB.  Thus, extended headers should
- * almost never be required.  On systems with 4-byte alignment, we allow 11
- * bits for the context ID and 18 bits for the size, which allows for up to
- * 2048 possible context IDs and allocations of up to 1 byte less than 256kB.
+ * almost never be required.  On systems with 4-byte alignment, we allow 20
+ * bits for the context ID and 19 bits for the size, which allows for up to
+ * 1 million possible context IDs and allocations of up to 511 bytes.
  * This should be good enough that most allocations won't need an extended
  * header, but some will.
  */
@@ -81,8 +81,8 @@ typedef uint64 chunk_unsigned;
 #define CHUNK_SIZE_BITS                                32
 #else
 typedef uint32 chunk_unsigned;
-#define CHUNK_CONTEXT_ID_BITS          11
-#define CHUNK_SIZE_BITS                                18
+#define CHUNK_CONTEXT_ID_BITS          20
+#define CHUNK_SIZE_BITS                                9
 #endif
 
 /* Context type codes; must be less than 1 << CHUNK_CONTEXT_TYPE_BITS. */