linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nhat Pham <nphamcs@gmail.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: hannes@cmpxchg.org
Subject: [RFC][PATCH 0/4] cachestat: a new syscall for page cache state of files
Date: Tue, 15 Nov 2022 10:28:57 -0800	[thread overview]
Message-ID: <20221115182901.2755368-1-nphamcs@gmail.com> (raw)

There is currently no good way to query the page cache state of large
file sets and directory trees. There is mincore(), but it scales poorly:
the kernel writes out a lot of bitmap data that userspace has to
aggregate, when the user really doesn not care about per-page information
in that case. The user also needs to mmap and unmap each file as it goes
along, which can be quite slow as well.

This series of patches introduces a new system call, cachestat, that
summarizes the page cache statistics (number of cached pages, dirty
pages, pages marked for writeback, evicted pages etc.) of a file, in a
specified range of bytes. It also include a selftest suite that tests some
typical usage

This interface is inspired by past discussion and concerns with fincore,
which has a similar design (and as a result, issues) as mincore.
Relevant links:

https://lkml.indiana.edu/hypermail/linux/kernel/1302.1/04207.html
https://lkml.indiana.edu/hypermail/linux/kernel/1302.1/04209.html

For comparison with mincore, I ran both syscalls on a 2TB sparse file:

Using mincore:
real    0m37.510s
user    0m2.934s
sys     0m34.558s

Using cachestat:
real    0m0.009s
user    0m0.000s
sys     0m0.009s

Mincore takes about 4000 times longer to obtain less aggregated
information!

Some open questions:

* What other fields might be useful?
* Huge pages: another useful stat to include is the number of huge pages
  cached. However, as the size of a huge page can vary, having just a
  single field is not very meaningful.
* An alternative would be to have one field for each possible size - but
  this is not future-proof, as bigger sizes might be introduced later.

Johannes Weiner (1):
  workingset: fix confusion around eviction vs refault container

Nhat Pham (3):
  workingset: refactor LRU refault to expose refault recency check
  cachestat: implement cachestat syscall
  selftests: Add selftests for cachestat

 MAINTAINERS                                   |   8 +
 arch/x86/entry/syscalls/syscall_32.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_64.tbl        |   1 +
 include/linux/swap.h                          |   1 +
 include/linux/syscalls.h                      |   2 +
 include/uapi/asm-generic/unistd.h             |   5 +-
 include/uapi/linux/mman.h                     |   8 +
 kernel/sys_ni.c                               |   1 +
 mm/Makefile                                   |   2 +-
 mm/cachestat.c                                | 109 +++++++++++
 mm/workingset.c                               | 142 +++++++++-----
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/cachestat/.gitignore  |   2 +
 tools/testing/selftests/cachestat/Makefile    |   9 +
 .../selftests/cachestat/test_cachestat.c      | 184 ++++++++++++++++++
 15 files changed, 430 insertions(+), 46 deletions(-)
 create mode 100644 mm/cachestat.c
 create mode 100644 tools/testing/selftests/cachestat/.gitignore
 create mode 100644 tools/testing/selftests/cachestat/Makefile
 create mode 100644 tools/testing/selftests/cachestat/test_cachestat.c

--
2.30.2


             reply	other threads:[~2022-11-15 18:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 18:28 Nhat Pham [this message]
2022-11-15 18:28 ` [PATCH 1/4] workingset: fix confusion around eviction vs refault container Nhat Pham
2022-11-15 18:28 ` [PATCH 2/4] workingset: refactor LRU refault to expose refault recency check Nhat Pham
2022-11-16  7:02   ` kernel test robot
2022-11-15 18:29 ` [PATCH 3/4] cachestat: implement cachestat syscall Nhat Pham
2022-11-16  5:51   ` kernel test robot
2022-11-16  7:02   ` kernel test robot
2022-11-16 11:55   ` kernel test robot
2022-11-21 14:45   ` Brian Foster
2022-11-21 15:55     ` Johannes Weiner
2022-11-15 18:29 ` [PATCH 4/4] selftests: Add selftests for cachestat Nhat Pham
2022-11-16 23:18 ` [RFC][PATCH 0/4] cachestat: a new syscall for page cache state of files Nhat Pham

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=20221115182901.2755368-1-nphamcs@gmail.com \
    --to=nphamcs@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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