From: Alexey Dobriyan <adobriyan@gmail.com>
To: akpm@linux-foundation.org
Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com,
iamjoonsoo.kim@lge.com, linux-mm@kvack.org, adobriyan@gmail.com
Subject: [PATCH 02/25] slab: make kmalloc_index() return "unsigned int"
Date: Mon, 5 Mar 2018 23:07:07 +0300 [thread overview]
Message-ID: <20180305200730.15812-2-adobriyan@gmail.com> (raw)
In-Reply-To: <20180305200730.15812-1-adobriyan@gmail.com>
kmalloc_index() return index into an array of kmalloc kmem caches,
therefore should be unsigned.
Space savings with SLUB on trimmed down .config:
add/remove: 0/1 grow/shrink: 6/56 up/down: 85/-557 (-472)
Function old new delta
calculate_sizes 924 983 +59
on_freelist 589 604 +15
init_cache_random_seq 122 127 +5
ext4_mb_init 1206 1210 +4
slab_pad_check.part 270 271 +1
cpu_partial_store 112 113 +1
usersize_show 28 27 -1
...
new_slab 1871 1837 -34
slab_order 204 - -204
This patch start a series of converting SLUB (mostly) to "unsigned int".
1) Most integers in the code are in fact unsigned entities: array indexes,
lengths, buffer sizes, allocation orders. It is therefore better to use
unsigned variables
2) Some integers in the code are either "size_t" or "unsigned long"
for no reason.
size_t usually comes from people trying to maintain type correctness
and figuring out that "sizeof" operator returns size_t or memset/memcpy
takes size_t so should everything passed to it.
However the number of 4GB+ objects in the kernel is very small.
Most, if not all, dynamically allocated objects with kmalloc() or
kmem_cache_create() aren't actually big. Maintaining wide types
doesn't do anything.
64-bit ops are bigger than 32-bit on our beloved x86_64,
so try to not use 64-bit where it isn't necessary
(read: everywhere where integers are integers not pointers)
3) in case of SLAB allocators, there are additional limitations
*) page->inuse, page->objects are only 16-/15-bit,
*) cache size was always 32-bit
*) slab orders are small, order 20 is needed to go 64-bit on x86_64
(PAGE_SIZE << order)
Basically everything is 32-bit except kmalloc(1ULL<<32) which gets shortcut
through page allocator.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
include/linux/slab.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 231abc8976c5..296f33a512eb 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -308,7 +308,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
* 2 = 129 .. 192 bytes
* n = 2^(n-1)+1 .. 2^n
*/
-static __always_inline int kmalloc_index(size_t size)
+static __always_inline unsigned int kmalloc_index(size_t size)
{
if (!size)
return 0;
@@ -504,7 +504,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
return kmalloc_large(size, flags);
#ifndef CONFIG_SLOB
if (!(flags & GFP_DMA)) {
- int index = kmalloc_index(size);
+ unsigned int index = kmalloc_index(size);
if (!index)
return ZERO_SIZE_PTR;
@@ -542,7 +542,7 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
#ifndef CONFIG_SLOB
if (__builtin_constant_p(size) &&
size <= KMALLOC_MAX_CACHE_SIZE && !(flags & GFP_DMA)) {
- int i = kmalloc_index(size);
+ unsigned int i = kmalloc_index(size);
if (!i)
return ZERO_SIZE_PTR;
--
2.16.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2018-03-05 20:07 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 20:07 [PATCH 01/25] slab: fixup calculate_alignment() argument type Alexey Dobriyan
2018-03-05 20:07 ` Alexey Dobriyan [this message]
2018-03-06 18:24 ` [PATCH 02/25] slab: make kmalloc_index() return "unsigned int" Christopher Lameter
2018-03-05 20:07 ` [PATCH 03/25] slab: make kmalloc_size() " Alexey Dobriyan
2018-03-06 18:24 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 04/25] slab: make create_kmalloc_cache() work with 32-bit sizes Alexey Dobriyan
2018-03-06 18:32 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 05/25] slab: make create_boot_cache() " Alexey Dobriyan
2018-03-06 18:34 ` Christopher Lameter
2018-03-06 19:14 ` Matthew Wilcox
2018-03-05 20:07 ` [PATCH 06/25] slab: make kmem_cache_create() " Alexey Dobriyan
2018-03-06 18:37 ` Christopher Lameter
2018-04-05 21:48 ` Andrew Morton
2018-04-06 8:40 ` Alexey Dobriyan
2018-04-07 15:13 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 07/25] slab: make size_index[] array u8 Alexey Dobriyan
2018-03-06 18:38 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 08/25] slab: make size_index_elem() unsigned int Alexey Dobriyan
2018-03-06 18:39 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 09/25] slub: make ->remote_node_defrag_ratio " Alexey Dobriyan
2018-03-06 18:41 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 10/25] slub: make ->max_attr_size " Alexey Dobriyan
2018-03-06 18:42 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 11/25] slub: make ->red_left_pad " Alexey Dobriyan
2018-03-06 18:42 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 12/25] slub: make ->reserved " Alexey Dobriyan
2018-03-06 18:43 ` Christopher Lameter
2018-03-09 15:51 ` Alexey Dobriyan
2018-03-06 18:45 ` Matthew Wilcox
2018-03-09 22:42 ` Alexey Dobriyan
2018-03-05 20:07 ` [PATCH 13/25] slub: make ->align " Alexey Dobriyan
2018-03-06 18:43 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 14/25] slub: make ->inuse " Alexey Dobriyan
2018-03-06 18:44 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 15/25] slub: make ->cpu_partial " Alexey Dobriyan
2018-03-06 18:44 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 16/25] slub: make ->offset " Alexey Dobriyan
2018-03-06 18:45 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 17/25] slub: make ->object_size " Alexey Dobriyan
2018-03-06 18:45 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 18/25] slub: make ->size " Alexey Dobriyan
2018-03-06 18:46 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 19/25] slab: make kmem_cache_flags accept 32-bit object size Alexey Dobriyan
2018-03-06 18:47 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 20/25] kasan: make kasan_cache_create() work with 32-bit slab cache sizes Alexey Dobriyan
2018-03-05 20:07 ` [PATCH 21/25] slab: make usercopy region 32-bit Alexey Dobriyan
2018-03-05 20:07 ` [PATCH 22/25] slub: make slab_index() return unsigned int Alexey Dobriyan
2018-03-06 18:48 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 23/25] slub: make struct kmem_cache_order_objects::x " Alexey Dobriyan
2018-03-06 18:51 ` Christopher Lameter
2018-04-05 21:51 ` Andrew Morton
2018-04-06 18:02 ` Alexey Dobriyan
2018-04-07 15:18 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 24/25] slub: make size_from_object() return " Alexey Dobriyan
2018-03-06 18:52 ` Christopher Lameter
2018-03-05 20:07 ` [PATCH 25/25] slab: use 32-bit arithmetic in freelist_randomize() Alexey Dobriyan
2018-03-06 18:52 ` Christopher Lameter
2018-03-06 18:21 ` [PATCH 01/25] slab: fixup calculate_alignment() argument type Christopher Lameter
2018-04-10 20:25 ` Matthew Wilcox
2018-04-10 20:47 ` Alexey Dobriyan
2018-04-10 21:02 ` Matthew Wilcox
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=20180305200730.15812-2-adobriyan@gmail.com \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.