Commit 7c979c95 authored by Teodor Sigaev's avatar Teodor Sigaev

Allocate all page images at once in generic wal interface

That reduces number of allocation.

Per gripe from Michael Paquier and Tom Lane suggestion.
parent b09cd2e5
...@@ -61,8 +61,14 @@ typedef struct ...@@ -61,8 +61,14 @@ typedef struct
/* State of generic xlog record construction */ /* State of generic xlog record construction */
struct GenericXLogState 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]; PageData pages[MAX_GENERIC_XLOG_PAGES];
bool isLogged;
}; };
static void writeFragment(PageData *pageData, OffsetNumber offset, static void writeFragment(PageData *pageData, OffsetNumber offset,
...@@ -267,16 +273,11 @@ GenericXLogStart(Relation relation) ...@@ -267,16 +273,11 @@ GenericXLogStart(Relation relation)
int i; int i;
state = (GenericXLogState *) palloc(sizeof(GenericXLogState)); state = (GenericXLogState *) palloc(sizeof(GenericXLogState));
state->isLogged = RelationNeedsWAL(relation); state->isLogged = RelationNeedsWAL(relation);
for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++) for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
{ {
/* state->pages[i].image = state->images + BLCKSZ * 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].buffer = InvalidBuffer; state->pages[i].buffer = InvalidBuffer;
} }
...@@ -432,8 +433,6 @@ GenericXLogFinish(GenericXLogState *state) ...@@ -432,8 +433,6 @@ GenericXLogFinish(GenericXLogState *state)
lsn = InvalidXLogRecPtr; lsn = InvalidXLogRecPtr;
} }
for (i = 0; i < MAX_GENERIC_XLOG_PAGES; i++)
pfree(state->pages[i].image);
pfree(state); pfree(state);
return lsn; return lsn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment