[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211208183906.548393311@infradead.org>
Date: Wed, 08 Dec 2021 19:36:58 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: will@...nel.org, boqun.feng@...il.com
Cc: linux-kernel@...r.kernel.org, x86@...nel.org, peterz@...radead.org,
mark.rutland@....com, elver@...gle.com, keescook@...omium.org,
hch@...radead.org, torvalds@...ux-foundation.org
Subject: [RFC][PATCH 3/5] refcount: Improve out-of-line code-gen
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@...radead.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);
Powered by blists - more mailing lists