@@ -61,8 +61,14 @@ typedef struct
6161/* State of generic xlog record construction */
6262struct 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 ];
6570PageData pages [MAX_GENERIC_XLOG_PAGES ];
71+ bool isLogged ;
6672};
6773
6874static void writeFragment (PageData * pageData ,OffsetNumber offset ,
@@ -267,16 +273,11 @@ GenericXLogStart(Relation relation)
267273int i ;
268274
269275state = (GenericXLogState * )palloc (sizeof (GenericXLogState ));
270-
271276state -> isLogged = RelationNeedsWAL (relation );
277+
272278for (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 ;
280281state -> pages [i ].buffer = InvalidBuffer ;
281282}
282283
@@ -432,8 +433,6 @@ GenericXLogFinish(GenericXLogState *state)
432433lsn = InvalidXLogRecPtr ;
433434}
434435
435- for (i = 0 ;i < MAX_GENERIC_XLOG_PAGES ;i ++ )
436- pfree (state -> pages [i ].image );
437436pfree (state );
438437
439438return lsn ;