Skip to content

Commit 9c01e9a

Browse files
committed
mm/slub: Define struct slab fields for CONFIG_SLUB_CPU_PARTIAL only when enabled
The fields 'next' and 'slabs' are only used when CONFIG_SLUB_CPU_PARTIAL is enabled. We can put their definition to #ifdef to prevent accidental use when disabled. Currenlty show_slab_objects() and slabs_cpu_partial_show() contain code accessing the slabs field that's effectively dead with CONFIG_SLUB_CPU_PARTIAL=n through the wrappers slub_percpu_partial() and slub_percpu_partial_read_once(), but to prevent a compile error, we need to hide all this code behind #ifdef. Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Tested-by: Hyeonggon Yoo <[email protected]>
1 parent 662188c commit 9c01e9a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mm/slab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ struct slab {
2525
union {
2626
struct list_head slab_list;
2727
struct rcu_head rcu_head;
28+
#ifdef CONFIG_SLUB_CPU_PARTIAL
2829
struct {
2930
struct slab *next;
3031
int slabs; /* Nr of slabs left */
3132
};
33+
#endif
3234
};
3335
struct kmem_cache *slab_cache;
3436
/* Double-word boundary */

mm/slub.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5258,6 +5258,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
52585258
total += x;
52595259
nodes[node] += x;
52605260

5261+
#ifdef CONFIG_SLUB_CPU_PARTIAL
52615262
slab = slub_percpu_partial_read_once(c);
52625263
if (slab) {
52635264
node = slab_nid(slab);
@@ -5270,6 +5271,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
52705271
total += x;
52715272
nodes[node] += x;
52725273
}
5274+
#endif
52735275
}
52745276
}
52755277

@@ -5469,9 +5471,10 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
54695471
{
54705472
int objects = 0;
54715473
int slabs = 0;
5472-
int cpu;
5474+
int cpu __maybe_unused;
54735475
int len = 0;
54745476

5477+
#ifdef CONFIG_SLUB_CPU_PARTIAL
54755478
for_each_online_cpu(cpu) {
54765479
struct slab *slab;
54775480

@@ -5480,12 +5483,13 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
54805483
if (slab)
54815484
slabs += slab->slabs;
54825485
}
5486+
#endif
54835487

54845488
/* Approximate half-full slabs, see slub_set_cpu_partial() */
54855489
objects = (slabs * oo_objects(s->oo)) / 2;
54865490
len += sysfs_emit_at(buf, len, "%d(%d)", objects, slabs);
54875491

5488-
#ifdef CONFIG_SMP
5492+
#if defined(CONFIG_SLUB_CPU_PARTIAL) && defined(CONFIG_SMP)
54895493
for_each_online_cpu(cpu) {
54905494
struct slab *slab;
54915495

0 commit comments

Comments
 (0)