Thread: Too much memory allocated for ReorderBufferDiskChange

Too much memory allocated for ReorderBufferDiskChange

From
Antonin Houska
Date:
I suggest the following change to avoid excessive
allocation. sizeof(ReorderBufferDiskChange) should already be contained in
ondisk->size.

diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
new file mode 100644
index c72a611..84f6e05
*** a/src/backend/replication/logical/reorderbuffer.c
--- b/src/backend/replication/logical/reorderbuffer.c
*************** ReorderBufferRestoreChanges(ReorderBuffe
*** 2366,2373 ****

          ondisk = (ReorderBufferDiskChange *) rb->outbuf;

!         ReorderBufferSerializeReserve(rb,
!                                       sizeof(ReorderBufferDiskChange) + ondisk->size);
          ondisk = (ReorderBufferDiskChange *) rb->outbuf;

          pgstat_report_wait_start(WAIT_EVENT_REORDER_BUFFER_READ);
--- 2366,2372 ----

          ondisk = (ReorderBufferDiskChange *) rb->outbuf;

!         ReorderBufferSerializeReserve(rb, ondisk->size);
          ondisk = (ReorderBufferDiskChange *) rb->outbuf;

          pgstat_report_wait_start(WAIT_EVENT_REORDER_BUFFER_READ);

--
Antonin Houska
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26, A-2700 Wiener Neustadt
Web: https://www.cybertec-postgresql.com


Re: Too much memory allocated for ReorderBufferDiskChange

From
Euler Taveira
Date:
2018-03-05 12:26 GMT-03:00 Antonin Houska <ah@cybertec.at>:
> !               ReorderBufferSerializeReserve(rb,
> !                                                                         sizeof(ReorderBufferDiskChange) +
ondisk->size);
>                 ondisk = (ReorderBufferDiskChange *) rb->outbuf;
>
ReorderBufferSerializeReserve() always does a repalloc here
(ReorderBufferDiskChange size is always greater than zero) then the
allocation size is correct.


-- 
   Euler Taveira                                   Timbira -
http://www.timbira.com.br/
   PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento