Re: [PATCH 03/17] mm: page_alloc: Use jump labels to avoid checking number_of_cpusets
From: Peter Zijlstra
Date: Wed May 07 2014 - 05:04:31 EST
On Tue, May 06, 2014 at 11:21:18PM +0100, Mel Gorman wrote:
> On Tue, May 06, 2014 at 10:23:50PM +0200, Peter Zijlstra wrote:
> > Why the HAVE_JUMP_LABEL and number_of_cpusets thing? When
> > !HAVE_JUMP_LABEL the static_key thing reverts to an atomic_t and
> > static_key_false() becomes:
> >
>
> Because number_of_cpusets is used to size a kmalloc(). Potentially I could
> abuse the internals of static keys and use the value of key->enabled but
> that felt like abuse of the API.
But are those ifdefs worth the saving of 4 bytes of .data?
That said, I see no real problem adding static_key_count(). Static keys
(jump labels back then) were specifically designed to include the count
and act as 'ref/usage' counter. Its just that so far everybody only
cared about the boolean 'are there users' question, but there is no
reason not to also return the full count.
Maybe I should also do a patch that renames the static_key::enabled
field to static_key::count to better reflect this.
---
include/linux/jump_label.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 5c1dfb2a9e73..1a48d16622aa 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -197,4 +197,9 @@ static inline bool static_key_enabled(struct static_key *key)
return (atomic_read(&key->enabled) > 0);
}
+static inline int static_key_count(struct static_key *key)
+{
+ return atomic_read(&key->enabled);
+}
+
#endif /* _LINUX_JUMP_LABEL_H */
Attachment:
pgpLfr1FJRIEf.pgp
Description: PGP signature