]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
jump_label: Reduce the size of struct static_key
authorJason Baron <jbaron@akamai.com>
Fri, 3 Feb 2017 20:42:24 +0000 (15:42 -0500)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 15 Feb 2017 14:02:26 +0000 (09:02 -0500)
commit3821fd35b58dba449bd894014fbf4e1c43c9e951
tree1cda103a9fd67edb26a225ce1679ac3c83595903
parent7257634135c247de235f3cdfdaa22f9eb5f054e4
jump_label: Reduce the size of struct static_key

The static_key->next field goes mostly unused. The field is used for
associating module uses with a static key. Most uses of struct static_key
define a static key in the core kernel and make use of it entirely within
the core kernel, or define the static key in a module and make use of it
only from within that module. In fact, of the ~3,000 static keys defined,
I found only about 5 or so that did not fit this pattern.

Thus, we can remove the static_key->next field entirely and overload
the static_key->entries field. That is, when all the static_key uses
are contained within the same module, static_key->entries continues
to point to those uses. However, if the static_key uses are not contained
within the module where the static_key is defined, then we allocate a
struct static_key_mod, store a pointer to the uses within that
struct static_key_mod, and have the static key point at the static_key_mod.
This does incur some extra memory usage when a static_key is used in a
module that does not define it, but since there are only a handful of such
cases there is a net savings.

In order to identify if the static_key->entries pointer contains a
struct static_key_mod or a struct jump_entry pointer, bit 1 of
static_key->entries is set to 1 if it points to a struct static_key_mod and
is 0 if it points to a struct jump_entry. We were already using bit 0 in a
similar way to store the initial value of the static_key. This does mean
that allocations of struct static_key_mod and that the struct jump_entry
tables need to be at least 4-byte aligned in memory. As far as I can tell
all arches meet this criteria.

For my .config, the patch increased the text by 778 bytes, but reduced
the data + bss size by 14912, for a net savings of 14,134 bytes.

   text    data     bss     dec     hex filename
8092427 5016512  790528 13899467  d416cb vmlinux.pre
8093205 5001600  790528 13885333  d3df95 vmlinux.post

Link: http://lkml.kernel.org/r/1486154544-4321-1-git-send-email-jbaron@akamai.com
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Jason Baron <jbaron@akamai.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Documentation/static-keys.txt
include/linux/jump_label.h
kernel/jump_label.c