Skip to content

Commit 0d7561c

Browse files
Glauber Costapenberg
authored andcommitted
sl[au]b: Process slabinfo_show in common code
With all the infrastructure in place, we can now have slabinfo_show done from slab_common.c. A cache-specific function is called to grab information about the cache itself, since that is still heavily dependent on the implementation. But with the values produced by it, all the printing and handling is done from common code. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Christoph Lameter <cl@linux.com> CC: David Rientjes <rientjes@google.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
1 parent bcee6e2 commit 0d7561c

File tree

4 files changed

+57
-27
lines changed

4 files changed

+57
-27
lines changed

mm/slab.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,9 +4276,8 @@ static void cache_reap(struct work_struct *w)
42764276
}
42774277

42784278
#ifdef CONFIG_SLABINFO
4279-
int slabinfo_show(struct seq_file *m, void *p)
4279+
void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
42804280
{
4281-
struct kmem_cache *cachep = list_entry(p, struct kmem_cache, list);
42824281
struct slab *slabp;
42834282
unsigned long active_objs;
42844283
unsigned long num_objs;
@@ -4333,13 +4332,20 @@ int slabinfo_show(struct seq_file *m, void *p)
43334332
if (error)
43344333
printk(KERN_ERR "slab: cache %s error: %s\n", name, error);
43354334

4336-
seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
4337-
name, active_objs, num_objs, cachep->size,
4338-
cachep->num, (1 << cachep->gfporder));
4339-
seq_printf(m, " : tunables %4u %4u %4u",
4340-
cachep->limit, cachep->batchcount, cachep->shared);
4341-
seq_printf(m, " : slabdata %6lu %6lu %6lu",
4342-
active_slabs, num_slabs, shared_avail);
4335+
sinfo->active_objs = active_objs;
4336+
sinfo->num_objs = num_objs;
4337+
sinfo->active_slabs = active_slabs;
4338+
sinfo->num_slabs = num_slabs;
4339+
sinfo->shared_avail = shared_avail;
4340+
sinfo->limit = cachep->limit;
4341+
sinfo->batchcount = cachep->batchcount;
4342+
sinfo->shared = cachep->shared;
4343+
sinfo->objects_per_slab = cachep->num;
4344+
sinfo->cache_order = cachep->gfporder;
4345+
}
4346+
4347+
void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
4348+
{
43434349
#if STATS
43444350
{ /* list3 stats */
43454351
unsigned long high = cachep->high_mark;
@@ -4369,8 +4375,6 @@ int slabinfo_show(struct seq_file *m, void *p)
43694375
allochit, allocmiss, freehit, freemiss);
43704376
}
43714377
#endif
4372-
seq_putc(m, '\n');
4373-
return 0;
43744378
}
43754379

43764380
#define MAX_SLABINFO_WRITE 128

mm/slab.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,22 @@ int __kmem_cache_shutdown(struct kmem_cache *);
4949

5050
struct seq_file;
5151
struct file;
52-
int slabinfo_show(struct seq_file *m, void *p);
5352

53+
struct slabinfo {
54+
unsigned long active_objs;
55+
unsigned long num_objs;
56+
unsigned long active_slabs;
57+
unsigned long num_slabs;
58+
unsigned long shared_avail;
59+
unsigned int limit;
60+
unsigned int batchcount;
61+
unsigned int shared;
62+
unsigned int objects_per_slab;
63+
unsigned int cache_order;
64+
};
65+
66+
void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo);
67+
void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *s);
5468
ssize_t slabinfo_write(struct file *file, const char __user *buffer,
5569
size_t count, loff_t *ppos);
5670
#endif

mm/slab_common.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,23 @@ static void s_stop(struct seq_file *m, void *p)
242242

243243
static int s_show(struct seq_file *m, void *p)
244244
{
245-
return slabinfo_show(m, p);
245+
struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
246+
struct slabinfo sinfo;
247+
248+
memset(&sinfo, 0, sizeof(sinfo));
249+
get_slabinfo(s, &sinfo);
250+
251+
seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
252+
s->name, sinfo.active_objs, sinfo.num_objs, s->size,
253+
sinfo.objects_per_slab, (1 << sinfo.cache_order));
254+
255+
seq_printf(m, " : tunables %4u %4u %4u",
256+
sinfo.limit, sinfo.batchcount, sinfo.shared);
257+
seq_printf(m, " : slabdata %6lu %6lu %6lu",
258+
sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail);
259+
slabinfo_show_stats(m, s);
260+
seq_putc(m, '\n');
261+
return 0;
246262
}
247263

248264
/*

mm/slub.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,18 +5405,14 @@ __initcall(slab_sysfs_init);
54055405
* The /proc/slabinfo ABI
54065406
*/
54075407
#ifdef CONFIG_SLABINFO
5408-
int slabinfo_show(struct seq_file *m, void *p)
5408+
void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
54095409
{
54105410
unsigned long nr_partials = 0;
54115411
unsigned long nr_slabs = 0;
5412-
unsigned long nr_inuse = 0;
54135412
unsigned long nr_objs = 0;
54145413
unsigned long nr_free = 0;
5415-
struct kmem_cache *s;
54165414
int node;
54175415

5418-
s = list_entry(p, struct kmem_cache, list);
5419-
54205416
for_each_online_node(node) {
54215417
struct kmem_cache_node *n = get_node(s, node);
54225418

@@ -5429,16 +5425,16 @@ int slabinfo_show(struct seq_file *m, void *p)
54295425
nr_free += count_partial(n, count_free);
54305426
}
54315427

5432-
nr_inuse = nr_objs - nr_free;
5428+
sinfo->active_objs = nr_objs - nr_free;
5429+
sinfo->num_objs = nr_objs;
5430+
sinfo->active_slabs = nr_slabs;
5431+
sinfo->num_slabs = nr_slabs;
5432+
sinfo->objects_per_slab = oo_objects(s->oo);
5433+
sinfo->cache_order = oo_order(s->oo);
5434+
}
54335435

5434-
seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d", s->name, nr_inuse,
5435-
nr_objs, s->size, oo_objects(s->oo),
5436-
(1 << oo_order(s->oo)));
5437-
seq_printf(m, " : tunables %4u %4u %4u", 0, 0, 0);
5438-
seq_printf(m, " : slabdata %6lu %6lu %6lu", nr_slabs, nr_slabs,
5439-
0UL);
5440-
seq_putc(m, '\n');
5441-
return 0;
5436+
void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *s)
5437+
{
54425438
}
54435439

54445440
ssize_t slabinfo_write(struct file *file, const char __user *buffer,

0 commit comments

Comments
 (0)