X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=mm%2Fbacking-dev.c;h=f2e574dbc30089d778880d2ad178d5dd48174034;hb=b4416d2bea007f07f2e74cdc4cb64042ec996c83;hp=4967fb176e532c07bca7979becea7fa25b2b8f6e;hpb=189d3c4a94ef19fca2a71a6a336e9fda900e25e7;p=linux-2.6-omap-h63xx.git diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 4967fb176e5..f2e574dbc30 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -10,6 +10,80 @@ static struct class *bdi_class; +#ifdef CONFIG_DEBUG_FS +#include +#include + +static struct dentry *bdi_debug_root; + +static void bdi_debug_init(void) +{ + bdi_debug_root = debugfs_create_dir("bdi", NULL); +} + +static int bdi_debug_stats_show(struct seq_file *m, void *v) +{ + struct backing_dev_info *bdi = m->private; + long background_thresh; + long dirty_thresh; + long bdi_thresh; + + get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi); + +#define K(x) ((x) << (PAGE_SHIFT - 10)) + seq_printf(m, + "BdiWriteback: %8lu kB\n" + "BdiReclaimable: %8lu kB\n" + "BdiDirtyThresh: %8lu kB\n" + "DirtyThresh: %8lu kB\n" + "BackgroundThresh: %8lu kB\n", + (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)), + (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)), + K(bdi_thresh), + K(dirty_thresh), + K(background_thresh)); +#undef K + + return 0; +} + +static int bdi_debug_stats_open(struct inode *inode, struct file *file) +{ + return single_open(file, bdi_debug_stats_show, inode->i_private); +} + +static const struct file_operations bdi_debug_stats_fops = { + .open = bdi_debug_stats_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void bdi_debug_register(struct backing_dev_info *bdi, const char *name) +{ + bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root); + bdi->debug_stats = debugfs_create_file("stats", 0444, bdi->debug_dir, + bdi, &bdi_debug_stats_fops); +} + +static void bdi_debug_unregister(struct backing_dev_info *bdi) +{ + debugfs_remove(bdi->debug_stats); + debugfs_remove(bdi->debug_dir); +} +#else +static inline void bdi_debug_init(void) +{ +} +static inline void bdi_debug_register(struct backing_dev_info *bdi, + const char *name) +{ +} +static inline void bdi_debug_unregister(struct backing_dev_info *bdi) +{ +} +#endif + static ssize_t read_ahead_kb_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -40,22 +114,25 @@ static ssize_t name##_show(struct device *dev, \ BDI_SHOW(read_ahead_kb, K(bdi->ra_pages)) -BDI_SHOW(reclaimable_kb, K(bdi_stat(bdi, BDI_RECLAIMABLE))) -BDI_SHOW(writeback_kb, K(bdi_stat(bdi, BDI_WRITEBACK))) - -static inline unsigned long get_dirty(struct backing_dev_info *bdi, int i) +static ssize_t min_ratio_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { - unsigned long thresh[3]; - - get_dirty_limits(&thresh[0], &thresh[1], &thresh[2], bdi); + struct backing_dev_info *bdi = dev_get_drvdata(dev); + char *end; + unsigned int ratio; + ssize_t ret = -EINVAL; - return thresh[i]; + ratio = simple_strtoul(buf, &end, 10); + if (*buf && (end[0] == '\0' || (end[0] == '\n' && end[1] == '\0'))) { + ret = bdi_set_min_ratio(bdi, ratio); + if (!ret) + ret = count; + } + return ret; } +BDI_SHOW(min_ratio, bdi->min_ratio) -BDI_SHOW(dirty_kb, K(get_dirty(bdi, 1))) -BDI_SHOW(bdi_dirty_kb, K(get_dirty(bdi, 2))) - -static ssize_t min_ratio_store(struct device *dev, +static ssize_t max_ratio_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct backing_dev_info *bdi = dev_get_drvdata(dev); @@ -65,23 +142,20 @@ static ssize_t min_ratio_store(struct device *dev, ratio = simple_strtoul(buf, &end, 10); if (*buf && (end[0] == '\0' || (end[0] == '\n' && end[1] == '\0'))) { - ret = bdi_set_min_ratio(bdi, ratio); + ret = bdi_set_max_ratio(bdi, ratio); if (!ret) ret = count; } return ret; } -BDI_SHOW(min_ratio, bdi->min_ratio) +BDI_SHOW(max_ratio, bdi->max_ratio) #define __ATTR_RW(attr) __ATTR(attr, 0644, attr##_show, attr##_store) static struct device_attribute bdi_dev_attrs[] = { __ATTR_RW(read_ahead_kb), - __ATTR_RO(reclaimable_kb), - __ATTR_RO(writeback_kb), - __ATTR_RO(dirty_kb), - __ATTR_RO(bdi_dirty_kb), __ATTR_RW(min_ratio), + __ATTR_RW(max_ratio), __ATTR_NULL, }; @@ -89,37 +163,31 @@ static __init int bdi_class_init(void) { bdi_class = class_create(THIS_MODULE, "bdi"); bdi_class->dev_attrs = bdi_dev_attrs; + bdi_debug_init(); return 0; } -core_initcall(bdi_class_init); +postcore_initcall(bdi_class_init); int bdi_register(struct backing_dev_info *bdi, struct device *parent, const char *fmt, ...) { - char *name; va_list args; int ret = 0; struct device *dev; va_start(args, fmt); - name = kvasprintf(GFP_KERNEL, fmt, args); + dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args); va_end(args); - - if (!name) - return -ENOMEM; - - dev = device_create(bdi_class, parent, MKDEV(0, 0), name); if (IS_ERR(dev)) { ret = PTR_ERR(dev); goto exit; } bdi->dev = dev; - dev_set_drvdata(bdi->dev, bdi); + bdi_debug_register(bdi, dev_name(dev)); exit: - kfree(name); return ret; } EXPORT_SYMBOL(bdi_register); @@ -133,6 +201,7 @@ EXPORT_SYMBOL(bdi_register_dev); void bdi_unregister(struct backing_dev_info *bdi) { if (bdi->dev) { + bdi_debug_unregister(bdi); device_unregister(bdi->dev); bdi->dev = NULL; } @@ -147,6 +216,8 @@ int bdi_init(struct backing_dev_info *bdi) bdi->dev = NULL; bdi->min_ratio = 0; + bdi->max_ratio = 100; + bdi->max_prop_frac = PROP_FRAC_BASE; for (i = 0; i < NR_BDI_STAT_ITEMS; i++) { err = percpu_counter_init_irq(&bdi->bdi_stat[i], 0);