public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Steve <steve_iouring_list@shic.co.uk>
To: io-uring@vger.kernel.org
Subject: Relationship between io-uring asynchronous idioms and mmap/LRU paging.
Date: Fri, 11 Jul 2025 19:12:49 +0100	[thread overview]
Message-ID: <a11e741c-458f-4343-8f68-28ecc151cb34@shic.co.uk> (raw)

I hope my post is appropriate for this list. Relative to other recent 
posts on this list, my interests are high-level.

I want to develop efficient, scalable, low-latency, asynchronous 
services in user-space. I've dabbled with liburing in the context of an 
experimental service involving network request/responses.  For the 
purpose of this post, assume calculating responses, to requests, 
requires looking-up pages in a huge read-only file.  In order to reap 
all the performance benefits of io-uring, I know I should avoid blocking 
calls in my event loop.

If I were to use a multithreaded (c.f. asynchronous) paradigm... my 
strategy, to look-up pages, would have been to mmap 
<https://man7.org/linux/man-pages/man2/mmap.2.html> the huge file and 
rely upon the kernel LRU cache. Cache misses, relative to the memory 
mapped file will result in a page fault and a blocked thread. This could 
be OK, if cache-misses are rare events... but, while cache hits are 
expected to be frequent, I can't assume cache misses will be rare.

Options I have considered:

   1. Introduce a thread-pool, with task-request and task-response 
queues... using tasks to de-couple reading requests from writing 
responses... the strategy would be to avoid the io-uring event loop 
thread interacting with the memory mapped file. Intuitively, this seems 
cumbersome - compared with using a 'more asynchronous' idiom to avoid 
having to depend upon multithreaded concurrency and thread synchronisation.

   2. Implement an explicit application-layer page cache. Pages could be 
retrieved, into explicitly allocated memory, asynchronously... using 
io-uring read requests. I could suspend request/response processing on 
any cache miss... then resume processing when the io-uring completion 
queue informs that each page has been loaded.  A C++20 coroutine, for 
example, could allow this asynchronous suspension and resumption of 
calculation of responses to requests. This approach seems to undermine 
resource-use cooperation between processes. A single page on disk could 
end-up cached separately by each process instance (inefficient) and 
there would be difficulties efficiently managing appropriate sizes for 
application layer caches.

In an ideal world, I would like to fuse the benefits of mmap's 
kernel-managed cache, with the advantages of an io-uring asynchronous 
idiom.  I find myself wishing there were kernel-level APIs to:

   * Determine if a page, at a virtual address, is already cached in 
RAM. [ Perhaps mincore() 
<https://man7.org/linux/man-pages/man2/mincore.2.html> could be adequate? ]
   * Submit an asynchronous io-uring request with comparable (but 
non-blocking) effect to a page-fault for the virtual address whose page 
was not in core.
   * Receive notification, on the io-uring completion queue, that an 
requested page has now been cached.

If such facilities were to exist, I can imagine a process, using 
io-uring asynchronous idioms, that retains the memory management 
advantages associated with mmap... without introducing dependence upon 
threads.  I've not found any documentation to suggest that my imagined 
io-uring features exist.  Am I overlooking something? Are there plans to 
implement asynchronous features involving the kernel page-cache and 
io-uring scheduling?  Would io-uring experts consider option 1 a 
sensible, pragmatic, choice... in a circumstance where kernel-level 
caching of the mapped file seems desirable... or would a different 
approach be more appropriate?

Thanks in advance for any comments.

Steve



             reply	other threads:[~2025-07-11 18:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-11 18:12 Steve [this message]
2025-07-17 14:50 ` Relationship between io-uring asynchronous idioms and mmap/LRU paging Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a11e741c-458f-4343-8f68-28ecc151cb34@shic.co.uk \
    --to=steve_iouring_list@shic.co.uk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox