Skip to content

Commit 4fd0b46

Browse files
Alexey Dobriyantorvalds
authored andcommitted
slab, slub, slob: convert slab_flags_t to 32-bit
struct kmem_cache::flags is "unsigned long" which is unnecessary on 64-bit as no flags are defined in the higher bits. Switch the field to 32-bit and save some space on x86_64 until such flags appear: add/remove: 0/0 grow/shrink: 0/107 up/down: 0/-657 (-657) function old new delta sysfs_slab_add 720 719 -1 ... check_object 699 676 -23 [[email protected]: fix printk warning] Link: http://lkml.kernel.org/r/20171021100635.GA8287@avx2 Signed-off-by: Alexey Dobriyan <[email protected]> Acked-by: Pekka Enberg <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d50112e commit 4fd0b46

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

include/linux/slab.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
* The ones marked DEBUG are only valid if CONFIG_DEBUG_SLAB is set.
2323
*/
2424
/* DEBUG: Perform (expensive) checks on alloc/free */
25-
#define SLAB_CONSISTENCY_CHECKS ((slab_flags_t __force)0x00000100UL)
25+
#define SLAB_CONSISTENCY_CHECKS ((slab_flags_t __force)0x00000100U)
2626
/* DEBUG: Red zone objs in a cache */
27-
#define SLAB_RED_ZONE ((slab_flags_t __force)0x00000400UL)
27+
#define SLAB_RED_ZONE ((slab_flags_t __force)0x00000400U)
2828
/* DEBUG: Poison objects */
29-
#define SLAB_POISON ((slab_flags_t __force)0x00000800UL)
29+
#define SLAB_POISON ((slab_flags_t __force)0x00000800U)
3030
/* Align objs on cache lines */
31-
#define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000UL)
31+
#define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000U)
3232
/* Use GFP_DMA memory */
33-
#define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000UL)
33+
#define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000U)
3434
/* DEBUG: Store the last owner for bug hunting */
35-
#define SLAB_STORE_USER ((slab_flags_t __force)0x00010000UL)
35+
#define SLAB_STORE_USER ((slab_flags_t __force)0x00010000U)
3636
/* Panic if kmem_cache_create() fails */
37-
#define SLAB_PANIC ((slab_flags_t __force)0x00040000UL)
37+
#define SLAB_PANIC ((slab_flags_t __force)0x00040000U)
3838
/*
3939
* SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS!
4040
*
@@ -73,50 +73,50 @@
7373
* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
7474
*/
7575
/* Defer freeing slabs to RCU */
76-
#define SLAB_TYPESAFE_BY_RCU ((slab_flags_t __force)0x00080000UL)
76+
#define SLAB_TYPESAFE_BY_RCU ((slab_flags_t __force)0x00080000U)
7777
/* Spread some memory over cpuset */
78-
#define SLAB_MEM_SPREAD ((slab_flags_t __force)0x00100000UL)
78+
#define SLAB_MEM_SPREAD ((slab_flags_t __force)0x00100000U)
7979
/* Trace allocations and frees */
80-
#define SLAB_TRACE ((slab_flags_t __force)0x00200000UL)
80+
#define SLAB_TRACE ((slab_flags_t __force)0x00200000U)
8181

8282
/* Flag to prevent checks on free */
8383
#ifdef CONFIG_DEBUG_OBJECTS
84-
# define SLAB_DEBUG_OBJECTS ((slab_flags_t __force)0x00400000UL)
84+
# define SLAB_DEBUG_OBJECTS ((slab_flags_t __force)0x00400000U)
8585
#else
86-
# define SLAB_DEBUG_OBJECTS ((slab_flags_t __force)0x00000000UL)
86+
# define SLAB_DEBUG_OBJECTS 0
8787
#endif
8888

8989
/* Avoid kmemleak tracing */
90-
#define SLAB_NOLEAKTRACE ((slab_flags_t __force)0x00800000UL)
90+
#define SLAB_NOLEAKTRACE ((slab_flags_t __force)0x00800000U)
9191

9292
/* Don't track use of uninitialized memory */
9393
#ifdef CONFIG_KMEMCHECK
94-
# define SLAB_NOTRACK ((slab_flags_t __force)0x01000000UL)
94+
# define SLAB_NOTRACK ((slab_flags_t __force)0x01000000U)
9595
#else
96-
# define SLAB_NOTRACK ((slab_flags_t __force)0x00000000UL)
96+
# define SLAB_NOTRACK 0
9797
#endif
9898
/* Fault injection mark */
9999
#ifdef CONFIG_FAILSLAB
100-
# define SLAB_FAILSLAB ((slab_flags_t __force)0x02000000UL)
100+
# define SLAB_FAILSLAB ((slab_flags_t __force)0x02000000U)
101101
#else
102-
# define SLAB_FAILSLAB ((slab_flags_t __force)0x00000000UL)
102+
# define SLAB_FAILSLAB 0
103103
#endif
104104
/* Account to memcg */
105105
#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
106-
# define SLAB_ACCOUNT ((slab_flags_t __force)0x04000000UL)
106+
# define SLAB_ACCOUNT ((slab_flags_t __force)0x04000000U)
107107
#else
108-
# define SLAB_ACCOUNT ((slab_flags_t __force)0x00000000UL)
108+
# define SLAB_ACCOUNT 0
109109
#endif
110110

111111
#ifdef CONFIG_KASAN
112-
#define SLAB_KASAN ((slab_flags_t __force)0x08000000UL)
112+
#define SLAB_KASAN ((slab_flags_t __force)0x08000000U)
113113
#else
114-
#define SLAB_KASAN ((slab_flags_t __force)0x00000000UL)
114+
#define SLAB_KASAN 0
115115
#endif
116116

117117
/* The following flags affect the page allocator grouping pages by mobility */
118118
/* Objects are reclaimable */
119-
#define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000UL)
119+
#define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000U)
120120
#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
121121
/*
122122
* ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.

include/linux/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ typedef u32 dma_addr_t;
156156
#endif
157157

158158
typedef unsigned __bitwise gfp_t;
159-
typedef unsigned long __bitwise slab_flags_t;
159+
typedef unsigned __bitwise slab_flags_t;
160160
typedef unsigned __bitwise fmode_t;
161161

162162
#ifdef CONFIG_PHYS_ADDR_T_64BIT

mm/slab.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
252252
MAKE_LIST((cachep), (&(ptr)->slabs_free), slabs_free, nodeid); \
253253
} while (0)
254254

255-
#define CFLGS_OBJFREELIST_SLAB ((slab_flags_t __force)0x40000000UL)
256-
#define CFLGS_OFF_SLAB ((slab_flags_t __force)0x80000000UL)
255+
#define CFLGS_OBJFREELIST_SLAB ((slab_flags_t __force)0x40000000U)
256+
#define CFLGS_OFF_SLAB ((slab_flags_t __force)0x80000000U)
257257
#define OBJFREELIST_SLAB(x) ((x)->flags & CFLGS_OBJFREELIST_SLAB)
258258
#define OFF_SLAB(x) ((x)->flags & CFLGS_OFF_SLAB)
259259

mm/slub.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s)
194194

195195
/* Internal SLUB flags */
196196
/* Poison object */
197-
#define __OBJECT_POISON ((slab_flags_t __force)0x80000000UL)
197+
#define __OBJECT_POISON ((slab_flags_t __force)0x80000000U)
198198
/* Use cmpxchg_double */
199-
#define __CMPXCHG_DOUBLE ((slab_flags_t __force)0x40000000UL)
199+
#define __CMPXCHG_DOUBLE ((slab_flags_t __force)0x40000000U)
200200

201201
/*
202202
* Tracking user of a slab.
@@ -3657,7 +3657,7 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
36573657
if (flags & SLAB_PANIC)
36583658
panic("Cannot create slab %s size=%lu realsize=%u order=%u offset=%u flags=%lx\n",
36593659
s->name, (unsigned long)s->size, s->size,
3660-
oo_order(s->oo), s->offset, flags);
3660+
oo_order(s->oo), s->offset, (unsigned long)flags);
36613661
return -EINVAL;
36623662
}
36633663

0 commit comments

Comments
 (0)