Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=57ed3eda977a215f054102b460ab0eb5d8d112e6
Commit:     57ed3eda977a215f054102b460ab0eb5d8d112e6
Parent:     476c6c11a9ee4610ff0e4941e3851729f7caf062
Author:     Pekka J Enberg <[EMAIL PROTECTED]>
AuthorDate: Tue Jan 1 17:23:28 2008 +0100
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Tue Jan 1 11:32:02 2008 -0800

    slub: provide /proc/slabinfo
    
    This adds a read-only /proc/slabinfo file on SLUB, that makes slabtop work.
    
    [ [EMAIL PROTECTED]: build fix. ]
    
    Cc: Andi Kleen <[EMAIL PROTECTED]>
    Cc: Christoph Lameter <[EMAIL PROTECTED]>
    Cc: Peter Zijlstra <[EMAIL PROTECTED]>
    Signed-off-by: Pekka Enberg <[EMAIL PROTECTED]>
    Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 include/linux/slub_def.h |    2 +
 mm/slub.c                |  105 ++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 94 insertions(+), 13 deletions(-)

diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index 40801e7..b7d9408 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -200,4 +200,6 @@ static __always_inline void *kmalloc_node(size_t size, 
gfp_t flags, int node)
 }
 #endif
 
+extern const struct seq_operations slabinfo_op;
+
 #endif /* _LINUX_SLUB_DEF_H */
diff --git a/mm/slub.c b/mm/slub.c
index 3655ad3..903dabd 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3076,6 +3076,19 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t 
gfpflags,
        return slab_alloc(s, gfpflags, node, caller);
 }
 
+static unsigned long count_partial(struct kmem_cache_node *n)
+{
+       unsigned long flags;
+       unsigned long x = 0;
+       struct page *page;
+
+       spin_lock_irqsave(&n->list_lock, flags);
+       list_for_each_entry(page, &n->partial, lru)
+               x += page->inuse;
+       spin_unlock_irqrestore(&n->list_lock, flags);
+       return x;
+}
+
 #if defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG)
 static int validate_slab(struct kmem_cache *s, struct page *page,
                                                unsigned long *map)
@@ -3458,19 +3471,6 @@ static int list_locations(struct kmem_cache *s, char 
*buf,
        return n;
 }
 
-static unsigned long count_partial(struct kmem_cache_node *n)
-{
-       unsigned long flags;
-       unsigned long x = 0;
-       struct page *page;
-
-       spin_lock_irqsave(&n->list_lock, flags);
-       list_for_each_entry(page, &n->partial, lru)
-               x += page->inuse;
-       spin_unlock_irqrestore(&n->list_lock, flags);
-       return x;
-}
-
 enum slab_stat_type {
        SL_FULL,
        SL_PARTIAL,
@@ -4123,3 +4123,82 @@ static int __init slab_sysfs_init(void)
 
 __initcall(slab_sysfs_init);
 #endif
+
+/*
+ * The /proc/slabinfo ABI
+ */
+#ifdef CONFIG_PROC_FS
+
+static void print_slabinfo_header(struct seq_file *m)
+{
+       seq_puts(m, "slabinfo - version: 2.1\n");
+       seq_puts(m, "# name            <active_objs> <num_objs> <objsize> "
+                "<objperslab> <pagesperslab>");
+       seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
+       seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
+       seq_putc(m, '\n');
+}
+
+static void *s_start(struct seq_file *m, loff_t *pos)
+{
+       loff_t n = *pos;
+
+       down_read(&slub_lock);
+       if (!n)
+               print_slabinfo_header(m);
+
+       return seq_list_start(&slab_caches, *pos);
+}
+
+static void *s_next(struct seq_file *m, void *p, loff_t *pos)
+{
+       return seq_list_next(p, &slab_caches, pos);
+}
+
+static void s_stop(struct seq_file *m, void *p)
+{
+       up_read(&slub_lock);
+}
+
+static int s_show(struct seq_file *m, void *p)
+{
+       unsigned long nr_partials = 0;
+       unsigned long nr_slabs = 0;
+       unsigned long nr_inuse = 0;
+       unsigned long nr_objs;
+       struct kmem_cache *s;
+       int node;
+
+       s = list_entry(p, struct kmem_cache, list);
+
+       for_each_online_node(node) {
+               struct kmem_cache_node *n = get_node(s, node);
+
+               if (!n)
+                       continue;
+
+               nr_partials += n->nr_partial;
+               nr_slabs += atomic_long_read(&n->nr_slabs);
+               nr_inuse += count_partial(n);
+       }
+
+       nr_objs = nr_slabs * s->objects;
+       nr_inuse += (nr_slabs - nr_partials) * s->objects;
+
+       seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d", s->name, nr_inuse,
+                  nr_objs, s->size, s->objects, (1 << s->order));
+       seq_printf(m, " : tunables %4u %4u %4u", 0, 0, 0);
+       seq_printf(m, " : slabdata %6lu %6lu %6lu", nr_slabs, nr_slabs,
+                  0UL);
+       seq_putc(m, '\n');
+       return 0;
+}
+
+const struct seq_operations slabinfo_op = {
+       .start = s_start,
+       .next = s_next,
+       .stop = s_stop,
+       .show = s_show,
+};
+
+#endif /* CONFIG_PROC_FS */
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to