From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Dave Chinner <david@fromorbit.com>,
Al Viro <viro@zeniv.linux.org.uk>,
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 [thread overview]
Message-ID: <20220305160424.1040102-2-amir73il@gmail.com> (raw)
In-Reply-To: <20220305160424.1040102-1-amir73il@gmail.com>
Counter that are only read with percpu_counter_sum() can use an
arbitrary large batch size.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
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 */
--
2.25.1
next prev parent reply other threads:[~2022-03-05 16:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-05 16:04 [PATCH v4 0/9] Generic per-sb io stats Amir Goldstein
2022-03-05 16:04 ` Amir Goldstein [this message]
2022-03-05 16:04 ` [PATCH v4 2/9] lib/percpu_counter: add helpers for arrays of counters Amir Goldstein
2022-03-08 10:03 ` Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 3/9] fs: tidy up fs_flags definitions Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 4/9] fs: add optional iostats counters to struct super_block Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 5/9] fs: collect per-sb io stats Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 6/9] fs: report " Amir Goldstein
2022-03-10 9:53 ` Miklos Szeredi
2022-03-10 10:45 ` Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 7/9] ovl: opt-in for " Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 8/9] fuse: " Amir Goldstein
2022-03-05 16:04 ` [PATCH v4 9/9] fs: enable per-sb io stats for all blockdev filesystems Amir Goldstein
2022-03-06 4:18 ` [PATCH v4 0/9] Generic per-sb io stats Theodore Ts'o
2022-03-06 7:55 ` Amir Goldstein
2022-03-07 0:14 ` Dave Chinner
2022-03-07 10:04 ` Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220305160424.1040102-2-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).