From patchwork Sat Mar 5 16:04:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770417 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95AF2C433FE for ; Sat, 5 Mar 2022 16:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231985AbiCEQFg (ORCPT ); Sat, 5 Mar 2022 11:05:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231979AbiCEQFf (ORCPT ); Sat, 5 Mar 2022 11:05:35 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CC838BE0; Sat, 5 Mar 2022 08:04:43 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id j17so16974789wrc.0; Sat, 05 Mar 2022 08:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tgBNhkJaZjE8Z4MFNsIEqcgJ3jiEcmyqWbotT8QMd+4=; b=mGJbLdouKEPU4AOSgNOot+8Hywzrzt2aXQJs6qGlZUj8165Q3y1isJsqXIRwsaOJRl pXdnLrA36k0oNw427Gkzo9OPOyLuq3fspsJFpaTZdN/WcMHVp+9br1/ORnVGDo6kQQSJ w9XuUSF2cwooVzCz37zyFkkWxHnZ/ULkeW/bN90FPDmW44/qdxFqf8WaMf5w7cxkiVim Bq+1LhD6z4lPk960SdSQLDEcu13MFcqUXrmXTWM+T+ROs1vitdbxf+mQ7SvzBsTsu8zs ych67M1Ulu/Dk/2XoJUgpaN+VYF5qWb8j3TOigVVuMuPd82cVyGD5QxxjtHcKZjI3S2J LB2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tgBNhkJaZjE8Z4MFNsIEqcgJ3jiEcmyqWbotT8QMd+4=; b=gMlFvfWBXHjlYbxo92WEitxksTzSWX+V4ReudrVc6ZpjYWiTrRgY0eWs8GDEjf7Zxf xNIYrdvM3fVrAj0CWg37BFwFNjAZc+bAqau9DzBZ+sMgtjHRPBGITVNz/ayDwDOitpqd 8cKkO3JZCe6G15psSyIOeeugFJKUMBVrTICfrh0KlGA15E1wupcpBCTDDSMX5sfkDVKZ YZaZXJF1wfsYfBnjAapOPW+GtLAM1M8oh3TW3YxGvR6FfmWYMfHzf/I1bWpT08MYxrWW vYWDZhGVEw4ERJb5aR3wHehTCNSa3whl06Ic58iRaX+9L8sAaKhNs2VdoTE+ShQgvqAb QCsA== X-Gm-Message-State: AOAM5332TVzq9ktOHnK9q8x4WwrL8fwkLIwqYU0O/HgQvvmfNikI/oQk dwqARt+nz3ENnD3j0lY8szo= X-Google-Smtp-Source: ABdhPJyIRxblTmebE85ok1adXQZpwkViUl3XwG8ayOHerHSJYLaq6owo5lDTSz5h0v6LvtV8PeMHUg== X-Received: by 2002:adf:a341:0:b0:1f0:1a12:8920 with SMTP id d1-20020adfa341000000b001f01a128920mr2957850wrb.100.1646496282339; Sat, 05 Mar 2022 08:04:42 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:41 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 1/9] lib/percpu_counter: add helpers for "relaxed" counters Date: Sat, 5 Mar 2022 18:04:16 +0200 Message-Id: <20220305160424.1040102-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Counter that are only read with percpu_counter_sum() can use an arbitrary large batch size. Signed-off-by: Amir Goldstein --- include/linux/percpu_counter.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h index 01861eebed79..7f01f2e41304 100644 --- a/include/linux/percpu_counter.h +++ b/include/linux/percpu_counter.h @@ -193,4 +193,33 @@ static inline void percpu_counter_sub(struct percpu_counter *fbc, s64 amount) percpu_counter_add(fbc, -amount); } +/* + * Helpers for percpu counters for which per-cpu drift doesn't matter. + * This is typically the case for statistics counters that are read with + * percpu_counter_sum{,_positive}(). + */ +#define PERCPU_COUNTER_LARGE_BATCH (INT_MAX / 2) + +static inline void percpu_counter_add_relaxed(struct percpu_counter *fbc, + s64 amount) +{ + percpu_counter_add_batch(fbc, amount, PERCPU_COUNTER_LARGE_BATCH); +} + +static inline void percpu_counter_sub_relaxed(struct percpu_counter *fbc, + s64 amount) +{ + percpu_counter_add_relaxed(fbc, amount); +} + +static inline void percpu_counter_inc_relaxed(struct percpu_counter *fbc) +{ + percpu_counter_add_relaxed(fbc, 1); +} + +static inline void percpu_counter_dec_relaxed(struct percpu_counter *fbc) +{ + percpu_counter_add_relaxed(fbc, -1); +} + #endif /* _LINUX_PERCPU_COUNTER_H */ From patchwork Sat Mar 5 16:04:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770419 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A7CCC4321E for ; Sat, 5 Mar 2022 16:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231993AbiCEQFh (ORCPT ); Sat, 5 Mar 2022 11:05:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231981AbiCEQFf (ORCPT ); Sat, 5 Mar 2022 11:05:35 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E6173878C; Sat, 5 Mar 2022 08:04:45 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id q7-20020a7bce87000000b00382255f4ca9so8323130wmj.2; Sat, 05 Mar 2022 08:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FjOj0yhcyWryfJc/gOuiHfZG2qtTwyBqMdR1AX5xLrk=; b=UCn+J6nrhzZt8zrm8r8aImFZRh1ijH4mj7j8aZ0F7QvalXFAxk3XDUz8G2cLY/YX/g UsYwHXeahy2z7tPJSrcA2SPJzyqtE5ro0vD/zwxqNVLixwa7QzO9PbcX/Cdth95iMtM8 9/MIXBoiEJ2cbbnthQYRuTk3ma3b389OecLsWKXYxHulhXscyLKw0K1UHXxI0wlNoGKo ytim/ODnJYll/DSzgSmuyoiK/R7R0RFlh7UAm/P3nz46LPgVlH5nMBbVBmOOJsxyDMFf KghHrr5CLUOm9yzE82plVIF2W7i7rG962CyyUedxKArZXo26QphGTp3aqTE6yzj9IPpc L0Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FjOj0yhcyWryfJc/gOuiHfZG2qtTwyBqMdR1AX5xLrk=; b=UUwgY/SXAj4vu5NpEbwFUMzqJxJsBGM6OA9++yoT/dZXHBd0zsYhuXxcH8vDSOQDpr Ngd+JfacwDqJ8ut99qWlASTmCBOcASpokey00XQPXWX08Xp5JLwFi1Ig4qS3OFOVJae4 ncCU74h1m2RftDKq2bbCnAoxI2JKw8SevGF7iijetiKpr0CNN7FwdpnmJlxUXwBg877D ue6LHmlP79T94u171nGyJ+3eTTjJ09fZ9C+iDXVnaIWabW/GyX4y4XewB6aBgtdcBN4i HDi2x//BBR6SH5uv3wGc6NuUriaDNqWQMIn9eucSiHI77al4aQgM93oXj1QPaLM+bPa3 0w8w== X-Gm-Message-State: AOAM531G1DT3EZ589YqCSmEHoczQHFViFfrfD+ZC0QGR5DAqxjL6B0xP eNQZdpAA0XvFzuiW50lYYxKa/X5y8HU= X-Google-Smtp-Source: ABdhPJzoafBUfwkUKcPtn01V4gK510mJCn220fcKXrpkTJk3pwAjQG55bDc5Ky4Up6fkOF8ElAmMIw== X-Received: by 2002:a1c:ed18:0:b0:37e:7a1d:a507 with SMTP id l24-20020a1ced18000000b0037e7a1da507mr11974558wmh.187.1646496283830; Sat, 05 Mar 2022 08:04:43 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:43 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 2/9] lib/percpu_counter: add helpers for arrays of counters Date: Sat, 5 Mar 2022 18:04:17 +0200 Message-Id: <20220305160424.1040102-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Hoist the helpers to init/destroy an array of counters from nfsd_stats to percpu_counter library. Signed-off-by: Amir Goldstein --- fs/nfsd/export.c | 10 ++++++--- fs/nfsd/nfscache.c | 5 +++-- fs/nfsd/stats.c | 37 +++------------------------------- fs/nfsd/stats.h | 3 --- include/linux/percpu_counter.h | 19 +++++++++++++++++ lib/percpu_counter.c | 27 +++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 42 deletions(-) diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index 668c7527b17e..ec97a086077a 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -334,17 +334,21 @@ static void nfsd4_fslocs_free(struct nfsd4_fs_locations *fsloc) static int export_stats_init(struct export_stats *stats) { stats->start_time = ktime_get_seconds(); - return nfsd_percpu_counters_init(stats->counter, EXP_STATS_COUNTERS_NUM); + return percpu_counters_init(stats->counter, EXP_STATS_COUNTERS_NUM, 0, + GFP_KERNEL); } static void export_stats_reset(struct export_stats *stats) { - nfsd_percpu_counters_reset(stats->counter, EXP_STATS_COUNTERS_NUM); + int i; + + for (i = 0; i < EXP_STATS_COUNTERS_NUM; i++) + percpu_counter_set(&stats->counter[i], 0); } static void export_stats_destroy(struct export_stats *stats) { - nfsd_percpu_counters_destroy(stats->counter, EXP_STATS_COUNTERS_NUM); + percpu_counters_destroy(stats->counter, EXP_STATS_COUNTERS_NUM); } static void svc_export_put(struct kref *ref) diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 0b3f12aa37ff..d93bb4866d07 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -150,12 +150,13 @@ void nfsd_drc_slab_free(void) static int nfsd_reply_cache_stats_init(struct nfsd_net *nn) { - return nfsd_percpu_counters_init(nn->counter, NFSD_NET_COUNTERS_NUM); + return percpu_counters_init(nn->counter, NFSD_NET_COUNTERS_NUM, 0, + GFP_KERNEL); } static void nfsd_reply_cache_stats_destroy(struct nfsd_net *nn) { - nfsd_percpu_counters_destroy(nn->counter, NFSD_NET_COUNTERS_NUM); + percpu_counters_destroy(nn->counter, NFSD_NET_COUNTERS_NUM); } int nfsd_reply_cache_init(struct nfsd_net *nn) diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c index a8c5a02a84f0..933e703cbb3b 100644 --- a/fs/nfsd/stats.c +++ b/fs/nfsd/stats.c @@ -84,46 +84,15 @@ static const struct proc_ops nfsd_proc_ops = { .proc_release = single_release, }; -int nfsd_percpu_counters_init(struct percpu_counter counters[], int num) -{ - int i, err = 0; - - for (i = 0; !err && i < num; i++) - err = percpu_counter_init(&counters[i], 0, GFP_KERNEL); - - if (!err) - return 0; - - for (; i > 0; i--) - percpu_counter_destroy(&counters[i-1]); - - return err; -} - -void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num) -{ - int i; - - for (i = 0; i < num; i++) - percpu_counter_set(&counters[i], 0); -} - -void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num) -{ - int i; - - for (i = 0; i < num; i++) - percpu_counter_destroy(&counters[i]); -} - static int nfsd_stat_counters_init(void) { - return nfsd_percpu_counters_init(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM); + return percpu_counters_init(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM, + 0, GFP_KERNEL); } static void nfsd_stat_counters_destroy(void) { - nfsd_percpu_counters_destroy(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM); + percpu_counters_destroy(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM); } int nfsd_stat_init(void) diff --git a/fs/nfsd/stats.h b/fs/nfsd/stats.h index 9b43dc3d9991..61840f9035a9 100644 --- a/fs/nfsd/stats.h +++ b/fs/nfsd/stats.h @@ -36,9 +36,6 @@ extern struct nfsd_stats nfsdstats; extern struct svc_stat nfsd_svcstats; -int nfsd_percpu_counters_init(struct percpu_counter counters[], int num); -void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num); -void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num); int nfsd_stat_init(void); void nfsd_stat_shutdown(void); diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h index 7f01f2e41304..37dd81c85411 100644 --- a/include/linux/percpu_counter.h +++ b/include/linux/percpu_counter.h @@ -46,6 +46,10 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc); int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch); void percpu_counter_sync(struct percpu_counter *fbc); +int percpu_counters_init(struct percpu_counter counters[], int num, s64 amount, + gfp_t gfp); +void percpu_counters_destroy(struct percpu_counter counters[], int num); + static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) { return __percpu_counter_compare(fbc, rhs, percpu_counter_batch); @@ -109,6 +113,21 @@ static inline void percpu_counter_destroy(struct percpu_counter *fbc) { } +static inline int percpu_counters_init(struct percpu_counter counters[], + int num, s64 amount, gfp_t gfp) +{ + int i; + + for (i = 0; i < num; i++) + counters[i] = amount; + return 0; +} + +static inline void percpu_counters_destroy(struct percpu_counter counters[], + int num) +{ +} + static inline void percpu_counter_set(struct percpu_counter *fbc, s64 amount) { fbc->count = amount; diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index ed610b75dc32..f75a45c63c18 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c @@ -181,6 +181,33 @@ void percpu_counter_destroy(struct percpu_counter *fbc) } EXPORT_SYMBOL(percpu_counter_destroy); +int percpu_counters_init(struct percpu_counter counters[], int num, s64 amount, + gfp_t gfp) +{ + int i, err = 0; + + for (i = 0; !err && i < num; i++) + err = percpu_counter_init(&counters[i], amount, gfp); + + if (!err) + return 0; + + for (; i > 0; i--) + percpu_counter_destroy(&counters[i-1]); + + return err; +} +EXPORT_SYMBOL(percpu_counters_init); + +void percpu_counters_destroy(struct percpu_counter counters[], int num) +{ + int i; + + for (i = 0; i < num; i++) + percpu_counter_destroy(&counters[i]); +} +EXPORT_SYMBOL(percpu_counters_destroy); + int percpu_counter_batch __read_mostly = 32; EXPORT_SYMBOL(percpu_counter_batch); From patchwork Sat Mar 5 16:04:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770422 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B139AC433FE for ; Sat, 5 Mar 2022 16:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbiCEQFt (ORCPT ); Sat, 5 Mar 2022 11:05:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231997AbiCEQFj (ORCPT ); Sat, 5 Mar 2022 11:05:39 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5B15387B2; Sat, 5 Mar 2022 08:04:46 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id b5so16925211wrr.2; Sat, 05 Mar 2022 08:04:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XIBRvQXE//zDJAEj1LXYr/IDU3RJ1FAKagi05ekc5gM=; b=pbaIQ3wjh/0/IjgSW9c19x3yY3kB0IKi0Nf8621R+s39g4IApSGoOO1A0+ytlYyt5X /l40N4++dQHWD5UjTqDKAK/cjjs0CCrO8EfFyyXprrA2ioXh0OzaGr7Uazj6Tw4LgIg3 oHQJgUfclCZUOb5Rf8QMgwEBmxd4HuFpLDz7HNuFpDEsadXiUZmHHU+YND2xi2XjoGFc lLqZITYSvsLLdxA6RCMtrlMtqWsQggqF6Z2ED9uOIeOqVXLyEvlTZqduEmRbYbXOlVay obRsJJuwjjUGq/lcHluiFLok4WiTyG2CTs0OjUAeD09zH/YsSV6BhRMNPUc57XVZ6d7G +4hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XIBRvQXE//zDJAEj1LXYr/IDU3RJ1FAKagi05ekc5gM=; b=IGO3G2v6AHeXuW/jfVP7F/vPBtVJrE1y7zihyCHz11h0GtaJQ9phAney6YktCobYAg 4ciNQB0l7yTeSLs4onc77/c+P16bKY5EcqdvbLfcb+QupsG/+Qqkj2vcZ77v2COuSztR au0akdzxC+fDt+SXvEkzfOJ5AWjyME6zcGstI6kt5oQc5VyrvamZA5spt65KmMAL0+4z DVMkF6pntkNK2dOUqSyOBTPrrIc/eVnm2FDtWa21z+MKlux3XSo21Qww/kUh3HdbUTfd DSkNsA5btbLAaLG3YUwbsF4pdWlO0J+GIN4MeMwCzu99F+SOpZWmNi4vPdpBNWHoEcF7 KGZQ== X-Gm-Message-State: AOAM530IZZ6zsFVa4ObXaaYo9Z0CIu1VN8j3EJ3XRpYgwyPnbH0VMJ41 vZFJ9yEvSgOrIJuphkiZip8= X-Google-Smtp-Source: ABdhPJyOZdAamn/dg/bv38lfSaqZVf9bJvhdpYULSmZZpNdQrknkIGIM24iYvkk4dOZISiLKWQNy2A== X-Received: by 2002:adf:eccc:0:b0:1f0:1a33:a7af with SMTP id s12-20020adfeccc000000b001f01a33a7afmr2944141wro.113.1646496285317; Sat, 05 Mar 2022 08:04:45 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:44 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 3/9] fs: tidy up fs_flags definitions Date: Sat, 5 Mar 2022 18:04:18 +0200 Message-Id: <20220305160424.1040102-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use bit shift for flag constants and abbreviate comments. Signed-off-by: Amir Goldstein --- include/linux/fs.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 831b20430d6e..ecb64997c390 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2429,13 +2429,13 @@ int sync_inode_metadata(struct inode *inode, int wait); struct file_system_type { const char *name; int fs_flags; -#define FS_REQUIRES_DEV 1 -#define FS_BINARY_MOUNTDATA 2 -#define FS_HAS_SUBTYPE 4 -#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ -#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */ -#define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ -#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ +#define FS_REQUIRES_DEV (1<<0) +#define FS_BINARY_MOUNTDATA (1<<1) +#define FS_HAS_SUBTYPE (1<<2) +#define FS_USERNS_MOUNT (1<<3) /* Can be mounted by userns root */ +#define FS_DISALLOW_NOTIFY_PERM (1<<4) /* Disable fanotify permission events */ +#define FS_ALLOW_IDMAP (1<<5) /* FS can handle vfs idmappings */ +#define FS_RENAME_DOES_D_MOVE (1<<15) /* FS will handle d_move() internally */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; struct dentry *(*mount) (struct file_system_type *, int, From patchwork Sat Mar 5 16:04:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770420 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 263CDC433FE for ; Sat, 5 Mar 2022 16:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232024AbiCEQFq (ORCPT ); Sat, 5 Mar 2022 11:05:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232000AbiCEQFp (ORCPT ); Sat, 5 Mar 2022 11:05:45 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 762D540E7B; Sat, 5 Mar 2022 08:04:48 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so6768445wmp.5; Sat, 05 Mar 2022 08:04:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5CHc8CKH7uLvD0MRz+pjrVdTqF9gV7wQBEMlUwFM4GM=; b=AfcdU295DfZ60SJB0qJHp4pnm4CD3ZkDzQslxY5H+dleyUYaRN2HZCbTb/Qhcvh5NK f4jwKi2FzyeRi9y2tRBAHTYvYKW0h/X71tYXLOhSdKbK0+Bv51OBASDbjoYdbtY2OQec PCro6sNe4zXZA0uAGB+hYWW8XQVbc7GKLAOutxSBPbSxqCYoB0v7baLzaIBnCXMga4+C 2isvRbf4GeRnsrMr9m5wUi7G/2+kcmhSuPsBxwmog/Vi3jRLoYS/6QMxs2T+r+82Lowx 7MA8SMJv5CFYrR8qIj+r3hjX94xk3GzwHkhQiiCZH5lZ+rrdvdW5ZqkYCM4b0jefU00I T/5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5CHc8CKH7uLvD0MRz+pjrVdTqF9gV7wQBEMlUwFM4GM=; b=1rmldlaqkfI1YIp5wbUj3CCzP9ttwOCRnIdmBbIZZmvzqaQUtUHA4vmrTMScZBjSFC gFhNdwZF9EaFqfi/GcoPTY4iBRNgsvjBYzbzzTsWSsRFWSQz3f0EGMFHI4/Rm7FeMVqM 2qkdE5j1yt+a8ds6A8hUm7zeeQeaoKAT4Ou00ai6CPCGXkwEG5+EtJMh5WxwqUAiNDnI BczdAq6BHps0oVHXv04dyokVJdYzNli/8Mah26W7NfcdQ8CjGD5dFarUoM4tFoiT4bkD 51+ERSV1z7lFgobMK4gbZmB2ZhB9Xly3xfQjtQSbQSrg3zVViEEBMvsl3UbyEim/TwtO ewyQ== X-Gm-Message-State: AOAM5339n87YWG80hbJCEyARMALEK9oGN0PJFT91D8UJP5Owp+jQOMcM EPYmNpnw6Q74zyNQf7llfzg= X-Google-Smtp-Source: ABdhPJxdFMnzPUU+1O1iGiA2wtKyD2rs0ohY81KGPvW9SwV+nn7+joGlqJEUJLeHLuFo02Hac3howQ== X-Received: by 2002:a05:600c:205a:b0:380:d03d:9cd5 with SMTP id p26-20020a05600c205a00b00380d03d9cd5mr12069992wmg.89.1646496287010; Sat, 05 Mar 2022 08:04:47 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:46 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 4/9] fs: add optional iostats counters to struct super_block Date: Sat, 5 Mar 2022 18:04:19 +0200 Message-Id: <20220305160424.1040102-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org With CONFIG_FS_IOSTATS, filesystems can opt-in to generic per-sb I/O statistics by setting the FS_SB_IOSTATS fstype flag. These counters will be used to collect per-sb I/O statistics and display them in /proc//mountstats. Signed-off-by: Amir Goldstein --- fs/Kconfig | 8 +++ fs/super.c | 6 ++ include/linux/fs.h | 11 +++- include/linux/fs_iostats.h | 130 +++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 include/linux/fs_iostats.h diff --git a/fs/Kconfig b/fs/Kconfig index 6c7dc1387beb..394d9da6bda9 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -15,6 +15,14 @@ config VALIDATE_FS_PARSER Enable this to perform validation of the parameter description for a filesystem when it is registered. +config FS_IOSTATS + bool "Enable generic filesystem I/O statistics" + help + Enable this to allow collecting filesystem I/O statistics and display + them in /proc//mountstats. + + Say N if unsure. + config FS_IOMAP bool diff --git a/fs/super.c b/fs/super.c index f1d4a193602d..a18930693e54 100644 --- a/fs/super.c +++ b/fs/super.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "internal.h" @@ -179,6 +180,7 @@ static void destroy_unused_super(struct super_block *s) up_write(&s->s_umount); list_lru_destroy(&s->s_dentry_lru); list_lru_destroy(&s->s_inode_lru); + sb_iostats_destroy(s); security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); @@ -230,6 +232,9 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, if (security_sb_alloc(s)) goto fail; + if (type->fs_flags & FS_SB_IOSTATS && sb_iostats_init(s)) + goto fail; + for (i = 0; i < SB_FREEZE_LEVELS; i++) { if (__percpu_init_rwsem(&s->s_writers.rw_sem[i], sb_writers_name[i], @@ -290,6 +295,7 @@ static void __put_super(struct super_block *s) WARN_ON(s->s_dentry_lru.node); WARN_ON(s->s_inode_lru.node); WARN_ON(!list_empty(&s->s_mounts)); + sb_iostats_destroy(s); security_sb_free(s); fscrypt_sb_free(s); put_user_ns(s->s_user_ns); diff --git a/include/linux/fs.h b/include/linux/fs.h index ecb64997c390..f8e7ec81ae0b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1455,6 +1455,8 @@ struct sb_writers { struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS]; }; +struct sb_iostats; + struct super_block { struct list_head s_list; /* Keep this first */ dev_t s_dev; /* search index; _not_ kdev_t */ @@ -1509,8 +1511,12 @@ struct super_block { /* Granularity of c/m/atime in ns (cannot be worse than a second) */ u32 s_time_gran; /* Time limits for c/m/atime in seconds */ - time64_t s_time_min; - time64_t s_time_max; + time64_t s_time_min; + time64_t s_time_max; +#ifdef CONFIG_FS_IOSTATS + /* Optional per-sb I/O stats */ + struct sb_iostats *s_iostats; +#endif #ifdef CONFIG_FSNOTIFY __u32 s_fsnotify_mask; struct fsnotify_mark_connector __rcu *s_fsnotify_marks; @@ -2435,6 +2441,7 @@ struct file_system_type { #define FS_USERNS_MOUNT (1<<3) /* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM (1<<4) /* Disable fanotify permission events */ #define FS_ALLOW_IDMAP (1<<5) /* FS can handle vfs idmappings */ +#define FS_SB_IOSTATS (1<<6) /* FS has generic per-sb I/O stats */ #define FS_RENAME_DOES_D_MOVE (1<<15) /* FS will handle d_move() internally */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; diff --git a/include/linux/fs_iostats.h b/include/linux/fs_iostats.h new file mode 100644 index 000000000000..2db13e9e17fc --- /dev/null +++ b/include/linux/fs_iostats.h @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_FS_IOSTATS_H +#define _LINUX_FS_IOSTATS_H + +#include +#include +#include + +/* Similar to task_io_accounting members */ +enum { + SB_IOSTATS_CHARS_RD, /* bytes read via syscalls */ + SB_IOSTATS_CHARS_WR, /* bytes written via syscalls */ + SB_IOSTATS_SYSCALLS_RD, /* # of read syscalls */ + SB_IOSTATS_SYSCALLS_WR, /* # of write syscalls */ + SB_IOSTATS_COUNTERS_NUM +}; + +struct sb_iostats { + time64_t start_time; + struct percpu_counter counter[SB_IOSTATS_COUNTERS_NUM]; +}; + +#ifdef CONFIG_FS_IOSTATS +static inline struct sb_iostats *sb_iostats(struct super_block *sb) +{ + return sb->s_iostats; +} + +static inline bool sb_has_iostats(struct super_block *sb) +{ + return !!sb->s_iostats; +} + +/* Initialize per-sb I/O stats */ +static inline int sb_iostats_init(struct super_block *sb) +{ + int err; + + if (sb->s_iostats) + return 0; + + sb->s_iostats = kmalloc(sizeof(struct sb_iostats), GFP_KERNEL); + if (!sb->s_iostats) + return -ENOMEM; + + err = percpu_counters_init(sb->s_iostats->counter, + SB_IOSTATS_COUNTERS_NUM, 0, GFP_KERNEL); + if (err) { + kfree(sb->s_iostats); + sb->s_iostats = NULL; + return err; + } + + sb->s_iostats->start_time = ktime_get_seconds(); + return 0; +} + +static inline void sb_iostats_destroy(struct super_block *sb) +{ + if (!sb->s_iostats) + return; + + percpu_counters_destroy(sb->s_iostats->counter, + SB_IOSTATS_COUNTERS_NUM); + kfree(sb->s_iostats); + sb->s_iostats = NULL; +} + +static inline void sb_iostats_counter_inc(struct super_block *sb, int id) +{ + if (!sb->s_iostats) + return; + + percpu_counter_inc_relaxed(&sb->s_iostats->counter[id]); +} + +static inline void sb_iostats_counter_add(struct super_block *sb, int id, + s64 amt) +{ + if (!sb->s_iostats) + return; + + percpu_counter_add_relaxed(&sb->s_iostats->counter[id], amt); +} + +static inline s64 sb_iostats_counter_read(struct super_block *sb, int id) +{ + if (!sb->s_iostats) + return 0; + + return percpu_counter_sum_positive(&sb->s_iostats->counter[id]); +} + +#else /* !CONFIG_FS_IOSTATS */ + +static inline struct sb_iostats *sb_iostats(struct super_block *sb) +{ + return NULL; +} + +static inline bool sb_has_iostats(struct super_block *sb) +{ + return false; +} + +static inline int sb_iostats_init(struct super_block *sb) +{ + return 0; +} + +static inline void sb_iostats_destroy(struct super_block *sb) +{ +} + +static inline void sb_iostats_counter_inc(struct super_block *sb, int id) +{ +} + +static inline void sb_iostats_counter_add(struct super_block *sb, int id, + s64 amt) +{ +} + +static inline s64 sb_iostats_counter_read(struct super_block *sb, int id) +{ + return 0; +} +#endif + +#endif /* _LINUX_FS_IOSTATS_H */ From patchwork Sat Mar 5 16:04:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770421 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DD91C43217 for ; Sat, 5 Mar 2022 16:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232008AbiCEQFs (ORCPT ); Sat, 5 Mar 2022 11:05:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231998AbiCEQFp (ORCPT ); Sat, 5 Mar 2022 11:05:45 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A744527FB; Sat, 5 Mar 2022 08:04:50 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id j17so16975020wrc.0; Sat, 05 Mar 2022 08:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FcuiD2GTRh1jKD6riWIdoaj4V02D0ZKz+QuzZ5wgQGU=; b=Rwn3Eyg5/Som6eX6+n+/G/om90aW3CoxBdaqpO9BZ+Q40A3jl16O4IHN715Egvirqq 36hXGa770Kvbp/b8595OlbkXGhnzaUPIzO0RIm34wMeD1CwiYLypomNuwyNfxPFgipcr O65KT/eBIkiMtOtksgbbu7DmiyVstakDBM0LgjTYO+NzY6+1VGlszI06Ubln6Hu4dxDv mkBR3oO3mKWipP7WflZbqkI6JdwKpGeBjYDCQwXZY9p5poY1HBJ0WmDTl9YafC9Icpu6 D3TrTDy/I47RCxMphjkvhxdJV4oyerbfsbraHthmqMCjyItJY8m3S6Qxy2SkqPsIQtLz 2siw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FcuiD2GTRh1jKD6riWIdoaj4V02D0ZKz+QuzZ5wgQGU=; b=U9Uu5LxeoxpbPc9zib1Drvi8vtfNRiTnxHYu01AIx/ZEkP+exFLzblPFsWsSuRk7Gd J63GCrqu8dfNDLOzypCUOWkD8Mkmv2/2LoPb3QKpqKbjVG1vClyjX82GejfAGJZucUGV ZnbLoIxhM480G4apDayJfUSJoVuxGA/mv4u8ZIrXR3FisYaSKalvhr9Wzf2bhaA6w6Rj SJRQaB/ktV3kL/C/UG7ikpaYXozY9Ic2xPKUzTekCij3tLYrtfwWJWNl28/XIz00W/rZ yI2/l7aNFRRiH1XkDwiu3ATnjAnqozeV46UftUdeDp+O9NnJNLAnFPOXORq9gGZfjQOc b8hQ== X-Gm-Message-State: AOAM533N4HoEfxApV1VyxJkO7xvliFZ2d28je1y4eua99YPvMGJI8uwf SaSWcXUgP26rk72SqFiLh4c= X-Google-Smtp-Source: ABdhPJxbG0YgMfH7AalD4bl48AHqlO8NwmV7Eay438yKe6WJnJy9fnHAk78EibAzk/8aE+Hy/xAnnA== X-Received: by 2002:a5d:6392:0:b0:1f0:651d:51ac with SMTP id p18-20020a5d6392000000b001f0651d51acmr2895301wru.253.1646496288526; Sat, 05 Mar 2022 08:04:48 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:48 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 5/9] fs: collect per-sb io stats Date: Sat, 5 Mar 2022 18:04:20 +0200 Message-Id: <20220305160424.1040102-6-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Replace task io account helpers with wrappers that may also collect per-sb io stats for filesystems that have per-sb io stats enabled. Signed-off-by: Amir Goldstein --- fs/read_write.c | 88 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 0074afa7ecb3..8c599bf2dd78 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "internal.h" #include @@ -34,6 +35,45 @@ const struct file_operations generic_ro_fops = { EXPORT_SYMBOL(generic_ro_fops); +static inline void file_iostats_counter_inc(struct file *file, int id) +{ + if (file) + sb_iostats_counter_inc(file->f_path.mnt->mnt_sb, id); +} + +static inline void file_iostats_counter_add(struct file *file, int id, + ssize_t amt) +{ + if (file) + sb_iostats_counter_add(file->f_path.mnt->mnt_sb, id, amt); +} + +static void file_add_rchar(struct file *file, struct task_struct *tsk, + ssize_t amt) +{ + file_iostats_counter_add(file, SB_IOSTATS_CHARS_RD, amt); + add_rchar(tsk, amt); +} + +static void file_add_wchar(struct file *file, struct task_struct *tsk, + ssize_t amt) +{ + file_iostats_counter_add(file, SB_IOSTATS_CHARS_WR, amt); + add_wchar(tsk, amt); +} + +static void file_inc_syscr(struct file *file, struct task_struct *tsk) +{ + file_iostats_counter_inc(file, SB_IOSTATS_SYSCALLS_RD); + inc_syscr(current); +} + +static void file_inc_syscw(struct file *file, struct task_struct *tsk) +{ + file_iostats_counter_inc(file, SB_IOSTATS_SYSCALLS_WR); + inc_syscw(current); +} + static inline bool unsigned_offsets(struct file *file) { return file->f_mode & FMODE_UNSIGNED_OFFSET; @@ -441,9 +481,9 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) if (pos) *pos = kiocb.ki_pos; fsnotify_access(file); - add_rchar(current, ret); + file_add_rchar(file, current, ret); } - inc_syscr(current); + file_inc_syscr(file, current); return ret; } @@ -483,9 +523,9 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) ret = -EINVAL; if (ret > 0) { fsnotify_access(file); - add_rchar(current, ret); + file_add_rchar(file, current, ret); } - inc_syscr(current); + file_inc_syscr(file, current); return ret; } @@ -537,9 +577,9 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t if (pos) *pos = kiocb.ki_pos; fsnotify_modify(file); - add_wchar(current, ret); + file_add_wchar(file, current, ret); } - inc_syscw(current); + file_inc_syscw(file, current); return ret; } /* @@ -592,9 +632,9 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ ret = -EINVAL; if (ret > 0) { fsnotify_modify(file); - add_wchar(current, ret); + file_add_wchar(file, current, ret); } - inc_syscw(current); + file_inc_syscw(file, current); file_end_write(file); return ret; } @@ -947,8 +987,8 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec, } if (ret > 0) - add_rchar(current, ret); - inc_syscr(current); + file_add_rchar(f.file, current, ret); + file_inc_syscr(f.file, current); return ret; } @@ -971,8 +1011,8 @@ static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec, } if (ret > 0) - add_wchar(current, ret); - inc_syscw(current); + file_add_wchar(f.file, current, ret); + file_inc_syscw(f.file, current); return ret; } @@ -1000,8 +1040,8 @@ static ssize_t do_preadv(unsigned long fd, const struct iovec __user *vec, } if (ret > 0) - add_rchar(current, ret); - inc_syscr(current); + file_add_rchar(f.file, current, ret); + file_inc_syscr(f.file, current); return ret; } @@ -1023,8 +1063,8 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec, } if (ret > 0) - add_wchar(current, ret); - inc_syscw(current); + file_add_wchar(f.file, current, ret); + file_inc_syscw(f.file, current); return ret; } @@ -1250,8 +1290,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, } if (retval > 0) { - add_rchar(current, retval); - add_wchar(current, retval); + file_add_rchar(in.file, current, retval); + file_add_wchar(out.file, current, retval); fsnotify_access(in.file); fsnotify_modify(out.file); out.file->f_pos = out_pos; @@ -1261,8 +1301,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, in.file->f_pos = pos; } - inc_syscr(current); - inc_syscw(current); + file_inc_syscr(in.file, current); + file_inc_syscw(out.file, current); if (pos > max) retval = -EOVERFLOW; @@ -1511,13 +1551,13 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, done: if (ret > 0) { fsnotify_access(file_in); - add_rchar(current, ret); + file_add_rchar(file_in, current, ret); fsnotify_modify(file_out); - add_wchar(current, ret); + file_add_wchar(file_out, current, ret); } - inc_syscr(current); - inc_syscw(current); + file_inc_syscr(file_in, current); + file_inc_syscw(file_out, current); file_end_write(file_out); From patchwork Sat Mar 5 16:04:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770423 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35EA4C433F5 for ; Sat, 5 Mar 2022 16:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232021AbiCEQFv (ORCPT ); Sat, 5 Mar 2022 11:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232001AbiCEQFp (ORCPT ); Sat, 5 Mar 2022 11:05:45 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449B5652CE; Sat, 5 Mar 2022 08:04:51 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id c192so6671449wma.4; Sat, 05 Mar 2022 08:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gl15jVHDWqQUQcpXGK7b6MQUnuZpOd6NqFaENFI8dkU=; b=NGT+lmyuM3B8f/o23zzVpt18DkPE+YnPfDiBMv0xJX9yW28ILYB7HoN3niGKsRrvtS rupYn6Qa+RnL7rgz2qSaAxxtyM/q4y7G5zU7W1ZDiJZdqFXr54CM9uU+/+mxRBerPxlk xSswoIRT97p5+jZyf948JagexhFdnii1VDJbO34oZtjH/YdCHfKvXPkEhsZvDdotNrk+ dk1rLZ+nX/FQuYcTGoTKf3a7nxvbpw35Qha8JdG1GYShBxuTjWf28qquWeqOGObwhgg8 VyxX5WSviA6cXM+FBF7ehUyeA8kEPN3bmZemQdxr7KAo9/ns2V7mNUKxZNffLskd072V PoiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gl15jVHDWqQUQcpXGK7b6MQUnuZpOd6NqFaENFI8dkU=; b=ojKPGUVC7SB+yrQT6DXM1/W3FwowjuaCA2/7MfVdwH6s1CmGutfwwdARC3L/pWQPhC oP34hLBWroUEZ5CpG1QESiM4bvbyLLR2ZTYYFR36w7whGkqdmgxAg57+lM/OiByCNoBr oMI+nKDJqgL6Vi4e80ErJSTvSH2/KyF7pB2fFnLf9VcaOBPTbuHno2M7Jd2zTc3QSh0s 7uC4Gb5UNahGIg739KaxkUPy1rYxkfhr9kH02DhdFTYPr/HVmke50HFnBIpK5WIRD87T D6fWAdZ/74MPBCWdyFF8v19msBVL2UNcfeq/KWPQTO6IY09aAkqSeBtHF0/G+jW7qDXf PGyA== X-Gm-Message-State: AOAM531dnebIgNNyfbI1kJVoqe01ulera7dFj1LpOf4e/E7cYFg7O8Gk xIZ0bMhzgf3LhTfIpvudM+FrRF7ftOM= X-Google-Smtp-Source: ABdhPJwzSqC7SMuIZY0VYJ23xyzOpk5c2DMYmZ19g11IitMRBy+GdmJLnfLURcnoJt4dkB+T8rvYfA== X-Received: by 2002:a05:600c:3d99:b0:381:546c:8195 with SMTP id bi25-20020a05600c3d9900b00381546c8195mr12006349wmb.112.1646496289826; Sat, 05 Mar 2022 08:04:49 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:49 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 6/9] fs: report per-sb io stats Date: Sat, 5 Mar 2022 18:04:21 +0200 Message-Id: <20220305160424.1040102-7-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Show optional collected per-sb io stats in /proc//mountstats for filesystems that do not implement their own show_stats() method and have generic per-sb stats enabled. Signed-off-by: Amir Goldstein --- fs/proc_namespace.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index 49650e54d2f8..9054a909e031 100644 --- a/fs/proc_namespace.c +++ b/fs/proc_namespace.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "proc/internal.h" /* only for get_proc_task() in ->open() */ @@ -232,6 +233,21 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt) if (sb->s_op->show_stats) { seq_putc(m, ' '); err = sb->s_op->show_stats(m, mnt_path.dentry); + } else if (sb_has_iostats(sb)) { + struct sb_iostats *iostats = sb_iostats(sb); + + /* Similar to /proc//io */ + seq_printf(m, "\n" + "\ttimes: %lld %lld\n" + "\trchar: %lld\n" + "\twchar: %lld\n" + "\tsyscr: %lld\n" + "\tsyscw: %lld\n", + iostats->start_time, ktime_get_seconds(), + sb_iostats_counter_read(sb, SB_IOSTATS_CHARS_RD), + sb_iostats_counter_read(sb, SB_IOSTATS_CHARS_WR), + sb_iostats_counter_read(sb, SB_IOSTATS_SYSCALLS_RD), + sb_iostats_counter_read(sb, SB_IOSTATS_SYSCALLS_WR)); } seq_putc(m, '\n'); From patchwork Sat Mar 5 16:04:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770424 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29C2CC433EF for ; Sat, 5 Mar 2022 16:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231774AbiCEQFx (ORCPT ); Sat, 5 Mar 2022 11:05:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232007AbiCEQFp (ORCPT ); Sat, 5 Mar 2022 11:05:45 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9919454BCA; Sat, 5 Mar 2022 08:04:52 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id o18-20020a05600c4fd200b003826701f847so8246357wmq.4; Sat, 05 Mar 2022 08:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hK1LzTjIk6ekWwoL6fV3lgEDT91apb0sc/qKFWvkbwM=; b=GkGHEWXxoTrPmH7Mk9MIFj2BM8l3ufOFVCLLXWHxR8bK3DVGd/dDIhbYk6gclKD6bf hjgotmE9sslhMjmATEfbG+Up6lv6K7UPNisDm2UYrD+6IlKR7ml+TJGbaR6hi2GXj1ac ogycxiqdjNjvQFyTIS4i3WRLDZRXjVvfDH5shzXYp59T6OEA5D50f2FDaIYrD+e9HHwt K0jElp3++G9O8aNq4XNwqPS/DEGlgm9UEmmN3ubFNfgflBoUl8cq1hNkiCkvBE98NI5s FM9iU9O1d1E6/VYPevFmtxQYSlFrfR5fk8ZxHOX7r5t1I2cQLfAJfbshcnM7YgaLZLav dJtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hK1LzTjIk6ekWwoL6fV3lgEDT91apb0sc/qKFWvkbwM=; b=7FpwxCKrRR76O9GclVsK3nA6i8l00o0T9ZXIVaATuRpRR87a+oP+LFNLZEHRFwgITI +bCQEEwMml5ifqi/FiB+wfOfyoB3rTiEYXhep7vNNFnDUJFquTiTpI3vekot/HbowRvC 0z1KlweCtaV6AUpxLUsUiCRB+uem+ERtouAIpPo/Jnv4BQg96/0nJqREhwKvyoHV6txQ 9XDTij3bcj+FYzrjgn4eEZTJmxgyiEoZDQvxHH4AHLCr0W2mdAotxmz/zmvIoSg9svWg vc8+KahPoIpMYNhCnZLLsCVB4vH7LJgQSqv3z65L1AqPZWRiYT5hJoI/oUH5HsBSH3gh UGQA== X-Gm-Message-State: AOAM530bDQZ9K3UDcr6FM9Y0zcBlU36wnDxQyc1PdmNAOAKN6CJMlbwc j6UoGjq2ItpWT/DjVtKDRFw= X-Google-Smtp-Source: ABdhPJxg6VAl9eZiZSmVUrGkXdtNwip7gD1K7QQ4gpXJAXSjwMqfIP6PnbCdp9EovoVRJ8r6YXTOAw== X-Received: by 2002:a05:600c:3541:b0:389:95b2:5f63 with SMTP id i1-20020a05600c354100b0038995b25f63mr2249235wmq.126.1646496291198; Sat, 05 Mar 2022 08:04:51 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:50 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 7/9] ovl: opt-in for per-sb io stats Date: Sat, 5 Mar 2022 18:04:22 +0200 Message-Id: <20220305160424.1040102-8-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Traditionally, system administrators have used the iostat utility to track the amount of io performed to a local disk filesystem. Similar functionality is provided for NFS mounts via the nfsstat utility that reads the NFS client's stats from /proc/pid/mountstats. There is currently no good way for a system administrator or a monitoring application inside a container to track the amount of io performed via overlayfs. Opt-in for generic io stats via /proc/pid/mountstats to provide that functionality. This feature depends on CONFIG_FS_IOSTATS. Signed-off-by: Amir Goldstein --- fs/overlayfs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 7bb0a47cb615..4a5847bca1a6 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -2165,7 +2166,7 @@ static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags, static struct file_system_type ovl_fs_type = { .owner = THIS_MODULE, .name = "overlay", - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_SB_IOSTATS, .mount = ovl_mount, .kill_sb = kill_anon_super, }; From patchwork Sat Mar 5 16:04:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770425 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B752C433FE for ; Sat, 5 Mar 2022 16:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231997AbiCEQFy (ORCPT ); Sat, 5 Mar 2022 11:05:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232016AbiCEQFq (ORCPT ); Sat, 5 Mar 2022 11:05:46 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D35A38BE0; Sat, 5 Mar 2022 08:04:54 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id n15so2781562wra.6; Sat, 05 Mar 2022 08:04:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LwkEll/Fp2m1q/Q8MPQnu9BfhDdiF2uLgfkNWk7jG1o=; b=c8xfrY5KMxjGvAbdGOgwAAuBDQDUEomIJbz3cBMAkBlT3hYDhKNB/IssIKsfrbzz40 C4wsUqOZhH6LQyPd7Q0VsTBE6/tGHr0yDcT+odnUfukSHqW3qNesQomZNJF5s89vpBkf M4hySUX9hx9u3JLu8qPbjwWvwIg1WK4f7MsXE8q1d9QbtC+2/TFqzSnlLneoHT4GSWUV zxmTpUnNGIxUfC46J544RzUlYJhP4mMM3BO1a9jFCPWpZIjyg/Eg5xwkJQkY6ajk0ncF hiWXiyOFGCLCamxhSC8sk82XnG6yUPQOixmY2HRSEY1oExsintzR9NgmrUwXX06bI+OR yTaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LwkEll/Fp2m1q/Q8MPQnu9BfhDdiF2uLgfkNWk7jG1o=; b=oA3DLQCOFRqbj/u1IV/j8KQ5X23nHldM6PTwLZyxX3VsqtWzt3cHDZYACruWvwvOSI LjI8Xo9bw6dfVy66Y6YpKkUfQQEgVcmP1cdoIGzfebk+JtzaotXXbv3We69R8zVZW3su fmE8db5z/fQUVGIS/wA0K3p+XFSovs8apH1LjIqJZ/XmaYqIaVFcUJaX7gRPtRslHDjA Mxlc6npqh03wgNuwh7dAN7GFWiblc3ccOKumfXPXmHCXBfmsj9egxeAstXN8wmjYhAR6 3lbAr1PQDjaBvb9fz7ewE0d1YVzJJ46q5gZP5TkG/GOr162pSHvnz0P/wExkhAXr8YnM 73QA== X-Gm-Message-State: AOAM532DmVLpBAZMaOtsVs+275BbVlETMbwPO4IhNMJ9K/tvNeGAchGm J7qBA66fuhTUYRtE5mMfgQU= X-Google-Smtp-Source: ABdhPJwGvoYr/6vkLkjML4gFOAxQ7zCfqGtN6TOiFIiJi3ZZz6Vacwc2+Y2wT1k/tLZ1HfDeBJ7oCQ== X-Received: by 2002:a5d:6da1:0:b0:1e3:2bf5:13c with SMTP id u1-20020a5d6da1000000b001e32bf5013cmr3018931wrs.316.1646496292881; Sat, 05 Mar 2022 08:04:52 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:52 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 8/9] fuse: opt-in for per-sb io stats Date: Sat, 5 Mar 2022 18:04:23 +0200 Message-Id: <20220305160424.1040102-9-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Traditionally, system administrators have used the iostat utility to track the amount of io performed to a local disk filesystem. Similar functionality is provided for NFS mounts via the nfsstat utility that reads the NFS client's stats from /proc/pid/mountstats. There is currently no good way for a system administrator or a monitoring application to track the amount of io performed via fuse filesystems. Opt-in for generic io stats via /proc/pid/mountstats to provide that functionality. It is possible to collect io stats on the server side inside libfuse, but those io stats will not cover cached writes and reads. Therefore, implementing the server side io stats would be complementary to these client side io stats. Also, this feature provides the io stats for existing fuse filesystem/lib release binaries. This feature depends on CONFIG_FS_IOSTATS. Signed-off-by: Amir Goldstein --- fs/fuse/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 9ee36aa73251..a2cd90e059f8 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1806,7 +1807,7 @@ static void fuse_kill_sb_anon(struct super_block *sb) static struct file_system_type fuse_fs_type = { .owner = THIS_MODULE, .name = "fuse", - .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT, + .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT | FS_SB_IOSTATS, .init_fs_context = fuse_init_fs_context, .parameters = fuse_fs_parameters, .kill_sb = fuse_kill_sb_anon, From patchwork Sat Mar 5 16:04:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12770426 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC1CBC433F5 for ; Sat, 5 Mar 2022 16:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232007AbiCEQFz (ORCPT ); Sat, 5 Mar 2022 11:05:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbiCEQFq (ORCPT ); Sat, 5 Mar 2022 11:05:46 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A256518CC50; Sat, 5 Mar 2022 08:04:55 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id i66so6671121wma.5; Sat, 05 Mar 2022 08:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=upK+r5bGarAos+F72cjx71QAT29yIXZ4291fjq5oru0=; b=iqSK7Ddsf9Vq6/L3TpAxkesAk19RGszbk9snI6jOGr46XHHMtDJL0gwBZW3p7fxgfy zSLUfMwK+ZNWGfLE1PO8JrxO3Yk6dGf6ir3sx+xcoi8Ds0ztGSS7OKlrm1I8J7TM45Ji NDybf3WPXniD/vAPUWxND/DkVlrOIByS+SywNgeSX8sPQOgMH6d06yqLcuKFD1g/duoQ ja2g+C6bMU82ZprwyveJCkYExqWBywV+vt1TsdUp7Xka2KN/zxI7jQoqY4Qr4WNCG21f Vz9IGV/rU0CxwHk8Dyf+MRhTNQildWsenXOomVx/odVwxPpBkZVqgybV3nmIzATQ8wHd 6uhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=upK+r5bGarAos+F72cjx71QAT29yIXZ4291fjq5oru0=; b=MHNxhvWEpxRf7vJ+3caVD+SwWhtd2GTyC21RqttN+U3aKCQgfj23Vig9G3r8lKOE75 EQfdh2H4iccksiF3jIkcY2GbTOByQU+vUsSHh5zMU0mC6qCtPecmVr8ytJIClVRe4Cwe C51vwPy6bKy+N4LSyGFgK3wQt4dqTor41HK/vOn3kSzc3ncFLs/2NIZXljMx61IeEFVt wCHz9/bslm4G3gjDMek+4kbV273RHMOglj264v2ZuhKVI5kN+jcfBmT7bNynUB4gr304 4DV+OTWeWvJn4f9YeTOiYLe/wGkZL/k1PCsFg3ygpMUhtpcT1Z7KMwkv/W9PjX8AffhE CCug== X-Gm-Message-State: AOAM530lAjhCAX9Dw2k0Rx//dFMq9av5KMJXRjb1qhaq4KDYBHLW+Dec SDTw+zAFDufeCaCXwN2IUuE= X-Google-Smtp-Source: ABdhPJxX/uFQS1YsNh4MAfmtV+HP82Vkk6OnTAqo1x4vPWpbuucAjtD9p1NyKDXssa/1JJaag9dbTg== X-Received: by 2002:a1c:7916:0:b0:389:8d21:caa9 with SMTP id l22-20020a1c7916000000b003898d21caa9mr2816774wme.106.1646496294166; Sat, 05 Mar 2022 08:04:54 -0800 (PST) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id n5-20020a5d5985000000b001f0122f63e1sm1650717wri.85.2022.03.05.08.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Mar 2022 08:04:53 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Dave Chinner , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 9/9] fs: enable per-sb io stats for all blockdev filesystems Date: Sat, 5 Mar 2022 18:04:24 +0200 Message-Id: <20220305160424.1040102-10-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com> References: <20220305160424.1040102-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In addition to filesystems that opt-in with FS_SB_IOSTATS, auto-enable per-sb I/O stats for all blockdev filesystems. This can be used by tools like iotop to display the total I/O stats via sb along side the submitted I/O stats to block device to get a more complete view that also includes the cached I/O stats. Link: https://lore.kernel.org/linux-fsdevel/20220302211226.GG3927073@dread.disaster.area/ Suggested-by: Dave Chinner Signed-off-by: Amir Goldstein --- fs/super.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/super.c b/fs/super.c index a18930693e54..e1bee46dfb5a 100644 --- a/fs/super.c +++ b/fs/super.c @@ -232,7 +232,12 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, if (security_sb_alloc(s)) goto fail; - if (type->fs_flags & FS_SB_IOSTATS && sb_iostats_init(s)) + /* + * Account per-sb I/O stats for all blockdev filesystems and for + * filesystems that opt-in with FS_SB_IOSTATS. + */ + if (type->fs_flags & (FS_SB_IOSTATS | FS_REQUIRES_DEV) && + sb_iostats_init(s)) goto fail; for (i = 0; i < SB_FREEZE_LEVELS; i++) {