Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Allocate all page images at once in generic wal interface
authorTeodor Sigaev <teodor@sigaev.ru>
Tue, 17 May 2016 19:09:22 +0000 (22:09 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Tue, 17 May 2016 19:09:22 +0000 (22:09 +0300)
That reduces number of allocation.

Per gripe from Michael Paquier and Tom Lane suggestion.

src/backend/access/transam/generic_xlog.c

index 8ad69f83b1f74caee11b357c891eac0cd481cc1d..ae874cc50d4d37092bb4aa242606cb9ff805f03f 100644 (file)
@@ -61,8 +61,14 @@ typedef struct
 /* State of generic xlog record construction */
 struct GenericXLogState
 {
-   bool        isLogged;
+   /*
+    * page's images. Should be first in this struct to have MAXALIGN'ed
+    * images addresses, because some code working with pages directly aligns
+    * addresses, not an offsets from begining of page
+    */
+   char        images[MAX_GENERIC_XLOG_PAGES * BLCKSZ];
    PageData    pages[MAX_GENERIC_XLOG_PAGES];
+   bool        isLogged;
 };
 
 static void writeFragment(PageData *pageData, OffsetNumber offset,
@@ -267,16 +273,11 @@ GenericXLogStart(Relation relation)
    int         i;
 
    state = (GenericXLogState *) palloc(sizeof(GenericXLogState));
-
    state->isLogged = RelationNeedsWAL(relation);
+
    for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
    {
-       /*
-        * pre-alloc page's images to prevent allocation in
-        * GenericXLogRegisterBuffer() which could be called in different
-        * memory context(s)
-        */
-       state->pages[i].image = palloc(BLCKSZ);
+       state->pages[i].image = state->images + BLCKSZ * i;
        state->pages[i].buffer = InvalidBuffer;
    }
 
@@ -432,8 +433,6 @@ GenericXLogFinish(GenericXLogState *state)
        lsn = InvalidXLogRecPtr;
    }
 
-   for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
-       pfree(state->pages[i].image);
    pfree(state);
 
    return lsn;