pgsql: Process sync requests incrementally in AbsorbSyncRequests - Mailing list pgsql-committers

From Alexander Korotkov
Subject pgsql: Process sync requests incrementally in AbsorbSyncRequests
Date
Msg-id E1ug0PH-000yp4-30@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Process sync requests incrementally in AbsorbSyncRequests

If the number of sync requests is big enough, the palloc() call in
AbsorbSyncRequests() will attempt to allocate more than 1 GB of memory,
resulting in failure.  This can lead to an infinite loop in the checkpointer
process, as it repeatedly fails to absorb the pending requests.

This commit introduces the following changes to cope with this problem:
 1. Turn pending checkpointer requests array in shared memory into a bounded
    ring buffer.
 2. Limit maximum ring buffer size to 10M items.
 3. Make AbsorbSyncRequests() process requests incrementally in 10K batches.

Even #2 makes the whole queue size fit the maximum palloc() size of 1 GB.
of continuous lock holding.

This commit is for master only.  Simpler fix, which just limits a request
queue size to 10M, will be backpatched.

Reported-by: Ekaterina Sokolova <e.sokolova@postgrespro.ru>
Discussion: https://postgr.es/m/db4534f83a22a29ab5ee2566ad86ca92%40postgrespro.ru
Author: Maxim Orlov <orlovmg@gmail.com>
Co-authored-by:  Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/258bf0a2ea8ff86257f750018bfd44397ce7e554

Modified Files
--------------
src/backend/postmaster/checkpointer.c | 155 +++++++++++++++++++++++++---------
1 file changed, 114 insertions(+), 41 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Add assertions for all the required index AM callbacks
Next
From: Alexander Korotkov
Date:
Subject: pgsql: Limit checkpointer requests queue size