Skip to content

Commit 06fb561

Browse files
committed
Increase io_combine_limit range to 1MB.
The default of 128kB is unchanged, but the upper limit is changed from 32 blocks to 128 blocks, unless the operating system's IOV_MAX is too low. Some other RDBMSes seem to cap their multi-block buffer pool I/O around this number, and it seems useful to allow experimentation. The concrete change is to our definition of PG_IOV_MAX, which provides the maximum for io_combine_limit and io_max_combine_limit. It also affects a couple of other places that work with arrays of struct iovec or smaller objects on the stack, so we still don't want to use the system IOV_MAX directly without a clamp: it is not under our control and likely to be 1024. 128 seems acceptable for our current usage. For Windows, we can't use real scatter/gather yet, so we continue to define our own IOV_MAX value of 16 and emulate preadv()/pwritev() with loops. Someone would need to research the trade-offs of raising that number. NB if trying to see this working: you might temporarily need to hack BAS_BULKREAD to be bigger, since otherwise the obvious way of "a very big SELECT" is limited by that for now. Suggested-by: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/CA%2BhUKG%2B2T9p-%2BzM6Eeou-RAJjTML6eit1qn26f9twznX59qtCA%40mail.gmail.com
1 parent 10f6646 commit 06fb561

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

doc/src/sgml/config.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,8 @@ include_dir 'conf.d'
26382638
This parameter can only be set in
26392639
the <filename>postgresql.conf</filename> file or on the server
26402640
command line.
2641+
The maximum possible size depends on the operating system and block
2642+
size, but is typically 1MB on Unix and 128kB on Windows.
26412643
The default is 128kB.
26422644
</para>
26432645
</listitem>
@@ -2655,6 +2657,8 @@ include_dir 'conf.d'
26552657
higher than the <varname>io_max_combine_limit</varname> parameter, the
26562658
lower value will silently be used instead, so both may need to be raised
26572659
to increase the I/O size.
2660+
The maximum possible size depends on the operating system and block
2661+
size, but is typically 1MB on Unix and 128kB on Windows.
26582662
The default is 128kB.
26592663
</para>
26602664
</listitem>

src/backend/storage/aio/read_stream.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,10 @@ read_stream_begin_impl(int flags,
515515
* finishes we don't want to have to wait for its buffers to be consumed
516516
* before starting a new one.
517517
*
518-
* Be careful not to allow int16 to overflow (even though that's not
519-
* possible with the current GUC range limits), allowing also for the
520-
* spare entry and the overflow space.
518+
* Be careful not to allow int16 to overflow. That is possible with the
519+
* current GUC range limits, so this is an artificial limit of ~32k
520+
* buffers and we'd need to adjust the types to exceed that. We also have
521+
* to allow for the spare entry and the overflow space.
521522
*/
522523
max_pinned_buffers = (max_ios + 1) * io_combine_limit;
523524
max_pinned_buffers = Min(max_pinned_buffers,

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@
200200
#backend_flush_after = 0 # measured in pages, 0 disables
201201
#effective_io_concurrency = 16 # 1-1000; 0 disables prefetching
202202
#maintenance_io_concurrency = 16 # 1-1000; 0 disables prefetching
203-
#io_max_combine_limit = 128kB # usually 1-32 blocks (depends on OS)
203+
#io_max_combine_limit = 128kB # usually 1-128 blocks (depends on OS)
204204
# (change requires restart)
205-
#io_combine_limit = 128kB # usually 1-32 blocks (depends on OS)
205+
#io_combine_limit = 128kB # usually 1-128 blocks (depends on OS)
206206

207207
#io_method = worker # worker, sync (change requires restart)
208208
#io_max_concurrency = -1 # Max number of IOs that one process

src/include/port/pg_iovec.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ struct iovec
3333

3434
#endif
3535

36-
/* Define a reasonable maximum that is safe to use on the stack. */
37-
#define PG_IOV_MAX Min(IOV_MAX, 32)
36+
/*
37+
* Define a reasonable maximum that is safe to use on the stack in arrays of
38+
* struct iovec and other small types. The operating system could limit us to
39+
* a number as low as 16, but most systems have 1024.
40+
*/
41+
#define PG_IOV_MAX Min(IOV_MAX, 128)
3842

3943
/*
4044
* Like preadv(), but with a prefix to remind us of a side-effect: on Windows

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy