Skip to contentSkip to conversation

slab: make kmalloc_index() return "unsigned int"

PATCH In review Alexey Dobriyan 5 participants 31 messages Nov 23, 2017 – Nov 28, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/23 slab: make kmalloc_index() return "unsigned int"

kmalloc_index() return index into an array of kmalloc kmem caches, therefore should unsigned.

Space savings:

add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6 (-6)
Function old new delta
rtsx_scsi_handler 9116 9114 -2
vnic_rq_alloc 424 420 -4

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 that
memset/memcpy takes size_t so should everything you pass 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.

---
 include/linux/slab.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/slab.h +3 -3
index 50697a1d6621..e765800d7c9b 100644
@@ -295,7 +295,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;
@@ -491,7 +491,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;
@@ -529,7 +529,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;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 2/23 slab: make kmalloc_size() return "unsigned int"

kmalloc_size() derives size of kmalloc cache from internal index, which of course can't be negative.

Propagate unsignedness a bit.

Space savings:

add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-2 (-2)
Function old new delta
new_kmalloc_cache 42 41 -1
create_kmalloc_caches 238 237 -1

---
 include/linux/slab.h | 4 ++--
 mm/slab_common.c     | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/slab.h +2 -2
index e765800d7c9b..f3e4aca74406 100644
@@ -509,11 +509,11 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
  * return size or 0 if a kmalloc cache for that
  * size does not exist
  */
-static __always_inline int kmalloc_size(int n)
+static __always_inline unsigned int kmalloc_size(unsigned int n)
 {
 #ifndef CONFIG_SLOB
 	if (n > 2)
-		return 1 << n;
+		return 1U << n;
 
 	if (n == 1 && KMALLOC_MIN_SIZE <= 32)
 		return 96;
mm/slab_common.c +4 -4
index c8cb36774ba1..8ba0ffb31279 100644
@@ -1057,7 +1057,7 @@ void __init setup_kmalloc_cache_index_table(void)
 	}
 }
 
-static void __init new_kmalloc_cache(int idx, slab_flags_t flags)
+static void __init new_kmalloc_cache(unsigned int idx, slab_flags_t flags)
 {
 	kmalloc_caches[idx] = create_kmalloc_cache(kmalloc_info[idx].name,
 					kmalloc_info[idx].size, flags);
@@ -1070,7 +1070,7 @@ static void __init new_kmalloc_cache(int idx, slab_flags_t flags)
  */
 void __init create_kmalloc_caches(slab_flags_t flags)
 {
-	int i;
+	unsigned int i;
 
 	for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
 		if (!kmalloc_caches[i])
@@ -1095,9 +1095,9 @@ void __init create_kmalloc_caches(slab_flags_t flags)
 		struct kmem_cache *s = kmalloc_caches[i];
 
 		if (s) {
-			int size = kmalloc_size(i);
+			unsigned int size = kmalloc_size(i);
 			char *n = kasprintf(GFP_NOWAIT,
-				 "dma-kmalloc-%d", size);
+				 "dma-kmalloc-%u", size);
 
 			BUG_ON(!n);
 			kmalloc_dma_caches[i] = create_kmalloc_cache(n,
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH 3/23 slab: create_kmalloc_cache() works with 32-bit sizes

In reply to Alexey Dobriyan

KMALLOC_MAX_CACHE_SIZE is 32-bit so is the largest kmalloc cache size.

---
 mm/slab.h        | 4 ++--
 mm/slab_common.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
mm/slab.h +2 -2
index ad657ffa44e5..08f43ed41b75 100644
@@ -75,7 +75,7 @@ extern struct kmem_cache *kmem_cache;
 /* A table of kmalloc cache names and sizes */
 extern const struct kmalloc_info_struct {
 	const char *name;
-	unsigned long size;
+	unsigned int size;
 } kmalloc_info[];
 
 unsigned long calculate_alignment(slab_flags_t flags,
@@ -94,7 +94,7 @@ struct kmem_cache *kmalloc_slab(size_t, gfp_t);
 /* Functions provided by the slab allocators */
 int __kmem_cache_create(struct kmem_cache *, slab_flags_t flags);
 
-extern struct kmem_cache *create_kmalloc_cache(const char *name, size_t size,
+struct kmem_cache *create_kmalloc_cache(const char *name, unsigned int size,
 			slab_flags_t flags);
 extern void create_boot_cache(struct kmem_cache *, const char *name,
 			size_t size, slab_flags_t flags);
mm/slab_common.c +1 -1
index 8ba0ffb31279..fa27e0492f89 100644
@@ -898,7 +898,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
 	s->refcount = -1;	/* Exempt from merging for now */
 }
 
-struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
+struct kmem_cache *__init create_kmalloc_cache(const char *name, unsigned int size,
 				slab_flags_t flags)
 {
 	struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

PATCH 4/23 slab: create_boot_cache() only works with 32-bit sizes

In reply to Alexey Dobriyan

struct kmem_cache::size has always been "int" so all those "size_t size" are fake.

---
 mm/slab.h        | 2 +-
 mm/slab_common.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
mm/slab.h +1 -1
index 08f43ed41b75..6bbb7b5d1706 100644
@@ -97,7 +97,7 @@ int __kmem_cache_create(struct kmem_cache *, slab_flags_t flags);
 struct kmem_cache *create_kmalloc_cache(const char *name, unsigned int size,
 			slab_flags_t flags);
 extern void create_boot_cache(struct kmem_cache *, const char *name,
-			size_t size, slab_flags_t flags);
+			unsigned int size, slab_flags_t flags);
 
 int slab_unmergeable(struct kmem_cache *s);
 struct kmem_cache *find_mergeable(size_t size, size_t align,
mm/slab_common.c +2 -2
index fa27e0492f89..9c8c55e1e0e3 100644
@@ -878,7 +878,7 @@ bool slab_is_available(void)
 
 #ifndef CONFIG_SLOB
 /* Create a cache during boot when no slab services are available yet */
-void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t size,
+void __init create_boot_cache(struct kmem_cache *s, const char *name, unsigned int size,
 		slab_flags_t flags)
 {
 	int err;
@@ -892,7 +892,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
 	err = __kmem_cache_create(s, flags);
 
 	if (err)
-		panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
+		panic("Creation of kmalloc slab %s size=%u failed. Reason %d\n",
 					name, size, err);
 
 	s->refcount = -1;	/* Exempt from merging for now */
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

PATCH 5/23 slab: kmem_cache_create() only works with 32-bit sizes

In reply to Alexey Dobriyan

struct kmem_cache::size and ::align were always 32-bit.

Out of curiosity I created 4GB kmem_cache, it oopsed with division by 0. kmem_cache_create(1UL<<32+1) created 1-byte cache as expected.

size_t doesn't work and never did.

Space savings (all cases where cache size is not known at compile time):

add/remove: 0/0 grow/shrink: 3/21 up/down: 7/-61 (-54)
Function old new delta
ext4_groupinfo_create_slab 193 197 +4
find_mergeable 281 283 +2
kmem_cache_create 638 639 +1
tipc_server_start 771 770 -1
skd_construct 2616 2615 -1
ovs_flow_init 122 121 -1
init_cifs 1271 1270 -1
fork_init 284 283 -1
ecryptfs_init 405 404 -1
dm_bufio_client_create 1009 1008 -1
kvm_init 692 690 -2
elv_register 398 396 -2
calculate_alignment 60 58 -2
verity_fec_ctr 875 872 -3
sg_pool_init 192 189 -3
init_bio 203 200 -3
early_amd_iommu_init 2492 2489 -3
__kmem_cache_alias 164 161 -3
jbd2_journal_load 842 838 -4
ccid_kmem_cache_create 106 102 -4
setup_conf 5027 5022 -5
resize_stripes 1607 1602 -5
copy_pid_ns 825 819 -6
create_boot_cache 169 160 -9

---
 include/linux/slab.h |  2 +-
 mm/slab.c            |  2 +-
 mm/slab.h            | 10 +++++-----
 mm/slab_common.c     | 16 ++++++++--------
 mm/slub.c            |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)
include/linux/slab.h +1 -1
index f3e4aca74406..00a2b48d9bae 100644
@@ -135,7 +135,7 @@ struct mem_cgroup;
 void __init kmem_cache_init(void);
 bool slab_is_available(void);
 
-struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
+struct kmem_cache *kmem_cache_create(const char *, unsigned int, unsigned int,
 			slab_flags_t,
 			void (*)(void *));
 void kmem_cache_destroy(struct kmem_cache *);
mm/slab.c +1 -1
index 183e996dde5f..78fd096362da 100644
@@ -1882,7 +1882,7 @@ slab_flags_t kmem_cache_flags(unsigned long object_size,
 }
 
 struct kmem_cache *
-__kmem_cache_alias(const char *name, size_t size, size_t align,
+__kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		   slab_flags_t flags, void (*ctor)(void *))
 {
 	struct kmem_cache *cachep;
mm/slab.h +5 -5
index 6bbb7b5d1706..facaf949f727 100644
@@ -78,8 +78,8 @@ extern const struct kmalloc_info_struct {
 	unsigned int size;
 } kmalloc_info[];
 
-unsigned long calculate_alignment(slab_flags_t flags,
-		unsigned long align, unsigned long size);
+unsigned int calculate_alignment(slab_flags_t flags,
+		unsigned int align, unsigned int size);
 
 #ifndef CONFIG_SLOB
 /* Kmalloc array related functions */
@@ -100,11 +100,11 @@ extern void create_boot_cache(struct kmem_cache *, const char *name,
 			unsigned int size, slab_flags_t flags);
 
 int slab_unmergeable(struct kmem_cache *s);
-struct kmem_cache *find_mergeable(size_t size, size_t align,
+struct kmem_cache *find_mergeable(unsigned int size, unsigned int align,
 		slab_flags_t flags, const char *name, void (*ctor)(void *));
 #ifndef CONFIG_SLOB
 struct kmem_cache *
-__kmem_cache_alias(const char *name, size_t size, size_t align,
+__kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		   slab_flags_t flags, void (*ctor)(void *));
 
 slab_flags_t kmem_cache_flags(unsigned long object_size,
@@ -112,7 +112,7 @@ slab_flags_t kmem_cache_flags(unsigned long object_size,
 	void (*ctor)(void *));
 #else
 static inline struct kmem_cache *
-__kmem_cache_alias(const char *name, size_t size, size_t align,
+__kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		   slab_flags_t flags, void (*ctor)(void *))
 { return NULL; }
 
mm/slab_common.c +8 -8
index 9c8c55e1e0e3..1d46602c881e 100644
@@ -73,7 +73,7 @@ unsigned int kmem_cache_size(struct kmem_cache *s)
 EXPORT_SYMBOL(kmem_cache_size);
 
 #ifdef CONFIG_DEBUG_VM
-static int kmem_cache_sanity_check(const char *name, size_t size)
+static int kmem_cache_sanity_check(const char *name, unsigned int size)
 {
 	struct kmem_cache *s = NULL;
 
@@ -104,7 +104,7 @@ static int kmem_cache_sanity_check(const char *name, size_t size)
 	return 0;
 }
 #else
-static inline int kmem_cache_sanity_check(const char *name, size_t size)
+static inline int kmem_cache_sanity_check(const char *name, unsigned int size)
 {
 	return 0;
 }
@@ -290,7 +290,7 @@ int slab_unmergeable(struct kmem_cache *s)
 	return 0;
 }
 
-struct kmem_cache *find_mergeable(size_t size, size_t align,
+struct kmem_cache *find_mergeable(unsigned int size, unsigned int align,
 		slab_flags_t flags, const char *name, void (*ctor)(void *))
 {
 	struct kmem_cache *s;
@@ -341,8 +341,8 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
  * Figure out what the alignment of the objects will be given a set of
  * flags, a user specified alignment and the size of the objects.
  */
-unsigned long calculate_alignment(slab_flags_t flags,
-		unsigned long align, unsigned long size)
+unsigned int calculate_alignment(slab_flags_t flags,
+		unsigned int align, unsigned int size)
 {
 	/*
 	 * If the user wants hardware cache aligned objects then follow that
@@ -352,7 +352,7 @@ unsigned long calculate_alignment(slab_flags_t flags,
 	 * alignment though. If that is greater then use it.
 	 */
 	if (flags & SLAB_HWCACHE_ALIGN) {
-		unsigned long ralign = cache_line_size();
+		unsigned int ralign = cache_line_size();
 		while (size <= ralign / 2)
 			ralign /= 2;
 		align = max(align, ralign);
@@ -365,7 +365,7 @@ unsigned long calculate_alignment(slab_flags_t flags,
 }
 
 static struct kmem_cache *create_cache(const char *name,
-		size_t object_size, size_t size, size_t align,
+		unsigned int object_size, unsigned int size, unsigned int align,
 		slab_flags_t flags, void (*ctor)(void *),
 		struct mem_cgroup *memcg, struct kmem_cache *root_cache)
 {
@@ -430,7 +430,7 @@ static struct kmem_cache *create_cache(const char *name,
  * as davem.
  */
 struct kmem_cache *
-kmem_cache_create(const char *name, size_t size, size_t align,
+kmem_cache_create(const char *name, unsigned int size, unsigned int align,
 		  slab_flags_t flags, void (*ctor)(void *))
 {
 	struct kmem_cache *s = NULL;
mm/slub.c +1 -1
index cfd56e5a35fb..e653c4b51403 100644
@@ -4223,7 +4223,7 @@ void __init kmem_cache_init_late(void)
 }
 
 struct kmem_cache *
-__kmem_cache_alias(const char *name, size_t size, size_t align,
+__kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		   slab_flags_t flags, void (*ctor)(void *))
 {
 	struct kmem_cache *s, *c;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

PATCH 6/23 slab: make size_index[] array u8

In reply to Alexey Dobriyan

All those small numbers are reverse indexes into kmalloc caches array and can't be negative.

On x86_64 "unsigned int = fls()" can drop CDQE:

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2 (-2)
Function old new delta
kmalloc_slab 101 99 -2

---
 mm/slab_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/slab_common.c +2 -2
index 1d46602c881e..4405af3ee8eb 100644
@@ -927,7 +927,7 @@ EXPORT_SYMBOL(kmalloc_dma_caches);
  * of two cache sizes there. The size of larger slabs can be determined using
  * fls.
  */
-static s8 size_index[24] = {
+static u8 size_index[24] = {
 	3,	/* 8 */
 	4,	/* 16 */
 	5,	/* 24 */
@@ -965,7 +965,7 @@ static inline int size_index_elem(size_t bytes)
  */
 struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
 {
-	int index;
+	unsigned int index;
 
 	if (unlikely(size > KMALLOC_MAX_SIZE)) {
 		WARN_ON_ONCE(!(flags & __GFP_NOWARN));
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw

PATCH 7/23 slab: make size_index_elem() unsigned int

In reply to Alexey Dobriyan

size_index_elem() always work with small sizes (kmalloc cache are 32-bit) and return small indexes.

---
 mm/slab_common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/slab_common.c +3 -3
index 4405af3ee8eb..1cec6225fc4c 100644
@@ -954,7 +954,7 @@ static u8 size_index[24] = {
 	2	/* 192 */
 };
 
-static inline int size_index_elem(size_t bytes)
+static inline unsigned int size_index_elem(unsigned int bytes)
 {
 	return (bytes - 1) / 8;
 }
@@ -1023,13 +1023,13 @@ const struct kmalloc_info_struct kmalloc_info[] __initconst = {
  */
 void __init setup_kmalloc_cache_index_table(void)
 {
-	int i;
+	unsigned int i;
 
 	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
 		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
 
 	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
-		int elem = size_index_elem(i);
+		unsigned int elem = size_index_elem(i);
 
 		if (elem >= ARRAY_SIZE(size_index))
 			break;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

PATCH 8/23 slub: make ->remote_node_defrag_ratio unsigned int

In reply to Alexey Dobriyan

->remote_node_defrag_ratio is in range 0..1000.

---
 include/linux/slub_def.h |  2 +-
 mm/slub.c                | 11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/slub_def.h +1 -1
index 0adae162dc8f..571ff513ed97 100644
@@ -124,7 +124,7 @@ struct kmem_cache {
 	/*
 	 * Defragmentation by allocating from a remote node.
 	 */
-	int remote_node_defrag_ratio;
+	unsigned int remote_node_defrag_ratio;
 #endif
 
 #ifdef CONFIG_SLAB_FREELIST_RANDOM
mm/slub.c +6 -5
index e653c4b51403..45d8f0cbfb28 100644
@@ -5264,21 +5264,22 @@ SLAB_ATTR(shrink);
 #ifdef CONFIG_NUMA
 static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", s->remote_node_defrag_ratio / 10);
+	return sprintf(buf, "%u\n", s->remote_node_defrag_ratio / 10);
 }
 
 static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
 				const char *buf, size_t length)
 {
-	unsigned long ratio;
+	unsigned int ratio;
 	int err;
 
-	err = kstrtoul(buf, 10, &ratio);
+	err = kstrtouint(buf, 10, &ratio);
 	if (err)
 		return err;
+	if (ratio > 100)
+		return -ERANGE;
 
-	if (ratio <= 100)
-		s->remote_node_defrag_ratio = ratio * 10;
+	s->remote_node_defrag_ratio = ratio * 10;
 
 	return length;
 }
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw

PATCH 9/23 slub: make ->max_attr_size unsigned int

In reply to Alexey Dobriyan

->max_attr_size is maximum length of every SLAB memcg attribute ever written. VFS limits those to INT_MAX.

---
 include/linux/slub_def.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/slub_def.h +2 -1
index 571ff513ed97..5e98817e18a3 100644
@@ -110,7 +110,8 @@ struct kmem_cache {
 #endif
 #ifdef CONFIG_MEMCG
 	struct memcg_cache_params memcg_params;
-	int max_attr_size; /* for propagation, maximum size of a stored attr */
+	/* for propagation, maximum size of a stored attr */
+	unsigned int max_attr_size;
 #ifdef CONFIG_SYSFS
 	struct kset *memcg_kset;
 #endif
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw

PATCH 10/23 slub: make ->red_left_pad unsigned int

In reply to Alexey Dobriyan

Padding length can't be negative.

---
 include/linux/slub_def.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/slub_def.h +1 -1
index 5e98817e18a3..a7019a4c713d 100644
@@ -101,7 +101,7 @@ struct kmem_cache {
 	int inuse;		/* Offset to metadata */
 	int align;		/* Alignment */
 	int reserved;		/* Reserved bytes at the end of slabs */
-	int red_left_pad;	/* Left redzone padding size */
+	unsigned int red_left_pad;	/* Left redzone padding size */
 	const char *name;	/* Name (only for display!) */
 	struct list_head list;	/* List of slab caches */
 #ifdef CONFIG_SYSFS
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#13 lore raw

PATCH 11/23 slub: make ->reserved unsigned int

In reply to Alexey Dobriyan

->reserved is either 0 or sizeof(struct rcu_head), can't be negative.

---
 include/linux/slub_def.h | 2 +-
 mm/slub.c                | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/slub_def.h +1 -1
index a7019a4c713d..09ca236ce102 100644
@@ -100,7 +100,7 @@ struct kmem_cache {
 	void (*ctor)(void *);
 	int inuse;		/* Offset to metadata */
 	int align;		/* Alignment */
-	int reserved;		/* Reserved bytes at the end of slabs */
+	unsigned int reserved;	/* Reserved bytes at the end of slabs */
 	unsigned int red_left_pad;	/* Left redzone padding size */
 	const char *name;	/* Name (only for display!) */
 	struct list_head list;	/* List of slab caches */
mm/slub.c +1 -1
index 45d8f0cbfb28..2ca7463c72c2 100644
@@ -5069,7 +5069,7 @@ SLAB_ATTR_RO(destroy_by_rcu);
 
 static ssize_t reserved_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", s->reserved);
+	return sprintf(buf, "%u\n", s->reserved);
 }
 SLAB_ATTR_RO(reserved);
 
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#14 lore raw

PATCH 12/23 slub: make ->align unsigned int

In reply to Alexey Dobriyan

Kmem cache alignment can't be negative.

---
 include/linux/slub_def.h | 2 +-
 mm/slub.c                | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/slub_def.h +1 -1
index 09ca236ce102..ff2d3f513d15 100644
@@ -99,7 +99,7 @@ struct kmem_cache {
 	int refcount;		/* Refcount for slab cache destroy */
 	void (*ctor)(void *);
 	int inuse;		/* Offset to metadata */
-	int align;		/* Alignment */
+	unsigned int align;	/* Alignment */
 	unsigned int reserved;	/* Reserved bytes at the end of slabs */
 	unsigned int red_left_pad;	/* Left redzone padding size */
 	const char *name;	/* Name (only for display!) */
mm/slub.c +1 -1
index 2ca7463c72c2..ddfeb1d5c512 100644
@@ -4877,7 +4877,7 @@ SLAB_ATTR_RO(slab_size);
 
 static ssize_t align_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", s->align);
+	return sprintf(buf, "%u\n", s->align);
 }
 SLAB_ATTR_RO(align);
 
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw

PATCH 13/23 slub: make ->inuse unsigned int

In reply to Alexey Dobriyan

->inuse is "the number of bytes in actual use by the object", can't be negative.

---
 include/linux/slub_def.h | 2 +-
 mm/slub.c                | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
include/linux/slub_def.h +1 -1
index ff2d3f513d15..2383c46c88ce 100644
@@ -98,7 +98,7 @@ struct kmem_cache {
 	gfp_t allocflags;	/* gfp flags to use on each alloc */
 	int refcount;		/* Refcount for slab cache destroy */
 	void (*ctor)(void *);
-	int inuse;		/* Offset to metadata */
+	unsigned int inuse;	/* Offset to metadata */
 	unsigned int align;	/* Alignment */
 	unsigned int reserved;	/* Reserved bytes at the end of slabs */
 	unsigned int red_left_pad;	/* Left redzone padding size */
mm/slub.c +2 -3
index ddfeb1d5c512..f5b86d86be9a 100644
@@ -4237,12 +4237,11 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		 * the complete object on kzalloc.
 		 */
 		s->object_size = max(s->object_size, (int)size);
-		s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
+		s->inuse = max(s->inuse, ALIGN(size, sizeof(void *)));
 
 		for_each_memcg_cache(c, s) {
 			c->object_size = s->object_size;
-			c->inuse = max_t(int, c->inuse,
-					 ALIGN(size, sizeof(void *)));
+			c->inuse = max(c->inuse, ALIGN(size, sizeof(void *)));
 		}
 
 		if (sysfs_slab_alias(s, name)) {
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw

PATCH 14/23 slub: make ->cpu_partial unsigned int

In reply to Alexey Dobriyan

->cpu_partial is at least 0, can't be negative.

---
 include/linux/slub_def.h | 3 ++-
 mm/slub.c                | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)
include/linux/slub_def.h +2 -1
index 2383c46c88ce..d8b40e53e8f6 100644
@@ -88,7 +88,8 @@ struct kmem_cache {
 	int object_size;	/* The size of an object without meta data */
 	int offset;		/* Free pointer offset. */
 #ifdef CONFIG_SLUB_CPU_PARTIAL
-	int cpu_partial;	/* Number of per cpu partial objects to keep around */
+	/* Number of per cpu partial objects to keep around */
+	unsigned int cpu_partial;
 #endif
 	struct kmem_cache_order_objects oo;
 
mm/slub.c +3 -3
index f5b86d86be9a..61218ecc0ea7 100644
@@ -1809,7 +1809,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
 {
 	struct page *page, *page2;
 	void *object = NULL;
-	int available = 0;
+	unsigned int available = 0;
 	int objects;
 
 	/*
@@ -4943,10 +4943,10 @@ static ssize_t cpu_partial_show(struct kmem_cache *s, char *buf)
 static ssize_t cpu_partial_store(struct kmem_cache *s, const char *buf,
 				 size_t length)
 {
-	unsigned long objects;
+	unsigned int objects;
 	int err;
 
-	err = kstrtoul(buf, 10, &objects);
+	err = kstrtouint(buf, 10, &objects);
 	if (err)
 		return err;
 	if (objects && !kmem_cache_has_cpu_partial(s))
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

PATCH 15/23 slub: make ->offset unsigned int

In reply to Alexey Dobriyan

->offset is free pointer offset from the start of the object, can't be negative.

---
 include/linux/slub_def.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/slub_def.h +1 -1
index d8b40e53e8f6..94f1228f2f41 100644
@@ -86,7 +86,7 @@ struct kmem_cache {
 	unsigned long min_partial;
 	int size;		/* The size of an object including meta data */
 	int object_size;	/* The size of an object without meta data */
-	int offset;		/* Free pointer offset. */
+	unsigned int offset;	/* Free pointer offset. */
 #ifdef CONFIG_SLUB_CPU_PARTIAL
 	/* Number of per cpu partial objects to keep around */
 	unsigned int cpu_partial;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw

PATCH 16/23 slub: make ->object_size unsigned int

In reply to Alexey Dobriyan

Linux doesn't support negative length objects in kmem caches.

---
 include/linux/slub_def.h | 2 +-
 mm/slab_common.c         | 2 +-
 mm/slub.c                | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
include/linux/slub_def.h +1 -1
index 94f1228f2f41..b9d1f0ef1335 100644
@@ -85,7 +85,7 @@ struct kmem_cache {
 	slab_flags_t flags;
 	unsigned long min_partial;
 	int size;		/* The size of an object including meta data */
-	int object_size;	/* The size of an object without meta data */
+	unsigned int object_size;/* The size of an object without meta data */
 	unsigned int offset;	/* Free pointer offset. */
 #ifdef CONFIG_SLUB_CPU_PARTIAL
 	/* Number of per cpu partial objects to keep around */
mm/slab_common.c +1 -1
index 1cec6225fc4c..2b5435e1e619 100644
@@ -94,7 +94,7 @@ static int kmem_cache_sanity_check(const char *name, unsigned int size)
 		 */
 		res = probe_kernel_address(s->name, tmp);
 		if (res) {
-			pr_err("Slab cache with size %d has lost its name\n",
+			pr_err("Slab cache with size %u has lost its name\n",
 			       s->object_size);
 			continue;
 		}
mm/slub.c +4 -4
index 61218ecc0ea7..4e09dabb89da 100644
@@ -680,7 +680,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
 		print_section(KERN_ERR, "Bytes b4 ", p - 16, 16);
 
 	print_section(KERN_ERR, "Object ", p,
-		      min_t(unsigned long, s->object_size, PAGE_SIZE));
+		      min_t(unsigned int, s->object_size, PAGE_SIZE));
 	if (s->flags & SLAB_RED_ZONE)
 		print_section(KERN_ERR, "Redzone ", p + s->object_size,
 			s->inuse - s->object_size);
@@ -2398,7 +2398,7 @@ slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
 
 	pr_warn("SLUB: Unable to allocate memory on node %d, gfp=%#x(%pGg)\n",
 		nid, gfpflags, &gfpflags);
-	pr_warn("  cache: %s, object size: %d, buffer size: %d, default order: %d, min order: %d\n",
+	pr_warn("  cache: %s, object size: %u, buffer size: %d, default order: %d, min order: %d\n",
 		s->name, s->object_size, s->size, oo_order(s->oo),
 		oo_order(s->min));
 
@@ -4236,7 +4236,7 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		 * Adjust the object sizes so that we clear
 		 * the complete object on kzalloc.
 		 */
-		s->object_size = max(s->object_size, (int)size);
+		s->object_size = max(s->object_size, size);
 		s->inuse = max(s->inuse, ALIGN(size, sizeof(void *)));
 
 		for_each_memcg_cache(c, s) {
@@ -4882,7 +4882,7 @@ SLAB_ATTR_RO(align);
 
 static ssize_t object_size_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", s->object_size);
+	return sprintf(buf, "%u\n", s->object_size);
 }
 SLAB_ATTR_RO(object_size);
 
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#19 lore raw

PATCH 17/23 slub: make ->size unsigned int

In reply to Alexey Dobriyan

Linux doesn't support negative length objects in kmem caches (including metadata).

---
 include/linux/slub_def.h |  2 +-
 mm/slub.c                | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
include/linux/slub_def.h +1 -1
index b9d1f0ef1335..e768ac49f0b4 100644
@@ -84,7 +84,7 @@ struct kmem_cache {
 	/* Used for retriving partial slabs etc */
 	slab_flags_t flags;
 	unsigned long min_partial;
-	int size;		/* The size of an object including meta data */
+	unsigned int size;	/* The size of an object including meta data */
 	unsigned int object_size;/* The size of an object without meta data */
 	unsigned int offset;	/* Free pointer offset. */
 #ifdef CONFIG_SLUB_CPU_PARTIAL
mm/slub.c +6 -6
index 4e09dabb89da..042421584ef8 100644
@@ -2398,7 +2398,7 @@ slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
 
 	pr_warn("SLUB: Unable to allocate memory on node %d, gfp=%#x(%pGg)\n",
 		nid, gfpflags, &gfpflags);
-	pr_warn("  cache: %s, object size: %u, buffer size: %d, default order: %d, min order: %d\n",
+	pr_warn("  cache: %s, object size: %u, buffer size: %u, default order: %d, min order: %d\n",
 		s->name, s->object_size, s->size, oo_order(s->oo),
 		oo_order(s->min));
 
@@ -3632,8 +3632,8 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
 	free_kmem_cache_nodes(s);
 error:
 	if (flags & SLAB_PANIC)
-		panic("Cannot create slab %s size=%lu realsize=%u order=%u offset=%u flags=%lx\n",
-		      s->name, (unsigned long)s->size, s->size,
+		panic("Cannot create slab %s size=%u realsize=%u order=%u offset=%u flags=%lx\n",
+		      s->name, s->size, s->size,
 		      oo_order(s->oo), s->offset, (unsigned long)flags);
 	return -EINVAL;
 }
@@ -3822,7 +3822,7 @@ const char *__check_heap_object(const void *ptr, unsigned long n,
 				struct page *page)
 {
 	struct kmem_cache *s;
-	unsigned long offset;
+	unsigned int offset;
 	size_t object_size;
 
 	/* Find object and usable object size. */
@@ -4870,7 +4870,7 @@ struct slab_attribute {
 
 static ssize_t slab_size_show(struct kmem_cache *s, char *buf)
 {
-	return sprintf(buf, "%d\n", s->size);
+	return sprintf(buf, "%u\n", s->size);
 }
 SLAB_ATTR_RO(slab_size);
 
@@ -5638,7 +5638,7 @@ static char *create_unique_id(struct kmem_cache *s)
 		*p++ = 'A';
 	if (p != name + 1)
 		*p++ = '-';
-	p += sprintf(p, "%07d", s->size);
+	p += sprintf(p, "%07u", s->size);
 
 	BUG_ON(p > name + ID_STR_LENGTH - 1);
 	return name;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw

PATCH 18/23 slab: make kmem_cache_flags accept 32-bit object size

In reply to Alexey Dobriyan

Now that all sizes are properly typed, propagate "unsigned int" down the callgraph.

---
 mm/slab.c | 2 +-
 mm/slab.h | 4 ++--
 mm/slub.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
mm/slab.c +1 -1
index 78fd096362da..15da0e177d7b 100644
@@ -1874,7 +1874,7 @@ static int __ref setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp)
 	return 0;
 }
 
-slab_flags_t kmem_cache_flags(unsigned long object_size,
+slab_flags_t kmem_cache_flags(unsigned int object_size,
 	slab_flags_t flags, const char *name,
 	void (*ctor)(void *))
 {
mm/slab.h +2 -2
index facaf949f727..2993ba92c89e 100644
@@ -107,7 +107,7 @@ struct kmem_cache *
 __kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		   slab_flags_t flags, void (*ctor)(void *));
 
-slab_flags_t kmem_cache_flags(unsigned long object_size,
+slab_flags_t kmem_cache_flags(unsigned int object_size,
 	slab_flags_t flags, const char *name,
 	void (*ctor)(void *));
 #else
@@ -116,7 +116,7 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
 		   slab_flags_t flags, void (*ctor)(void *))
 { return NULL; }
 
-static inline slab_flags_t kmem_cache_flags(unsigned long object_size,
+static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
 	slab_flags_t flags, const char *name,
 	void (*ctor)(void *))
 {
mm/slub.c +2 -2
index 042421584ef8..cd09ae2c48e8 100644
@@ -1290,7 +1290,7 @@ static int __init setup_slub_debug(char *str)
 
 __setup("slub_debug", setup_slub_debug);
 
-slab_flags_t kmem_cache_flags(unsigned long object_size,
+slab_flags_t kmem_cache_flags(unsigned int object_size,
 	slab_flags_t flags, const char *name,
 	void (*ctor)(void *))
 {
@@ -1323,7 +1323,7 @@ static inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n,
 					struct page *page) {}
 static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,
 					struct page *page) {}
-slab_flags_t kmem_cache_flags(unsigned long object_size,
+slab_flags_t kmem_cache_flags(unsigned int object_size,
 	slab_flags_t flags, const char *name,
 	void (*ctor)(void *))
 {
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#21 lore raw

PATCH 19/23 kasan: make kasan_cache_create() work with 32-bit slab caches

In reply to Alexey Dobriyan

If SLAB doesn't support 4GB+ kmem caches (it never did), KASAN should not do it as well.

---
 include/linux/kasan.h | 4 ++--
 mm/kasan/kasan.c      | 4 ++--
 mm/slab.c             | 2 +-
 mm/slub.c             | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
include/linux/kasan.h +2 -2
index e3eb834c9a35..d0a05e0f9e8e 100644
@@ -45,7 +45,7 @@ void kasan_unpoison_stack_above_sp_to(const void *watermark);
 void kasan_alloc_pages(struct page *page, unsigned int order);
 void kasan_free_pages(struct page *page, unsigned int order);
 
-void kasan_cache_create(struct kmem_cache *cache, size_t *size,
+void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
 			slab_flags_t *flags);
 void kasan_cache_shrink(struct kmem_cache *cache);
 void kasan_cache_shutdown(struct kmem_cache *cache);
@@ -94,7 +94,7 @@ static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
 static inline void kasan_free_pages(struct page *page, unsigned int order) {}
 
 static inline void kasan_cache_create(struct kmem_cache *cache,
-				      size_t *size,
+				      unsigned int *size,
 				      slab_flags_t *flags) {}
 static inline void kasan_cache_shrink(struct kmem_cache *cache) {}
 static inline void kasan_cache_shutdown(struct kmem_cache *cache) {}
mm/kasan/kasan.c +2 -2
index 405bba487df5..0bb95f6a1b7b 100644
@@ -336,11 +336,11 @@ static size_t optimal_redzone(size_t object_size)
 	return rz;
 }
 
-void kasan_cache_create(struct kmem_cache *cache, size_t *size,
+void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
 			slab_flags_t *flags)
 {
+	unsigned int orig_size = *size;
 	int redzone_adjust;
-	int orig_size = *size;
 
 	/* Add alloc meta. */
 	cache->kasan_info.alloc_meta_offset = *size;
mm/slab.c +1 -1
index 15da0e177d7b..328b9b705981 100644
@@ -1999,7 +1999,7 @@ int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags)
 	size_t ralign = BYTES_PER_WORD;
 	gfp_t gfp;
 	int err;
-	size_t size = cachep->size;
+	unsigned int size = cachep->size;
 
 #if DEBUG
 #if FORCED_DEBUG
mm/slub.c +1 -1
index cd09ae2c48e8..ce71665e266c 100644
@@ -3457,7 +3457,7 @@ static void set_cpu_partial(struct kmem_cache *s)
 static int calculate_sizes(struct kmem_cache *s, int forced_order)
 {
 	slab_flags_t flags = s->flags;
-	size_t size = s->object_size;
+	unsigned int size = s->object_size;
 	int order;
 
 	/*
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#23 lore raw

PATCH 20/23 slub: make slab_index() return unsigned int

In reply to Alexey Dobriyan

slab_index() returns index of an object within a slab which is at most u15 (or u16?).

Iterators additionally guarantee that "p >= addr".

---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
index ce71665e266c..04c8348b8ce9 100644
@@ -311,7 +311,7 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
 		__p += (__s)->size, __idx++)
 
 /* Determine object index from a given position */
-static inline int slab_index(void *p, struct kmem_cache *s, void *addr)
+static inline unsigned int slab_index(void *p, struct kmem_cache *s, void *addr)
 {
 	return (p - addr) / s->size;
 }
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#24 lore raw

PATCH 21/23 slub: make struct kmem_cache_order_objects::x unsigned int

In reply to Alexey Dobriyan

struct kmem_cache_order_objects is for mixing order and number of objects, and orders aren't bit enough to warrant 64-bit width.

Propagate unsignedness down so that everything fits.

!!! Patch assumes that "PAGE_SIZE << order" doesn't overflow. !!!

Space savings on x86_64:

add/remove: 1/0 grow/shrink: 1/14 up/down: 26/-163 (-137)
Function old new delta
__bit_spin_unlock.constprop - 21 +21
init_cache_random_seq 123 128 +5
kmem_cache_open 1189 1188 -1
on_freelist 585 582 -3
get_slabinfo 155 152 -3
check_slab 180 177 -3
order_show 29 25 -4
boot_kmem_cache_node 8864 8856 -8
boot_kmem_cache 8864 8856 -8
slab_out_of_memory 260 250 -10
__cmpxchg_double_slab.isra 380 368 -12
calculate_sizes 625 612 -13
order_store 103 88 -15
slab_order 202 177 -25
new_slab 1830 1805 -25
cmpxchg_double_slab.isra 569 536 -33

---
 include/linux/slub_def.h |  2 +-
 mm/slub.c                | 74 +++++++++++++++++++++++++-----------------------
 2 files changed, 40 insertions(+), 36 deletions(-)
include/linux/slub_def.h +1 -1
index e768ac49f0b4..b9daf0f88b4f 100644
@@ -73,7 +73,7 @@ struct kmem_cache_cpu {
  * given order would contain.
  */
 struct kmem_cache_order_objects {
-	unsigned long x;
+	unsigned int x;
 };
 
 /*
mm/slub.c +39 -35

206 lines not on this page · raw message

Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#27 lore raw

PATCH 22/23 slub: make size_from_object() return unsigned int

In reply to Alexey Dobriyan

Function returns size of the object without red zone, so can't be negative.

---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
index 27e619a38a02..5badbac9d650 100644
@@ -466,7 +466,7 @@ static void get_map(struct kmem_cache *s, struct page *page, unsigned long *map)
 		set_bit(slab_index(p, s, addr), map);
 }
 
-static inline int size_from_object(struct kmem_cache *s)
+static inline unsigned int size_from_object(struct kmem_cache *s)
 {
 	if (s->flags & SLAB_RED_ZONE)
 		return s->size - s->red_left_pad;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#28 lore raw

PATCH 23/23 slab: use 32-bit arithmetic in freelist_randomize()

In reply to Alexey Dobriyan

SLAB doesn't support 4GB+ of objects per slab, so randomization doesn't need size_t.

---
 mm/slab_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/slab_common.c +2 -2
index 2b5435e1e619..012f0af5cd81 100644
@@ -1140,10 +1140,10 @@ EXPORT_SYMBOL(kmalloc_order_trace);
 #ifdef CONFIG_SLAB_FREELIST_RANDOM
 /* Randomize a generic freelist */
 static void freelist_randomize(struct rnd_state *state, unsigned int *list,
-			size_t count)
+			       unsigned int count)
 {
-	size_t i;
 	unsigned int rand;
+	unsigned int i;
 
 	for (i = 0; i < count; i++)
 		list[i] = i;
Signature · 7 lines
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Re: [PATCH 03/23] slab: create_kmalloc_cache() works with 32-bit sizes

In reply to Alexey Dobriyan

mm/slab_common.c void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz · line 902

Quoted 3 lines · Alexey Dobriyan
mm/slab_common.c +1 -1
-struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
+struct kmem_cache *__init create_kmalloc_cache(const char *name, unsigned int size,
 				slab_flags_t flags)

Could you reflow this one? Surprised checkpatch didn't whinge.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw

Re: [PATCH 21/23] slub: make struct kmem_cache_order_objects::x unsigned int

In reply to Alexey Dobriyan
Quoted 1 line · Alexey Dobriyan

!!! Patch assumes that "PAGE_SIZE << order" doesn't overflow. !!!

Check for that condition and do not allow creation of such caches?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw

Re: [PATCH 19/23] kasan: make kasan_cache_create() work with 32-bit slab caches

In reply to Alexey Dobriyan
Thank you for the patch! Perhaps something to improve:

Hi Alexey,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to mmotm/master v4.14 next-20171124]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Alexey-Dobriyan/slab-make-kmalloc_index-return-unsigned-int/20171125-035138
reproduce:

        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__

sparse warnings: (new ones prefixed by >>)

vim +361 mm/kasan/kasan.c

7ed2f9e6 Alexander Potapenko 2016-03-25  338  
5d094e12 Alexey Dobriyan     2017-11-24  339  void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
d50112ed Alexey Dobriyan     2017-11-15  340  			slab_flags_t *flags)
7ed2f9e6 Alexander Potapenko 2016-03-25  341  {
5d094e12 Alexey Dobriyan     2017-11-24  342  	unsigned int orig_size = *size;
7ed2f9e6 Alexander Potapenko 2016-03-25  343  	int redzone_adjust;
80a9201a Alexander Potapenko 2016-07-28  344  
7ed2f9e6 Alexander Potapenko 2016-03-25  345  	/* Add alloc meta. */
7ed2f9e6 Alexander Potapenko 2016-03-25  346  	cache->kasan_info.alloc_meta_offset = *size;
7ed2f9e6 Alexander Potapenko 2016-03-25  347  	*size += sizeof(struct kasan_alloc_meta);
7ed2f9e6 Alexander Potapenko 2016-03-25  348  
7ed2f9e6 Alexander Potapenko 2016-03-25  349  	/* Add free meta. */
5f0d5a3a Paul E. McKenney    2017-01-18  350  	if (cache->flags & SLAB_TYPESAFE_BY_RCU || cache->ctor ||
7ed2f9e6 Alexander Potapenko 2016-03-25  351  	    cache->object_size < sizeof(struct kasan_free_meta)) {
7ed2f9e6 Alexander Potapenko 2016-03-25  352  		cache->kasan_info.free_meta_offset = *size;
7ed2f9e6 Alexander Potapenko 2016-03-25  353  		*size += sizeof(struct kasan_free_meta);
7ed2f9e6 Alexander Potapenko 2016-03-25  354  	}
7ed2f9e6 Alexander Potapenko 2016-03-25  355  	redzone_adjust = optimal_redzone(cache->object_size) -
7ed2f9e6 Alexander Potapenko 2016-03-25  356  		(*size - cache->object_size);
80a9201a Alexander Potapenko 2016-07-28  357  
7ed2f9e6 Alexander Potapenko 2016-03-25  358  	if (redzone_adjust > 0)
7ed2f9e6 Alexander Potapenko 2016-03-25  359  		*size += redzone_adjust;
80a9201a Alexander Potapenko 2016-07-28  360  
80a9201a Alexander Potapenko 2016-07-28 @361  	*size = min(KMALLOC_MAX_SIZE, max(*size, cache->object_size +
7ed2f9e6 Alexander Potapenko 2016-03-25  362  					optimal_redzone(cache->object_size)));
80a9201a Alexander Potapenko 2016-07-28  363  
80a9201a Alexander Potapenko 2016-07-28  364  	/*
80a9201a Alexander Potapenko 2016-07-28  365  	 * If the metadata doesn't fit, don't enable KASAN at all.
80a9201a Alexander Potapenko 2016-07-28  366  	 */
80a9201a Alexander Potapenko 2016-07-28  367  	if (*size <= cache->kasan_info.alloc_meta_offset ||
80a9201a Alexander Potapenko 2016-07-28  368  			*size <= cache->kasan_info.free_meta_offset) {
80a9201a Alexander Potapenko 2016-07-28  369  		cache->kasan_info.alloc_meta_offset = 0;
80a9201a Alexander Potapenko 2016-07-28  370  		cache->kasan_info.free_meta_offset = 0;
80a9201a Alexander Potapenko 2016-07-28  371  		*size = orig_size;
80a9201a Alexander Potapenko 2016-07-28  372  		return;
80a9201a Alexander Potapenko 2016-07-28  373  	}
80a9201a Alexander Potapenko 2016-07-28  374  
80a9201a Alexander Potapenko 2016-07-28  375  	*flags |= SLAB_KASAN;
7ed2f9e6 Alexander Potapenko 2016-03-25  376  }
7ed2f9e6 Alexander Potapenko 2016-03-25  377  

:::::: The code at line 361 was first introduced by commit
:::::: 80a9201a5965f4715d5c09790862e0df84ce0614 mm, kasan: switch SLUB to stackdepot, enable memory quarantine for SLUB

:::::: TO: Alexander Potapenko <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#26 lore raw

Re: [PATCH 21/23] slub: make struct kmem_cache_order_objects::x unsigned int

In reply to Christopher Lameter
Quoted 5 lines · Christopher Lameter
Quoted 1 line · Alexey Dobriyan

!!! Patch assumes that "PAGE_SIZE << order" doesn't overflow. !!!

Check for that condition and do not allow creation of such caches?

It should be enforced by MAX_ORDER in slab_order() and setup_slub_max_order().

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [PATCH 03/23] slab: create_kmalloc_cache() works with 32-bit sizes

In reply to Matthew Wilcox
Quoted 8 lines · Matthew Wilcox
Quoted 5 lines · Alexey Dobriyan

-struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
+struct kmem_cache *__init create_kmalloc_cache(const char *name, unsigned int size,
slab_flags_t flags)

Could you reflow this one? Surprised checkpatch didn't whinge.

If it doesn't run, it doesn't whinge. :-)

I think that in the era of 16:9 monitors line length should be ignored altogether.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [PATCH 03/23] slab: create_kmalloc_cache() works with 32-bit sizes

Quoted 10 lines · Alexey Dobriyan
Quoted 8 lines · Matthew Wilcox
Quoted 5 lines · Alexey Dobriyan

-struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
+struct kmem_cache *__init create_kmalloc_cache(const char *name, unsigned int size,
slab_flags_t flags)

Could you reflow this one? Surprised checkpatch didn't whinge.

Quoted 4 lines

If it doesn't run, it doesn't whinge. :-)

I think that in the era of 16:9 monitors line length should be ignored altogether.

16:9 monitors let me get more 80x24 xterms on one virtual desktop. Please stick to the line lengths.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#29 lore raw
In reply to Alexey Dobriyan
Quoted 9 lines · On Fri, 24 Nov 2017 01:16:06 +0300 Alexey Dobriyan <[email protected]> wrote:

kmalloc_index() return index into an array of kmalloc kmem caches, therefore should unsigned.

Space savings:

add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6 (-6)
Function old new delta
rtsx_scsi_handler 9116 9114 -2
vnic_rq_alloc 424 420 -4

While I applaud the use of accurate and appropriate types, that's one heck of a big patch series. What do the slab maintainers think?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#30 lore raw
Quoted 7 lines · Andrew Morton
Quoted 4 lines

add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6 (-6)
Function old new delta
rtsx_scsi_handler 9116 9114 -2
vnic_rq_alloc 424 420 -4

While I applaud the use of accurate and appropriate types, that's one heck of a big patch series. What do the slab maintainers think?

Run some regression tests and make sure that we did not get some false aliasing?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>