From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE84BC54E76 for ; Tue, 17 Jan 2023 20:00:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 686926B0071; Tue, 17 Jan 2023 15:00:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 636D16B0073; Tue, 17 Jan 2023 15:00:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FE746B0074; Tue, 17 Jan 2023 15:00:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3DE136B0071 for ; Tue, 17 Jan 2023 15:00:04 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BFDCAAB00E for ; Tue, 17 Jan 2023 20:00:03 +0000 (UTC) X-FDA: 80365357086.06.2CC2E6D Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf17.hostedemail.com (Postfix) with ESMTP id 0A21E40014 for ; Tue, 17 Jan 2023 20:00:01 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TOJ8RxU1; spf=pass (imf17.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673985602; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=BAp2EKRgDOs4iHu5RgRGiM7hj51I7MR1ml/nzO8MP4Y=; b=Zkzh2AyMOpuFFHkGkq1Lip5/+DzeEiTL3DPyB7jClZruPxmz+l7Q4RQ7fRCvsgOxIKJtxN 8+yyzyIaZimtvqYKg3OkAQpjOH+eHolWAc4JC0jSyRQHx/jql3sHd2o+bfJwzRI+1rUxBS QaE/X5oqiVhp/i6Q+nvZWsSO1lSUXS4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TOJ8RxU1; spf=pass (imf17.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673985602; a=rsa-sha256; cv=none; b=CaXM1fWga3m5qKjDxk7d1kidOlbj9tyBYTB8QJV4z7H9CiEsW/k4Iu/FK3pDFuk+p5RZiD I4v7mAgYVaCLjU7XUmzAF66Br53VRYrPTCOKyoFlFmQHWtcPqtr3KkrX5T5RKXb2S9NjxD kwcSgFAvDxKuOKMMXhL1G7RnIYdpXl4= Received: by mail-pl1-f171.google.com with SMTP id d3so34637612plr.10 for ; Tue, 17 Jan 2023 12:00:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BAp2EKRgDOs4iHu5RgRGiM7hj51I7MR1ml/nzO8MP4Y=; b=TOJ8RxU1vwAH9vUn0euq3FQj/Ko+Ps6G451wmItbBTJwNZIh6LhUtdPsoVJSs0jJmN E++sVFWu8N5cQK/hWcfV4gZ3UFtYPf1iENHvutRMZ8x4iVWqvQa623NyMSTsbjCTbm0m LkQE6jrSyccNSO8IwDaBgmW7GbgB5/Zlf2eiUbFCqttibCX8KJ+NnYWNCDAMFPYVmPZo hGcItV2ERpgx3OaZ6mUwBjR2Esu4oOFrV+2Fn0X9oOln1IBrEfPuO+N7okuHRjid5pqJ F2C7f87DiDhwI1PbUKzgpZ69kRah8uiC+teomRT5g06H4TPAe3D6UqwHjFqPsWrb8lSa YsBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BAp2EKRgDOs4iHu5RgRGiM7hj51I7MR1ml/nzO8MP4Y=; b=OCO6XDD8upUDuLc00FDKPDPb8FMuqGS8gA2x06cRV5ELwhn/y0MTs6MC70d0gWaXox imsWy+jFK113pmQvFRUc9lHM8WlWOqeCHxCEA50V/17Zb/Rq6QziRdfwsdBARF2oO6Ro CSFRjjnQlSZZKVa49EF1QCBtNqjd+N9/EujCrpT+xViZEvH6MZFjn9YxDjCWByelYmGr CniVkqapy2I4tyMeqEkefyhfH3gKteRVS1SVWKoB1RCtBaRk36frCC9SNlplP3pj+2/H s0nxJfkmLMhR+rBYZXXBoulLQALD2Q/SYiYsmjFhYZPYybcDuUdBB1jspvy1xmrpjo2o CddA== X-Gm-Message-State: AFqh2krmiG+is2zhDNs5BNWL+QF5rLlWme0ORl1Thcp3UpKUnriH+js7 XnqK4o1PpC+HioqX/UFiO4s= X-Google-Smtp-Source: AMrXdXvvggDDhjlW7v4AlJLAyjNAccQgvIcdv518lelDzuRFDWb9hH+YlAMKmJ8S9B/QfRF1xEp8Nw== X-Received: by 2002:a17:902:eb8b:b0:194:6103:1e18 with SMTP id q11-20020a170902eb8b00b0019461031e18mr4792977plg.65.1673985600774; Tue, 17 Jan 2023 12:00:00 -0800 (PST) Received: from localhost (fwdproxy-prn-014.fbsv.net. [2a03:2880:ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id i1-20020a17090332c100b0019462aa090bsm1681766plr.284.2023.01.17.12.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 12:00:00 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bfoster@redhat.com, willy@infradead.org, linux-api@vger.kernel.org, kernel-team@meta.com Subject: [PATCH v6 0/3] cachestat: a new syscall for page cache state of files Date: Tue, 17 Jan 2023 11:59:56 -0800 Message-Id: <20230117195959.29768-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 8tnbyn4x3w18h7gqwweuhkjmu8yszq3y X-Rspam-User: X-Rspamd-Queue-Id: 0A21E40014 X-Rspamd-Server: rspam06 X-HE-Tag: 1673985601-373038 X-HE-Meta: U2FsdGVkX1/DXYgvdbOGyU59WJxcGxdFLhm8QW3EFUEXCHlT7S1OvGBlEq/YmhskDsw98tb7FDELM+BH2HdQaDj2Ugagq6FY2sdnetDOzcD/AavmR2VPvPKwnjKmGFg+ps+Rw2zPGHC/2KcrBXK9ekh/hoFILcRIywLaCGLdBwiZXWYez5jKZm1+hqBGrIxv31GohqqS71C4BW8IqGIGNgyVxsuwS26VkM7pICEF9UBbTzfPd+w9KQAGuQf67QWCEe/8gITb7x9QLf/ViPwdOObL8uYr5ns3ZVvjYZDgAkDIOr8OXDVC/e6FtgmfLoBedUnfIuBRLMeUozlVfkkCj9e/5ppaeKQ8t/t6bYNmBokFi5Gzt4ty+BhLTmOrpXn9HMOX90XwVmcSMqGA9lWSZz8tyGjjPCpm4HduX7S6VMEa0boO/p42jfPfMGx7haLGuhfWq5/v477QHzgfjQPGYJguXUYNQ2k8hpeGDrl3fyqJ7ODnNrwcd+5oGTKr1mgxFG5Q2rqnUcf0/0DzHQnWAfhnGfuz1E9r+3Sy0XLORxtdbvYSYTtgR8Ee8LfMlx+Z1JvjEth8JMTlr4srfQ8PJ7KTPEDEXP4yY4u9rustepQweT6bNebaeSCZelyRmuTM3f9ys4UWb0HwQDwWhbhIgkJWpEV5sILxVrMkAw3BNDHZDNN4sn/pUv8Qc3Ykmi0h7p3KaTfc0iEu1iEHx1k7Kvr33KZo79D37FMlpFjl8KpY1zpivcbMTUG+f+pGYXzbh77SWsiIwyI/m0pU4/6d+g9iEluoUzXLXNTuPhJl9m/QAUQLIl8zfRVUgX1Ly35j1LQpZM5VoCTKza3tC/c38l2HrcxGqzQ6nnTES2qsOEhdki9dm3HhG/PoFKljvnr77j98J9+EvZxLB2zZODs01zMkLUtyydqwv0XdDcOn9zZv3uB7JpYHIVowfgR7we3gXXtxgQ7qXOGjXxJvIBn ySPIeWZp QcFTBRhl/guPlDVYiziceAVUAjHKeJWlVnYWC/TxyJxq3bNfXDSJ0/RX/hq7/yMp8SGDSrFwIHh6W8yn9bYsTE8E6o/+nA7uIdAMH91qPyJAdEJbLq1laEXoiGLWnOgCfFHoC X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Changelog: v6: * Add a missing fdput() (suggested by Brian Foster) (patch 2) * Replace cstat_size with cstat_version (suggested by Brian Foster) (patch 2) * Add conditional resched to the xas walk. (suggested by Hillf Danton) (patch 2) v5: * Separate first patch into its own series. (suggested by Andrew Morton) * Expose filemap_cachestat() to non-syscall usage (patch 2) (suggested by Brian Foster). * Fix some build errors from last version. (patch 2) * Explain eviction and recent eviction in the draft man page and documentation (suggested by Andrew Morton). (patch 2) v4: * Refactor cachestat and move it to mm/filemap.c (patch 3) (suggested by Brian Foster) * Remove redundant checks (!folio, access_ok) (patch 3) (suggested by Matthew Wilcox and Al Viro) * Fix a bug in handling multipages folio. (patch 3) (suggested by Matthew Wilcox) * Add a selftest for shmem files, which can be used to test huge pages (patch 4) (suggested by Johannes Weiner) v3: * Fix some minor formatting issues and build errors. * Add the new syscall entry to missing architecture syscall tables. (patch 3). * Add flags argument for the syscall. (patch 3). * Clean up the recency refactoring (patch 2) (suggested by Yu Zhao) * Add the new Kconfig (CONFIG_CACHESTAT) to disable the syscall. (patch 3) (suggested by Josh Triplett) v2: * len == 0 means query to EOF. len < 0 is invalid. (patch 3) (suggested by Brian Foster) * Make cachestat extensible by adding the `cstat_size` argument in the syscall (patch 3) 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 This series should be applied on top of: workingset: fix confusion around eviction vs refault container https://lkml.org/lkml/2023/1/4/1066 This series consist of 3 patches: Nhat Pham (3): workingset: refactor LRU refault to expose refault recency check cachestat: implement cachestat syscall selftests: Add selftests for cachestat MAINTAINERS | 7 + arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + include/linux/fs.h | 3 + include/linux/swap.h | 1 + include/linux/syscalls.h | 4 + include/uapi/asm-generic/unistd.h | 5 +- include/uapi/linux/mman.h | 9 + init/Kconfig | 10 + kernel/sys_ni.c | 1 + mm/filemap.c | 154 +++++++++++ mm/workingset.c | 129 ++++++--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/cachestat/.gitignore | 2 + tools/testing/selftests/cachestat/Makefile | 8 + .../selftests/cachestat/test_cachestat.c | 260 ++++++++++++++++++ 27 files changed, 568 insertions(+), 39 deletions(-) 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 base-commit: 1440f576022887004f719883acb094e7e0dd4944 prerequisite-patch-id: 171a43d333e1b267ce14188a5beaea2f313787fb -- 2.30.2