Skip to content

Commit a304f83

Browse files
committed
Merge branch 'slab/procfs' into slab/for-linus
2 parents 2959440 + 0d7561c commit a304f83

File tree

4 files changed

+166
-158
lines changed

4 files changed

+166
-158
lines changed

mm/slab.c

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

42784278
#ifdef CONFIG_SLABINFO
4279-
4280-
static void print_slabinfo_header(struct seq_file *m)
4279+
void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
42814280
{
4282-
/*
4283-
* Output format version, so at least we can change it
4284-
* without _too_ many complaints.
4285-
*/
4286-
#if STATS
4287-
seq_puts(m, "slabinfo - version: 2.1 (statistics)\n");
4288-
#else
4289-
seq_puts(m, "slabinfo - version: 2.1\n");
4290-
#endif
4291-
seq_puts(m, "# name <active_objs> <num_objs> <objsize> "
4292-
"<objperslab> <pagesperslab>");
4293-
seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
4294-
seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
4295-
#if STATS
4296-
seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
4297-
"<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
4298-
seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
4299-
#endif
4300-
seq_putc(m, '\n');
4301-
}
4302-
4303-
static void *s_start(struct seq_file *m, loff_t *pos)
4304-
{
4305-
loff_t n = *pos;
4306-
4307-
mutex_lock(&slab_mutex);
4308-
if (!n)
4309-
print_slabinfo_header(m);
4310-
4311-
return seq_list_start(&slab_caches, *pos);
4312-
}
4313-
4314-
static void *s_next(struct seq_file *m, void *p, loff_t *pos)
4315-
{
4316-
return seq_list_next(p, &slab_caches, pos);
4317-
}
4318-
4319-
static void s_stop(struct seq_file *m, void *p)
4320-
{
4321-
mutex_unlock(&slab_mutex);
4322-
}
4323-
4324-
static int s_show(struct seq_file *m, void *p)
4325-
{
4326-
struct kmem_cache *cachep = list_entry(p, struct kmem_cache, list);
43274281
struct slab *slabp;
43284282
unsigned long active_objs;
43294283
unsigned long num_objs;
@@ -4378,13 +4332,20 @@ static int s_show(struct seq_file *m, void *p)
43784332
if (error)
43794333
printk(KERN_ERR "slab: cache %s error: %s\n", name, error);
43804334

4381-
seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
4382-
name, active_objs, num_objs, cachep->size,
4383-
cachep->num, (1 << cachep->gfporder));
4384-
seq_printf(m, " : tunables %4u %4u %4u",
4385-
cachep->limit, cachep->batchcount, cachep->shared);
4386-
seq_printf(m, " : slabdata %6lu %6lu %6lu",
4387-
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+
{
43884349
#if STATS
43894350
{ /* list3 stats */
43904351
unsigned long high = cachep->high_mark;
@@ -4414,31 +4375,8 @@ static int s_show(struct seq_file *m, void *p)
44144375
allochit, allocmiss, freehit, freemiss);
44154376
}
44164377
#endif
4417-
seq_putc(m, '\n');
4418-
return 0;
44194378
}
44204379

4421-
/*
4422-
* slabinfo_op - iterator that generates /proc/slabinfo
4423-
*
4424-
* Output layout:
4425-
* cache-name
4426-
* num-active-objs
4427-
* total-objs
4428-
* object size
4429-
* num-active-slabs
4430-
* total-slabs
4431-
* num-pages-per-slab
4432-
* + further values on SMP and with statistics enabled
4433-
*/
4434-
4435-
static const struct seq_operations slabinfo_op = {
4436-
.start = s_start,
4437-
.next = s_next,
4438-
.stop = s_stop,
4439-
.show = s_show,
4440-
};
4441-
44424380
#define MAX_SLABINFO_WRITE 128
44434381
/**
44444382
* slabinfo_write - Tuning for the slab allocator
@@ -4447,7 +4385,7 @@ static const struct seq_operations slabinfo_op = {
44474385
* @count: data length
44484386
* @ppos: unused
44494387
*/
4450-
static ssize_t slabinfo_write(struct file *file, const char __user *buffer,
4388+
ssize_t slabinfo_write(struct file *file, const char __user *buffer,
44514389
size_t count, loff_t *ppos)
44524390
{
44534391
char kbuf[MAX_SLABINFO_WRITE + 1], *tmp;
@@ -4490,19 +4428,6 @@ static ssize_t slabinfo_write(struct file *file, const char __user *buffer,
44904428
return res;
44914429
}
44924430

4493-
static int slabinfo_open(struct inode *inode, struct file *file)
4494-
{
4495-
return seq_open(file, &slabinfo_op);
4496-
}
4497-
4498-
static const struct file_operations proc_slabinfo_operations = {
4499-
.open = slabinfo_open,
4500-
.read = seq_read,
4501-
.write = slabinfo_write,
4502-
.llseek = seq_lseek,
4503-
.release = seq_release,
4504-
};
4505-
45064431
#ifdef CONFIG_DEBUG_SLAB_LEAK
45074432

45084433
static void *leaks_start(struct seq_file *m, loff_t *pos)
@@ -4631,6 +4556,16 @@ static int leaks_show(struct seq_file *m, void *p)
46314556
return 0;
46324557
}
46334558

4559+
static void *s_next(struct seq_file *m, void *p, loff_t *pos)
4560+
{
4561+
return seq_list_next(p, &slab_caches, pos);
4562+
}
4563+
4564+
static void s_stop(struct seq_file *m, void *p)
4565+
{
4566+
mutex_unlock(&slab_mutex);
4567+
}
4568+
46344569
static const struct seq_operations slabstats_op = {
46354570
.start = leaks_start,
46364571
.next = s_next,
@@ -4665,7 +4600,6 @@ static const struct file_operations proc_slabstats_operations = {
46654600

46664601
static int __init slab_proc_init(void)
46674602
{
4668-
proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
46694603
#ifdef CONFIG_DEBUG_SLAB_LEAK
46704604
proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
46714605
#endif

mm/slab.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,24 @@ static inline struct kmem_cache *__kmem_cache_alias(const char *name, size_t siz
4747

4848
int __kmem_cache_shutdown(struct kmem_cache *);
4949

50+
struct seq_file;
51+
struct file;
52+
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);
68+
ssize_t slabinfo_write(struct file *file, const char __user *buffer,
69+
size_t count, loff_t *ppos);
5070
#endif

mm/slab_common.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/module.h>
1414
#include <linux/cpu.h>
1515
#include <linux/uaccess.h>
16+
#include <linux/seq_file.h>
17+
#include <linux/proc_fs.h>
1618
#include <asm/cacheflush.h>
1719
#include <asm/tlbflush.h>
1820
#include <asm/page.h>
@@ -192,3 +194,110 @@ int slab_is_available(void)
192194
{
193195
return slab_state >= UP;
194196
}
197+
198+
#ifdef CONFIG_SLABINFO
199+
static void print_slabinfo_header(struct seq_file *m)
200+
{
201+
/*
202+
* Output format version, so at least we can change it
203+
* without _too_ many complaints.
204+
*/
205+
#ifdef CONFIG_DEBUG_SLAB
206+
seq_puts(m, "slabinfo - version: 2.1 (statistics)\n");
207+
#else
208+
seq_puts(m, "slabinfo - version: 2.1\n");
209+
#endif
210+
seq_puts(m, "# name <active_objs> <num_objs> <objsize> "
211+
"<objperslab> <pagesperslab>");
212+
seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
213+
seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
214+
#ifdef CONFIG_DEBUG_SLAB
215+
seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
216+
"<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
217+
seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
218+
#endif
219+
seq_putc(m, '\n');
220+
}
221+
222+
static void *s_start(struct seq_file *m, loff_t *pos)
223+
{
224+
loff_t n = *pos;
225+
226+
mutex_lock(&slab_mutex);
227+
if (!n)
228+
print_slabinfo_header(m);
229+
230+
return seq_list_start(&slab_caches, *pos);
231+
}
232+
233+
static void *s_next(struct seq_file *m, void *p, loff_t *pos)
234+
{
235+
return seq_list_next(p, &slab_caches, pos);
236+
}
237+
238+
static void s_stop(struct seq_file *m, void *p)
239+
{
240+
mutex_unlock(&slab_mutex);
241+
}
242+
243+
static int s_show(struct seq_file *m, void *p)
244+
{
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;
262+
}
263+
264+
/*
265+
* slabinfo_op - iterator that generates /proc/slabinfo
266+
*
267+
* Output layout:
268+
* cache-name
269+
* num-active-objs
270+
* total-objs
271+
* object size
272+
* num-active-slabs
273+
* total-slabs
274+
* num-pages-per-slab
275+
* + further values on SMP and with statistics enabled
276+
*/
277+
static const struct seq_operations slabinfo_op = {
278+
.start = s_start,
279+
.next = s_next,
280+
.stop = s_stop,
281+
.show = s_show,
282+
};
283+
284+
static int slabinfo_open(struct inode *inode, struct file *file)
285+
{
286+
return seq_open(file, &slabinfo_op);
287+
}
288+
289+
static const struct file_operations proc_slabinfo_operations = {
290+
.open = slabinfo_open,
291+
.read = seq_read,
292+
.write = slabinfo_write,
293+
.llseek = seq_lseek,
294+
.release = seq_release,
295+
};
296+
297+
static int __init slab_proc_init(void)
298+
{
299+
proc_create("slabinfo", S_IRUSR, NULL, &proc_slabinfo_operations);
300+
return 0;
301+
}
302+
module_init(slab_proc_init);
303+
#endif /* CONFIG_SLABINFO */

0 commit comments

Comments
 (0)