Skip to content

Commit

Permalink
proc: move /proc/slab_allocators boilerplate to mm/slab.c
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
  • Loading branch information
Alexey Dobriyan committed Oct 23, 2008
1 parent d6917e1 commit a0ec95a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
30 changes: 0 additions & 30 deletions fs/proc/proc_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,6 @@ static const struct file_operations proc_slabinfo_operations = {
.llseek = seq_lseek,
.release = seq_release,
};

#ifdef CONFIG_DEBUG_SLAB_LEAK
extern const struct seq_operations slabstats_op;
static int slabstats_open(struct inode *inode, struct file *file)
{
unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
int ret = -ENOMEM;
if (n) {
ret = seq_open(file, &slabstats_op);
if (!ret) {
struct seq_file *m = file->private_data;
*n = PAGE_SIZE / (2 * sizeof(unsigned long));
m->private = n;
n = NULL;
}
kfree(n);
}
return ret;
}

static const struct file_operations proc_slabstats_operations = {
.open = slabstats_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#endif
#endif

#ifdef CONFIG_MMU
Expand Down Expand Up @@ -338,9 +311,6 @@ void __init proc_misc_init(void)
/* And now for trickier ones */
#ifdef CONFIG_SLABINFO
proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
#ifdef CONFIG_DEBUG_SLAB_LEAK
proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
#endif
#endif
#ifdef CONFIG_MMU
proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations);
Expand Down
36 changes: 35 additions & 1 deletion mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#include <linux/init.h>
#include <linux/compiler.h>
#include <linux/cpuset.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/notifier.h>
#include <linux/kallsyms.h>
Expand Down Expand Up @@ -4443,13 +4444,46 @@ static int leaks_show(struct seq_file *m, void *p)
return 0;
}

const struct seq_operations slabstats_op = {
static const struct seq_operations slabstats_op = {
.start = leaks_start,
.next = s_next,
.stop = s_stop,
.show = leaks_show,
};

static int slabstats_open(struct inode *inode, struct file *file)
{
unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
int ret = -ENOMEM;
if (n) {
ret = seq_open(file, &slabstats_op);
if (!ret) {
struct seq_file *m = file->private_data;
*n = PAGE_SIZE / (2 * sizeof(unsigned long));
m->private = n;
n = NULL;
}
kfree(n);
}
return ret;
}

static const struct file_operations proc_slabstats_operations = {
.open = slabstats_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#endif

static int __init slab_proc_init(void)
{
#ifdef CONFIG_DEBUG_SLAB_LEAK
proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
#endif
return 0;
}
module_init(slab_proc_init);
#endif

/**
Expand Down

0 comments on commit a0ec95a

Please sign in to comment.