Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3203394rwb; Fri, 16 Dec 2022 11:27:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf6R9g0LMFXa+6AjtfuA9ZDrJPnrFUnoG28X+dVP5LQXQufHOHWcHA54YxWs/HeGpBw30vpz X-Received: by 2002:a17:902:dad1:b0:189:8513:f6f9 with SMTP id q17-20020a170902dad100b001898513f6f9mr44997615plx.18.1671218876112; Fri, 16 Dec 2022 11:27:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671218876; cv=none; d=google.com; s=arc-20160816; b=pK63eENTAMNVTIl44W9U7aQwEDWAVgJoxEV/K62DzQ1FI0QCTURNOfEidLuEK8gJ+R NRK3LUhqgzNRvWzNtTG+bPZrHQhJ02CyEfa0iyp9qns0qsVtzISdO+Dxn4t4YmiG282Z SjtgYaC61XKQL6WoiY/yWbpW35a2pVs1dC/E6iMpzT1iWbdfuhKksUB0EX++Nw1/Kgrs 8e/QsVJ2cPLgE1NLkQ7il9L8J0LIqnert8qk8U/0jzOuppEaO8LWj1z59oUINDF1g/k9 gRPwRqefsscLFuTiupbfyfhEqdse8TPfRgnm5epF52IL4uwRyXyyNfeMPGRB4cU0QEft rIOQ== 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=WIGHTz0eabOdyvedXhDmOO3amXHWmKUtSF8hi4QPVYM=; b=U3lR3MSfb1FflCSnhpt9sXpJJuvt4YVPyzz1xSrisljCQYdkx2XUH4+baAkxRqBjn5 mO9BjSIgjuOvVpJ7/m7o+Xm64wel1+Cg46Z5bxylL0/yigfYBk2vxTOc4ONbtXxg4389 6aKunQkE/AZIqW54oMEcC7QEU7ilVAwmhFlKmGWQnQOavTmBo1b7it/mtZUrA6MtuTYy 1HDgsQPuLmFDleGFYj5P4qORdWOZOja6+SqVdWuN5pNQyaUBBkk6Mbk+RJPZgY6Vx4Ur 7C0yI6IIK4WRAMvUyB5Xw+IcDD55/tP3p/uleyU9XJfxibKM3aVd78pN3PCoaeP6/ShZ w0XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K0eq7FlE; 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 jg15-20020a17090326cf00b00189734b4f02si3212821plb.69.2022.12.16.11.27.47; Fri, 16 Dec 2022 11:27:56 -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=K0eq7FlE; 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 S231653AbiLPTV6 (ORCPT + 69 others); Fri, 16 Dec 2022 14:21:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbiLPTVw (ORCPT ); Fri, 16 Dec 2022 14:21:52 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3EF57B67 for ; Fri, 16 Dec 2022 11:21:51 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id s7so3268055plk.5 for ; Fri, 16 Dec 2022 11:21:51 -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=WIGHTz0eabOdyvedXhDmOO3amXHWmKUtSF8hi4QPVYM=; b=K0eq7FlE/PQBcn5OgzH+EswODhhIlwrfi3mlASpMf2MLTLXT/8ZKtZ0fIf/TEPf5xg 5P8v2S+I8GgvUDVQ+KJjmvTDtE/Hyz9It8r3XSBWAxnwtRyKXAG+1tVTmo/Mk1B6PlHv Pru/zJfB0Wc+xTdaRgK5GkGcAe5ws3V7jNc+4QFPhS5XqCsXAGvDDzzSU2O9+D6tgAa1 H56BltNEkzAHE1gYbNbZIWSU4fdFQmTvHpolbeKTcVQte+ICmgcLGYU9V9LQw4A8da0O mEfdBMMR27zZxXx/jEVprTQzoOuLCpUTB+S8UOI5Nf5VZI9iMXTcLin2vfmrAThmrDA3 VgZg== 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=WIGHTz0eabOdyvedXhDmOO3amXHWmKUtSF8hi4QPVYM=; b=HfNOwIv0RD/uzC8xugIry2tNpFdlix2dvfDAYV2kAKRe39mbOV+GrKB6sn2KGZkuZF +0Fm8HVyqtu4+pAdKkpOypG8AgpV8LZr/Dw/rmQQSyeD05rFzqt3MB3Zua+N2WyuUXST 9udHizsW0rPfex2T4dmqHW/TamlUjqiEU+pKm9caDqa7kPh4l7imgZihCiY1XbRnR6WO 5AeQUwTrtA6+ArNs/DTokemxf0UVEiq6AZ8hehlE7oQ89cBoPXEID2Fp228RSL1HZdk2 dzcIAmL2tC1skad0VUgYUFc0SKweOloTTva3pIuJQiKqbpbvq0DYdlXc586Kerhf3v0U h06w== X-Gm-Message-State: ANoB5pmqdPmU07tMFT12UyAMIApRIZewECSWgw5gpfwELkcsvYT/zGrG JM8bc+DDt+wJ8G3sR3oGbqg= X-Received: by 2002:a17:90b:1108:b0:218:fa99:8347 with SMTP id gi8-20020a17090b110800b00218fa998347mr34253695pjb.37.1671218510733; Fri, 16 Dec 2022 11:21:50 -0800 (PST) Received: from localhost (fwdproxy-prn-014.fbsv.net. [2a03:2880:ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id k7-20020a17090a39c700b00200461cfa99sm5145511pjf.11.2022.12.16.11.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 11:21:50 -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 v4 0/4] cachestat: a new syscall for page cache state of files Date: Fri, 16 Dec 2022 11:21:45 -0800 Message-Id: <20221216192149.3902877-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: 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 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 | 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 | 3 + include/uapi/asm-generic/unistd.h | 5 +- include/uapi/linux/mman.h | 9 + init/Kconfig | 10 + kernel/sys_ni.c | 1 + mm/filemap.c | 137 +++++++++ mm/workingset.c | 130 ++++++--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/cachestat/.gitignore | 2 + tools/testing/selftests/cachestat/Makefile | 8 + .../selftests/cachestat/test_cachestat.c | 259 ++++++++++++++++++ 27 files changed, 550 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 -- 2.30.2