pgsql: Add smgrzeroextend(), FileZero(), FileFallocate()

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add smgrzeroextend(), FileZero(), FileFallocate()
Date: 2023-04-05 17:27:12
Message-ID: E1pk6ud-001WhT-N8@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Add smgrzeroextend(), FileZero(), FileFallocate()

smgrzeroextend() uses FileFallocate() to efficiently extend files by multiple
blocks. When extending by a small number of blocks, use FileZero() instead, as
using posix_fallocate() for small numbers of blocks is inefficient for some
file systems / operating systems. FileZero() is also used as the fallback for
FileFallocate() on platforms / filesystems that don't support fallocate.

A big advantage of using posix_fallocate() is that it typically won't cause
dirty buffers in the kernel pagecache. So far the most common pattern in our
code is that we smgrextend() a page full of zeroes and put the corresponding
page into shared buffers, from where we later write out the actual contents of
the page. If the kernel, e.g. due to memory pressure or elapsed time, already
wrote back the all-zeroes page, this can lead to doubling the amount of writes
reaching storage.

There are no users of smgrzeroextend() as of this commit. That will follow in
future commits.

Reviewed-by: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Reviewed-by: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Reviewed-by: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>
Discussion: https://postgr.es/m/20221029025420.eplyow6k7tgu6he3@awork3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4d330a61bb1969df31f2cebfe1ba9d1d004346d8

Modified Files
--------------
src/backend/storage/file/fd.c | 88 ++++++++++++++++++++++++++++++++
src/backend/storage/smgr/md.c | 108 ++++++++++++++++++++++++++++++++++++++++
src/backend/storage/smgr/smgr.c | 28 +++++++++++
src/include/storage/fd.h | 3 ++
src/include/storage/md.h | 2 +
src/include/storage/smgr.h | 2 +
6 files changed, 231 insertions(+)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2023-04-05 17:45:48 pgsql: bufmgr: Add some more error checking [infrastructure] around pin
Previous Message Tom Lane 2023-04-05 16:56:51 pgsql: Fix another issue with ENABLE/DISABLE TRIGGER on partitioned tab

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2023-04-05 17:41:18 Re: Temporary tables versus wraparound... again
Previous Message Greg Stark 2023-04-05 17:26:53 Re: Temporary tables versus wraparound... again