Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
mm: vmscan: Add a debug file for shrinkers
Browse files Browse the repository at this point in the history
This patch adds a debugfs file called "shrinker" when read this calls
all the shrinkers in the system with nr_to_scan set to zero and prints
the result.  These results are the number of objects the shrinkers have
available and can thus be used an indication of the total memory
that would be availble to the system if a shrink occurred.

Change-Id: Ied0ee7caff3d2fc1cb4bb839aaafee81b5b0b143
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
  • Loading branch information
Rebecca Schultz Zavin committed Oct 5, 2012
1 parent 7115079 commit 29b8a34
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions mm/vmscan.c
Expand Up @@ -42,6 +42,7 @@
#include <linux/sysctl.h>
#include <linux/oom.h>
#include <linux/prefetch.h>
#include <linux/debugfs.h>

#include <asm/tlbflush.h>
#include <asm/div64.h>
Expand Down Expand Up @@ -201,6 +202,39 @@ static unsigned long zone_nr_lru_pages(struct mem_cgroup_zone *mz,
return zone_page_state(mz->zone, NR_LRU_BASE + lru);
}

struct dentry *debug_file;

static int debug_shrinker_show(struct seq_file *s, void *unused)
{
struct shrinker *shrinker;
struct shrink_control sc;

sc.gfp_mask = -1;
sc.nr_to_scan = 0;

down_read(&shrinker_rwsem);
list_for_each_entry(shrinker, &shrinker_list, list) {
char name[64];
int num_objs;

num_objs = shrinker->shrink(shrinker, &sc);
seq_printf(s, "%pf %d\n", shrinker->shrink, num_objs);
}
up_read(&shrinker_rwsem);
return 0;
}

static int debug_shrinker_open(struct inode *inode, struct file *file)
{
return single_open(file, debug_shrinker_show, inode->i_private);
}

static const struct file_operations debug_shrinker_fops = {
.open = debug_shrinker_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

/*
* Add a shrinker callback to be called from the vm
Expand All @@ -214,6 +248,15 @@ void register_shrinker(struct shrinker *shrinker)
}
EXPORT_SYMBOL(register_shrinker);

static int __init add_shrinker_debug(void)
{
debugfs_create_file("shrinker", 0644, NULL, NULL,
&debug_shrinker_fops);
return 0;
}

late_initcall(add_shrinker_debug);

/*
* Remove one
*/
Expand Down

0 comments on commit 29b8a34

Please sign in to comment.