linux cachestat in file Readv and Prefetch

Started by Cédric Villemainover 2 years ago1 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t49055
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 06, 2026 at 08:02 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t49055_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t49055_1 && git checkout t49055_1

Patchset v1 (message #1) is on t49055_1

Jump to latest
#1Cédric Villemain
Cedric.Villemain@abcSQL.com

Hi,

I was testing the index prefetch and streamIO patches and I added
cachestat() syscall to get a better view of the prefetching.

It's a new linux syscall, it requires 6.5, it provides numerous
interesting information from the VM for the range of pages examined.
It's way way faster than the old mincore() and provides much more
valuable information:

    uint64 nr_cache;        /* Number of cached pages */
    uint64 nr_dirty;           /* Number of dirty pages */
    uint64 nr_writeback;  /* Number of pages marked for writeback. */
    uint64 nr_evicted;       /* Number of pages evicted from the cache. */
    /*
    * Number of recently evicted pages. A page is recently evicted if its
    * last eviction was recent enough that its reentry to the cache would
    * indicate that it is actively being used by the system, and that there
    * is memory pressure on the system.
    */
    uint64 nr_recently_evicted;

While here I also added some quick tweaks to suspend prefetching on
memory pressure.
It's working but I have absolutely not checked the performance impact of
my additions.

Sharing here for others to tests and adding in CF in case there is
interest to go further in this direction.

---
Cédric Villemain +33 (0)6 20 30 22 52
https://Data-Bene.io
PostgreSQL Expertise, Support, Training, R&D

Attachments:

t49055_1
v1-0001-Add-cachestat-requires-linux-6.5.patchtext/x-patch; charset=UTF-8; name=v1-0001-Add-cachestat-requires-linux-6.5.patchDownload+85-1