Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6343715rwb; Mon, 5 Dec 2022 10:57:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ve7vTPLbZEh6/XzEsY2+j0UZcwtD23ofRImbpbeEi9QTCt69ik24IJNkANn15HxTTy2qz X-Received: by 2002:a17:906:6782:b0:7ad:7d50:dec2 with SMTP id q2-20020a170906678200b007ad7d50dec2mr73613504ejp.37.1670266631815; Mon, 05 Dec 2022 10:57:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670266631; cv=none; d=google.com; s=arc-20160816; b=Ok0qtbhLK8uyyaMRqBaR5nsgjWPeS1okmXPjqezka5BJAYri8QjiIDEoMExvvkimdS sZHWJX/PVdBQFLR0wg4hYoNcY0UBZVqeBKWM6uUGj4ozAc2GXX01CHq8k1ZaHDnbFYaq 1SaWqIkDLcdQL67V+w8+SbWK0asVNmxJy2UXwLaDkpc46r/6+HnGBOxybpaA2+EJfC0P 0VpgYSctNuw8FaRMOSsuqJD5Imbus4zCWNgtx4YS3vT+2yL3/s8SBPHjAJN4RZSVOAun 1unmYn9Yh0caO3uu1/IWBr+d+fe3W01IrWA+vkrkewOZ5Yb2g9b1ZJ7i/aVH1TxescE+ sphA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=U4iGUxKXjjOVEMJuMdNLNIqO6vUJnd3qD/zTRON5oB0=; b=rfs0V7L4EmrQMAhWbfMLhsTOHAtkrsCyvfTfSnW706fXMPlGEdyGmRzqcGvRB891S2 9/K7obrwYo0tTwAB3gdq55kbHS+wxZAyMRk6p2gAje2RbjGCJ+6YX9Y1CHc3Mpv7jxcw 3RaCr7DsTPu+xlJJduKx1l7yoqf6EXMUVzZY1/cYDUKqdzjITJbXawJ5NCsYfka7wnsk QSzCzvz7OETCv5t/+anbUwfgSOLnnbNihqYv2/63iZ0vbi9x/2KDFCc9sDjjxvmwPfwn Q/qJwZiWgBLUoC+wEvqc+hIDPSti2tAvmOsDY3jJqq/aXksJ8jtkdxLHC5w7AW5jFadM fPKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l4JO0S1z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a34-20020a509ea5000000b0046443638c9esi204457edf.262.2022.12.05.10.56.52; Mon, 05 Dec 2022 10:57:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l4JO0S1z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232656AbiLERwZ (ORCPT + 81 others); Mon, 5 Dec 2022 12:52:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232755AbiLERvs (ORCPT ); Mon, 5 Dec 2022 12:51:48 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 067391EC44 for ; Mon, 5 Dec 2022 09:51:44 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so4301061pjj.4 for ; Mon, 05 Dec 2022 09:51:44 -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=U4iGUxKXjjOVEMJuMdNLNIqO6vUJnd3qD/zTRON5oB0=; b=l4JO0S1zAOZ9BTlZyHNbVhEOy2tlu82fAp28Wov5NxHhuX0A6+qa7ECv/eWzW6VEKV MeZEK+8uirEsoLiTbhKw4Jg1YPyci4uMoo2W//SBGH0WvK2tweLZWrM6uZF2bj14B232 XIXjEgbXZ1Qp0dePcNAgE7fiW0IHXQYBZpbQpi4rcb06BUqNbCenlLk0LHQBLPfPo6zB Ff3AFy1IYFYuoGE3aPe25fbW5JZo1hNpONd2R0hrskdbO0OOr5778gWWk543mp0/NtDL 9K8NbBMDW4jWaQO12YeEezZvPEhUIipMrftILpKfyC9AeKl70MNIvtN83gU4Im+tbLGM 1j4g== 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=U4iGUxKXjjOVEMJuMdNLNIqO6vUJnd3qD/zTRON5oB0=; b=v0Hb0xtQbZuh8r2hrUntN1T6g5kIA6BQUP6w4Bl71RQ+A0a91oU0uU8bMHbSEzg7Cd dyIbn7FMqHDgxNOtVmz7T0sqRbvBdmov92ej6H6pQFiREq+ePzfI++HupCNNBIu06mNb WHl3G7zvIzPZBOKicC1LKeLyUBFDEGMVD6VwBDsFQmqFpFY9f6/ahTS+qdXisSQ7Akpr Vgc+/Xp0LQGEeJeTu/HMa39yUjgxwyA1c6ZYDWtYCSoF2WmbDZBJzL3xnYwxAlSsHkHQ xt80oJwMrsc/PwGq3ANYtpbkxjSkId1iH/3DZautwtbjYKW2bWaTYmoGP1XQDMvA+GL8 3pPg== X-Gm-Message-State: ANoB5pm67LEZVnWFv7hlc20dBd6i0xGjx/6J79wZgDhyydwF77KeRgvJ wryTT41eqFCNw8Y7lIiNtuw= X-Received: by 2002:a17:902:e005:b0:189:c62e:ac2f with SMTP id o5-20020a170902e00500b00189c62eac2fmr12430135plo.144.1670262703435; Mon, 05 Dec 2022 09:51:43 -0800 (PST) Received: from localhost (fwdproxy-prn-013.fbsv.net. [2a03:2880:ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id c10-20020a170902d48a00b00188edd16246sm10860172plg.266.2022.12.05.09.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 09:51:42 -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 v2 0/4] cachestat: a new syscall for page cache state of files Date: Mon, 5 Dec 2022 09:51:36 -0800 Message-Id: <20221205175140.1543229-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changelog: 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/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/swap.h | 1 + include/linux/syscalls.h | 3 + include/uapi/asm-generic/unistd.h | 5 +- include/uapi/linux/mman.h | 8 + kernel/sys_ni.c | 1 + mm/Makefile | 2 +- mm/cachestat.c | 115 +++++++++++ mm/workingset.c | 144 +++++++++----- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/cachestat/.gitignore | 2 + tools/testing/selftests/cachestat/Makefile | 7 + .../selftests/cachestat/test_cachestat.c | 186 ++++++++++++++++++ 15 files changed, 438 insertions(+), 47 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