From patchwork Thu Dec 8 20:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13068844 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 6FB2FC4332F for ; Thu, 8 Dec 2022 20:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D74F28E0003; Thu, 8 Dec 2022 15:28:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D252F8E0001; Thu, 8 Dec 2022 15:28:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC9E8E0003; Thu, 8 Dec 2022 15:28:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AFE4B8E0001 for ; Thu, 8 Dec 2022 15:28:12 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5C5A01C68F2 for ; Thu, 8 Dec 2022 20:28:12 +0000 (UTC) X-FDA: 80220276024.27.3CE0957 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf08.hostedemail.com (Postfix) with ESMTP id BD973160007 for ; Thu, 8 Dec 2022 20:28:10 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=m2+cV4bV; spf=pass (imf08.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.216.51 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=1670531290; 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=6aaxwm43tiVxdpJBY9octccgxrKQy3Qmz9QSXAzXTL4=; b=eIjvVfjlRL0002SMPa+EndlnhQPrAvv365/1PokpYL2uq1dtZ/egsA7+uv3SqxTCJO2fdL C9MEFXSWCQYTLnlPULH80o/FY4SCicFJCCWp+H6r0wG4ABzGceZfC+bJ+jYfqhmwM3kY9b oDHattx3Gq+PeTC5j/q7KLZeteye9cw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=m2+cV4bV; spf=pass (imf08.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.216.51 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=1670531290; a=rsa-sha256; cv=none; b=fYsmhF+nWf7U43k9pPe1777XXaBMaR6PGnkgm5vSDOMnejIFJzIw1cEpGFf5HXMAVqo9UP pjbGzyzyvGSP25pbbI4YQ3IUxfmtvg1n0tts9g9bTa+7fXzkno1MeXbyJbXXE4fSB7a81A EaMhWxODivD8Tt9EjYxq/3q5RfEqsJc= Received: by mail-pj1-f51.google.com with SMTP id u15-20020a17090a3fcf00b002191825cf02so2730176pjm.2 for ; Thu, 08 Dec 2022 12:28:10 -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=6aaxwm43tiVxdpJBY9octccgxrKQy3Qmz9QSXAzXTL4=; b=m2+cV4bVjngA8qv+x/EgqbrTWbgdLa5nIrdA6WnUxBgGNGF5zvLDYu/rnWBK3Nibpa YF7Kc8usZ3yAonphUbBm+ld94kFoxswSZ1nmtDSCs2j3PbPRIyTFrsVijUZAfYELDCxl rIv4JRaPtZxg5N4xXgqMT2FIUh9mW6QlboFTnnYjyHH1Xr4ywLvt9YEOxG4OY6tdSE3N 4jCVODXuu4i8xyGzhncLoTxHTRsw9vcTGFXKSPe0yBmVAes2FTbyfR+NCVJ4cgWG7Onq QOEdIj1rWWZ+l9nxRTVzPid2C0AG/aopxlw3zGBy3XRJmXO5/Vxdv6H/C+Ssejtq8XJh S7iw== 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=6aaxwm43tiVxdpJBY9octccgxrKQy3Qmz9QSXAzXTL4=; b=g+UqPwckIDP/f0mRryhZGCetpqCldkO36f+GD1wHvczqBvIp3b1RdnIzOP7gvoSCM2 /f/3MtGoSxtdYYgc6T+YAYP5WbwSsN6JOARJMcnR8su/Th6CVFu+c5H+uk9xVKcYXaBv 9UlGs04tcvxXtiIwHEFYM8yOTLUAFaJeEMMyU3ijzdJzaatYbyFsC/kYrAmYvIwstRef Meh8tURuMiFRQbBYCqskULFTc5gs682423Dxq1EUD7dcdCHvWQIVjHATAqVMq9KyR0qi I0pAz5XqvhpgKWipBIsoidvJZM3TbF+DNdPKHeA9yP8sLx0LbqxfjTxyq0ySSdAzuMof ldVA== X-Gm-Message-State: ANoB5pl0ewraRg4Bsoj8ADzzFIhWHCncXVwIzibOKumafEHyEp+ppff9 rpYt9u90/JGRvHjAGYXwid8= X-Google-Smtp-Source: AA0mqf62PBR+BMeO5CDIFR47WRLfn7JEfDXkJwAgH8SbfB9zQATjhpfMj0KK2IvHxgkjgh8xKKaM4Q== X-Received: by 2002:a17:90b:2711:b0:213:9b80:ceee with SMTP id px17-20020a17090b271100b002139b80ceeemr109608058pjb.243.1670531289530; Thu, 08 Dec 2022 12:28:09 -0800 (PST) Received: from localhost (fwdproxy-prn-008.fbsv.net. [2a03:2880:ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id f13-20020a170902f38d00b001868bf6a7b8sm16933787ple.146.2022.12.08.12.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 12:28:08 -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, kernel-team@meta.com Subject: [PATCH v3 0/4] cachestat: a new syscall for page cache state of files Date: Thu, 8 Dec 2022 12:28:04 -0800 Message-Id: <20221208202808.908690-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BD973160007 X-Stat-Signature: tpt4jniu7y1jki4g3s9rc1z16ray863p X-Rspam-User: X-HE-Tag: 1670531290-997453 X-HE-Meta: U2FsdGVkX18oOsmA8RgobMJbYy5LLJST/wHXtTBoaFUgeh9HufC4koRiBQis5hzfEvUc7d1nzmFu+vH+gBaQKB+SYkN8Dn/4AMLu+LhexD3jKvy9+lzbs5763x0H7hjx/cvG8uC9bC2h0sEFqotF90yBpgCNyU5nflacuW5VT1SChqpspoHeMgls9epI7g6w1gcFId/+k2ZnHAHFpnpYBckeUDw3/6RpKQLIJ4+I4i/DsdwFOuKm+wQYPdwJeCZdz+1b5W/iLk1g3yu84tpKpeAFuJCO9y/vipY8SUnPn0AwaQOu4Z5NjzbSwQtxY5KDwLNdu1T3VRHyrq6OsLFfZ+7iYGs6vougfecqGUht0oMZloIoOqwgd6KxnNjXZD154ZVLKDpaa87+EPgUz1AeqdHK0wHBYaRd5QXrYxl4OreVFevNMdN8xXPEhzAAdPv3w+x1wZdJh+Cdp15/2HnCHKjC7zL7djGcQGsgvgWfnZbfRa5nhWoLJKWGm9OaObYIlD7GR12PryA/l4vWKNsaXC9MLs/zVv4N6aAf+cr5ntrwgJP5eEn4aNUDmGt4AHpz2TpFT09zKN3308DDOim9a2SmC6SaljP1U3VpSLHL/zZhZpTcLxGRJEJeF9yebqWiOZJ36fiCdrnlSrnsqGnf6VtUivuXh7FIZKZxCSqk8QEiFp3M92S/UtxWmYg9O+oZM5wTlDvRxYcOr7gM7914N7Lu2YZMM+NdkdnYhHoIoEtmX/BumwDsgdTHgBfJS4J55arh+7RECoiRkA1tAnJ2ch+JvgOiLML+DTNe7lIEil6x3j972w1YKcbe0Ss93I74NriVzlWzC6MbTz2Vas2S0QyHpP9HB7p+FdYnxCQZz07LBxvUf4IsYSQdXuRqcui2A51fr7dpYaIR2b/5Y+T5yHpUVM7iCVS3oiqQ1pXqI1qWh86HfyJDKWceD7E+LdUfKT/lsuSkAoA562mtY4q SEgcBOfa VCjSEJn5pbiVmP/6+jv/D27hNyzJBsY69DAvpMhq0w81bSI9ZHh+LiXfZUAqbqsx7wJN2fnm6GS6TRc8AlFf0jCbiWrTWnkTR5PkPEFfNLfaGdPJ9KYiESWnhdZV06BgwkB9s 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: 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 consist of 4 patches: 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/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/swap.h | 1 + include/linux/syscalls.h | 3 + include/uapi/asm-generic/unistd.h | 5 +- include/uapi/linux/mman.h | 9 + init/Kconfig | 10 + kernel/sys_ni.c | 1 + mm/Makefile | 1 + mm/cachestat.c | 117 +++++++++++ mm/workingset.c | 130 ++++++++---- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/cachestat/.gitignore | 2 + tools/testing/selftests/cachestat/Makefile | 7 + .../selftests/cachestat/test_cachestat.c | 186 ++++++++++++++++++ 27 files changed, 455 insertions(+), 39 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