Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7c979c9

Browse files
committed
Allocate all page images at once in generic wal interface
That reduces number of allocation. Per gripe from Michael Paquier and Tom Lane suggestion.
1 parent b09cd2e commit 7c979c9

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/backend/access/transam/generic_xlog.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ typedef struct
6161
/* State of generic xlog record construction */
6262
struct GenericXLogState
6363
{
64-
bool isLogged;
64+
/*
65+
* page's images. Should be first in this struct to have MAXALIGN'ed
66+
* images addresses, because some code working with pages directly aligns
67+
* addresses, not an offsets from begining of page
68+
*/
69+
char images[MAX_GENERIC_XLOG_PAGES * BLCKSZ];
6570
PageData pages[MAX_GENERIC_XLOG_PAGES];
71+
bool isLogged;
6672
};
6773

6874
static void writeFragment(PageData *pageData, OffsetNumber offset,
@@ -267,16 +273,11 @@ GenericXLogStart(Relation relation)
267273
int i;
268274

269275
state = (GenericXLogState *) palloc(sizeof(GenericXLogState));
270-
271276
state->isLogged = RelationNeedsWAL(relation);
277+
272278
for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
273279
{
274-
/*
275-
* pre-alloc page's images to prevent allocation in
276-
* GenericXLogRegisterBuffer() which could be called in different
277-
* memory context(s)
278-
*/
279-
state->pages[i].image = palloc(BLCKSZ);
280+
state->pages[i].image = state->images + BLCKSZ * i;
280281
state->pages[i].buffer = InvalidBuffer;
281282
}
282283

@@ -432,8 +433,6 @@ GenericXLogFinish(GenericXLogState *state)
432433
lsn = InvalidXLogRecPtr;
433434
}
434435

435-
for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
436-
pfree(state->pages[i].image);
437436
pfree(state);
438437

439438
return lsn;

0 commit comments

Comments
 (0)