From: Peter Zijlstra <peterz@infradead.org>
To: will@kernel.org, boqun.feng@gmail.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
peterz@infradead.org, mark.rutland@arm.com, elver@google.com,
keescook@chromium.org, hch@infradead.org,
torvalds@linux-foundation.org
Subject: [RFC][PATCH 3/5] refcount: Improve out-of-line code-gen
Date: Wed, 08 Dec 2021 19:36:58 +0100 [thread overview]
Message-ID: <20211208183906.548393311@infradead.org> (raw)
In-Reply-To: 20211208183655.251963904@infradead.org
Allow a number of ops to tail-call refcount_warn_saturate() in order
to generate smaller out-of-line code.
text data bss dec hex filename
97341 4985 1116 103442 19412 defconfig-build/kernel/events/core.o
97299 4985 1116 103400 193e8 defconfig-build/kernel/events/core.o
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/refcount.h | 9 ++++-----
lib/refcount.c | 4 +++-
2 files changed, 7 insertions(+), 6 deletions(-)
--- a/include/linux/refcount.h
+++ b/include/linux/refcount.h
@@ -124,7 +124,7 @@ enum refcount_saturation_type {
REFCOUNT_DEC_LEAK,
};
-void refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t);
+bool refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t);
/**
* refcount_set - set a refcount's value
@@ -160,7 +160,7 @@ static inline __must_check bool __refcou
*oldp = old;
if (unlikely(old < 0 || old + i < 0))
- refcount_warn_saturate(r, REFCOUNT_ADD_NOT_ZERO_OVF);
+ return refcount_warn_saturate(r, REFCOUNT_ADD_NOT_ZERO_OVF);
return old;
}
@@ -283,7 +283,7 @@ static inline __must_check bool __refcou
}
if (unlikely(old < 0 || old - i < 0))
- refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
+ return refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
return false;
}
@@ -335,8 +335,7 @@ static inline __must_check bool refcount
{
return atomic_dec_and_test_ofl(&r->refs, Eoverflow);
Eoverflow:
- refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
- return false;
+ return refcount_warn_saturate(r, REFCOUNT_SUB_UAF);
}
static inline void __refcount_dec(refcount_t *r, int *oldp)
--- a/lib/refcount.c
+++ b/lib/refcount.c
@@ -10,7 +10,7 @@
#define REFCOUNT_WARN(str) WARN_ONCE(1, "refcount_t: " str ".\n")
-void refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t)
+bool refcount_warn_saturate(refcount_t *r, enum refcount_saturation_type t)
{
int old = refcount_read(r);
refcount_set(r, REFCOUNT_SATURATED);
@@ -38,6 +38,8 @@ void refcount_warn_saturate(refcount_t *
default:
REFCOUNT_WARN("unknown saturation event!?");
}
+
+ return false;
}
EXPORT_SYMBOL(refcount_warn_saturate);
next prev parent reply other threads:[~2021-12-08 18:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-08 18:36 [RFC][PATCH 0/5] refcount: Improve code-gen Peter Zijlstra
2021-12-08 18:36 ` [RFC][PATCH 1/5] atomic: Introduce atomic_{inc,dec,dec_and_test}_ofl() Peter Zijlstra
2021-12-09 12:42 ` Mark Rutland
2021-12-09 13:34 ` Peter Zijlstra
2021-12-08 18:36 ` [RFC][PATCH 2/5] refcount: Use atomic_*_ofl() Peter Zijlstra
2021-12-08 19:19 ` Peter Zijlstra
2021-12-08 20:56 ` Peter Zijlstra
2021-12-09 13:17 ` Mark Rutland
2021-12-09 17:00 ` Mark Rutland
2021-12-08 18:36 ` Peter Zijlstra [this message]
2021-12-09 8:33 ` [RFC][PATCH 3/5] refcount: Improve out-of-line code-gen Peter Zijlstra
2021-12-09 17:51 ` Linus Torvalds
2021-12-08 18:36 ` [RFC][PATCH 4/5] atomic,x86: Implement atomic_dec_and_test_ofl() Peter Zijlstra
2021-12-08 18:37 ` [RFC][PATCH 5/5] atomic: Document the atomic_{}_ofl() functions Peter Zijlstra
2021-12-09 8:25 ` [RFC][PATCH 0/5] refcount: Improve code-gen Peter Zijlstra
2021-12-09 16:19 ` Jens Axboe
2021-12-09 16:51 ` Peter Zijlstra
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=20211208183906.548393311@infradead.org \
--to=peterz@infradead.org \
--cc=boqun.feng@gmail.com \
--cc=elver@google.com \
--cc=hch@infradead.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=torvalds@linux-foundation.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/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