The issue was closed on the grounds of usefulness. I think CPython should generally defer to the OS developers’ judgment here. These flags go through significant review before being added to the kernel’s stable ABI.
Use case
The motivation for RWF_DONTCACHE is documented in mm/filemap: add read support for RWF_DONTCACHE - wireguard-linux - WireGuard for the Linux kernel . The problem: when reading large amounts of data through buffered I/O, the page cache fills up and triggers aggressive kswapd reclaim. Performance degrades from ~155 MB/s to ~70-95 MB/s, with multiple kswapd threads consuming near 100% CPU.
With RWF_DONTCACHE, pages are pruned from cache after reading. This maintains consistent ~155 MB/s throughput with roughly half the CPU usage.
My own use case is scientific microscopy imaging, where datasets routinely exceed available RAM and are read sequentially for processing. This pattern (large sequential reads that won’t benefit from caching) is common across ML pipelines as well.
Precedent
CPython already exposes RWF_DSYNC, RWF_HIPRI, RWF_SYNC, and RWF_NOWAIT in the os module for use with preadv/pwritev. Adding RWF_DONTCACHE and RWF_ATOMIC follows the same pattern.
Current workaround
Without stdlib support, the alternative is calling preadv2 via ctypes/cffi and defining the constants manually.
With that in mind, would you accept a PR that exposes RWF_DONTCACHE (Linux 6.14+) and RWF_ATOMIC (Linux 6.13+)?
It seems like a clear policy on how and when to adopt these constants would make sense, so that whether adding or rejecting a request to add, there’s just a document you can point to to say it is (or is not) time. If documentation is a blocker, this could encourage motivated Python users to improve Linux docs.
The docs were only part of my concern in the original PR. At the time of GH-127922, CPython would have been basically the only project that used RWF_ATOMIC, and I didn’t think that was good for our low-maintenance policy. That’s no longer the case.
Anyways, I just merged GH-143475, so os.RWF_ATOMIC will be in Python 3.15.