From patchwork Tue Nov 15 18:28:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13044069 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 58D09C4332F for ; Tue, 15 Nov 2022 18:29:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 960496B0071; Tue, 15 Nov 2022 13:29:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 911726B0072; Tue, 15 Nov 2022 13:29:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D8546B0073; Tue, 15 Nov 2022 13:29:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6DE946B0071 for ; Tue, 15 Nov 2022 13:29:05 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3F9081C6049 for ; Tue, 15 Nov 2022 18:29:05 +0000 (UTC) X-FDA: 80136513450.02.57808FA Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf14.hostedemail.com (Postfix) with ESMTP id BA0D810000E for ; Tue, 15 Nov 2022 18:29:04 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso17683932pjg.5 for ; Tue, 15 Nov 2022 10:29:04 -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=JyDgb7jTANE0Qk859LfOEdF0OgwEPQqULMlB2KUqBqA=; b=SPvwBZphKt7+WD2D+YQ/omAaF18nUwvOrvHwpHsUIQwQngxMUoOz8S51fOMuJRUcjy O5gyD+/5wcpkmMdwa3/gZlr/Zktv1qA+qM53PvIoaOk83YK0inRytOPqAMc7f47mADV8 Qalg+zcJAkxyoSH5vGsLFIg2aw1TBgZ0kcyBHwTUFt+jAQ4HCE7fy1cgA5qdFBA9XYeO 9g/G7BI1dFi+prQUVAbdAm2BBKCxzOzfwfVocNlZZNccSFT2+fKiDNSpoIIFdpSdxSZd +zXG1n3WoCJc1IyKZ/khKDqmsSyJrP45w3dMptlCoaswDJNg+QHrtAdDjAYmnAfFkg7j w3zA== 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=JyDgb7jTANE0Qk859LfOEdF0OgwEPQqULMlB2KUqBqA=; b=7sqftg54DoRSzGn/s51kH+/4r93/Nqo48IE/u7U0jO+ZMTGtIezuqFNirwizVNh43j AYPMko6ooVPIiaYjIu7h/iSBcMvOOZripjx9iFOuC8lhOiRKy+NBAt9UFdaVrGp6bDWG PIhkvkqY9E5ytw51YKhJ9T9KKSOiR6s/D4V1qDckbHeU6vQN3YgK+SSsZetkTCRNf5Kv J/nf77XIkeXhUYzlLvAo2Xu/xYlgKQTU8UDys9Ce4yJpzj0gcw0Isn+zFX+O35mZ07/t bsJcNN8MwadN96JLLNMsAheA8agNj9j3yeF4H37ca4wP2I/wJ8lFcnyGkHI+3pxvh4I1 gdGg== X-Gm-Message-State: ANoB5pnoupqg54r/jMCC6shnsIU4ZuDcxrvtib36CLjesy68uwKOAdxB JIs0WxPw2aRIE+KWo7di1tCHHUbv2Yi/uw== X-Google-Smtp-Source: AA0mqf66garNKvM1of1uk/mXKAilT5V4v/nR05Pj2iYX1RAq7vck4xLmVnWZWoGwC9G9lzt2wbvyCg== X-Received: by 2002:a17:902:e792:b0:188:dd4b:7da3 with SMTP id cp18-20020a170902e79200b00188dd4b7da3mr32566plb.91.1668536943144; Tue, 15 Nov 2022 10:29:03 -0800 (PST) Received: from localhost (fwdproxy-prn-003.fbsv.net. [2a03:2880:ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id g10-20020a1709026b4a00b0018853dd8832sm10277486plt.4.2022.11.15.10.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 10:29:02 -0800 (PST) From: Nhat Pham 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 Message-Id: <20221115182901.2755368-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668536944; a=rsa-sha256; cv=none; b=y2jHPr6aREF4QyEuGkZ/zbRojMAzAJIBZVzoSiwjdQgnh4FrCZqavUudrnYrTWIeHhqFN/ mRykH1207qDMO4wYnQfEtJJMd56T5s4QtEU1uy71IvEmTvNpRezaLmm3TsSt2gQa1sEI7L CgbzCL5pfiCMYibIxUWNkwSzeW4HlGU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SPvwBZph; spf=pass (imf14.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.216.44 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=1668536944; 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=JyDgb7jTANE0Qk859LfOEdF0OgwEPQqULMlB2KUqBqA=; b=0L3TA4JE4FI+WiRsJXdeF9G18kXbNuWOJwrPIKQ9+kZcnIqLGL9BNORZiUOh2D/b43O6Mu w6b7U6lvMT/NttnFsYc2byjF/qqt1yYXtGrmTL68ViRWLmQI5GZNir9wMzOYOXVlEyjD6t u1SDpXFwmJtoUwSU43ecphHgOTWFG5w= X-Stat-Signature: ffxdm6etpo73uy5187grpw9ge4yug7qo X-Rspamd-Queue-Id: BA0D810000E Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SPvwBZph; spf=pass (imf14.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1668536944-372042 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: 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