Commit 66f3b8e2 authored by Jens Axboe's avatar Jens Axboe

writeback: move dirty inodes from super_block to backing_dev_info

This is a first step at introducing per-bdi flusher threads. We should
have no change in behaviour, although sb_has_dirty_inodes() is now
ridiculously expensive, as there's no easy way to answer that question.
Not a huge problem, since it'll be deleted in subsequent patches.
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent d8a8559c
This diff is collapsed.
...@@ -62,9 +62,6 @@ static struct super_block *alloc_super(struct file_system_type *type) ...@@ -62,9 +62,6 @@ static struct super_block *alloc_super(struct file_system_type *type)
s = NULL; s = NULL;
goto out; goto out;
} }
INIT_LIST_HEAD(&s->s_dirty);
INIT_LIST_HEAD(&s->s_io);
INIT_LIST_HEAD(&s->s_more_io);
INIT_LIST_HEAD(&s->s_files); INIT_LIST_HEAD(&s->s_files);
INIT_LIST_HEAD(&s->s_instances); INIT_LIST_HEAD(&s->s_instances);
INIT_HLIST_HEAD(&s->s_anon); INIT_HLIST_HEAD(&s->s_anon);
......
...@@ -40,6 +40,8 @@ enum bdi_stat_item { ...@@ -40,6 +40,8 @@ enum bdi_stat_item {
#define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids))) #define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
struct backing_dev_info { struct backing_dev_info {
struct list_head bdi_list;
unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */
unsigned long state; /* Always use atomic bitops on this */ unsigned long state; /* Always use atomic bitops on this */
unsigned int capabilities; /* Device capabilities */ unsigned int capabilities; /* Device capabilities */
...@@ -58,6 +60,10 @@ struct backing_dev_info { ...@@ -58,6 +60,10 @@ struct backing_dev_info {
struct device *dev; struct device *dev;
struct list_head b_dirty; /* dirty inodes */
struct list_head b_io; /* parked for writeback */
struct list_head b_more_io; /* parked for more writeback */
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *debug_dir; struct dentry *debug_dir;
struct dentry *debug_stats; struct dentry *debug_stats;
...@@ -72,6 +78,9 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent, ...@@ -72,6 +78,9 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev); int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
void bdi_unregister(struct backing_dev_info *bdi); void bdi_unregister(struct backing_dev_info *bdi);
extern struct mutex bdi_lock;
extern struct list_head bdi_list;
static inline void __add_bdi_stat(struct backing_dev_info *bdi, static inline void __add_bdi_stat(struct backing_dev_info *bdi,
enum bdi_stat_item item, s64 amount) enum bdi_stat_item item, s64 amount)
{ {
......
...@@ -715,7 +715,7 @@ struct posix_acl; ...@@ -715,7 +715,7 @@ struct posix_acl;
struct inode { struct inode {
struct hlist_node i_hash; struct hlist_node i_hash;
struct list_head i_list; struct list_head i_list; /* backing dev IO list */
struct list_head i_sb_list; struct list_head i_sb_list;
struct list_head i_dentry; struct list_head i_dentry;
unsigned long i_ino; unsigned long i_ino;
...@@ -1336,9 +1336,6 @@ struct super_block { ...@@ -1336,9 +1336,6 @@ struct super_block {
struct xattr_handler **s_xattr; struct xattr_handler **s_xattr;
struct list_head s_inodes; /* all inodes */ struct list_head s_inodes; /* all inodes */
struct list_head s_dirty; /* dirty inodes */
struct list_head s_io; /* parked for writeback */
struct list_head s_more_io; /* parked for more writeback */
struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */
struct list_head s_files; struct list_head s_files;
/* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */ /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */
......
...@@ -22,6 +22,8 @@ struct backing_dev_info default_backing_dev_info = { ...@@ -22,6 +22,8 @@ struct backing_dev_info default_backing_dev_info = {
EXPORT_SYMBOL_GPL(default_backing_dev_info); EXPORT_SYMBOL_GPL(default_backing_dev_info);
static struct class *bdi_class; static struct class *bdi_class;
DEFINE_MUTEX(bdi_lock);
LIST_HEAD(bdi_list);
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
#include <linux/debugfs.h> #include <linux/debugfs.h>
...@@ -211,6 +213,10 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent, ...@@ -211,6 +213,10 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
goto exit; goto exit;
} }
mutex_lock(&bdi_lock);
list_add_tail(&bdi->bdi_list, &bdi_list);
mutex_unlock(&bdi_lock);
bdi->dev = dev; bdi->dev = dev;
bdi_debug_register(bdi, dev_name(dev)); bdi_debug_register(bdi, dev_name(dev));
...@@ -225,9 +231,17 @@ int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev) ...@@ -225,9 +231,17 @@ int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev)
} }
EXPORT_SYMBOL(bdi_register_dev); EXPORT_SYMBOL(bdi_register_dev);
static void bdi_remove_from_list(struct backing_dev_info *bdi)
{
mutex_lock(&bdi_lock);
list_del(&bdi->bdi_list);
mutex_unlock(&bdi_lock);
}
void bdi_unregister(struct backing_dev_info *bdi) void bdi_unregister(struct backing_dev_info *bdi)
{ {
if (bdi->dev) { if (bdi->dev) {
bdi_remove_from_list(bdi);
bdi_debug_unregister(bdi); bdi_debug_unregister(bdi);
device_unregister(bdi->dev); device_unregister(bdi->dev);
bdi->dev = NULL; bdi->dev = NULL;
...@@ -245,6 +259,10 @@ int bdi_init(struct backing_dev_info *bdi) ...@@ -245,6 +259,10 @@ int bdi_init(struct backing_dev_info *bdi)
bdi->min_ratio = 0; bdi->min_ratio = 0;
bdi->max_ratio = 100; bdi->max_ratio = 100;
bdi->max_prop_frac = PROP_FRAC_BASE; bdi->max_prop_frac = PROP_FRAC_BASE;
INIT_LIST_HEAD(&bdi->bdi_list);
INIT_LIST_HEAD(&bdi->b_io);
INIT_LIST_HEAD(&bdi->b_dirty);
INIT_LIST_HEAD(&bdi->b_more_io);
for (i = 0; i < NR_BDI_STAT_ITEMS; i++) { for (i = 0; i < NR_BDI_STAT_ITEMS; i++) {
err = percpu_counter_init(&bdi->bdi_stat[i], 0); err = percpu_counter_init(&bdi->bdi_stat[i], 0);
...@@ -259,6 +277,8 @@ int bdi_init(struct backing_dev_info *bdi) ...@@ -259,6 +277,8 @@ int bdi_init(struct backing_dev_info *bdi)
err: err:
while (i--) while (i--)
percpu_counter_destroy(&bdi->bdi_stat[i]); percpu_counter_destroy(&bdi->bdi_stat[i]);
bdi_remove_from_list(bdi);
} }
return err; return err;
...@@ -269,6 +289,10 @@ void bdi_destroy(struct backing_dev_info *bdi) ...@@ -269,6 +289,10 @@ void bdi_destroy(struct backing_dev_info *bdi)
{ {
int i; int i;
WARN_ON(!list_empty(&bdi->b_dirty));
WARN_ON(!list_empty(&bdi->b_io));
WARN_ON(!list_empty(&bdi->b_more_io));
bdi_unregister(bdi); bdi_unregister(bdi);
for (i = 0; i < NR_BDI_STAT_ITEMS; i++) for (i = 0; i < NR_BDI_STAT_ITEMS; i++)
......
...@@ -320,15 +320,13 @@ static void task_dirty_limit(struct task_struct *tsk, unsigned long *pdirty) ...@@ -320,15 +320,13 @@ static void task_dirty_limit(struct task_struct *tsk, unsigned long *pdirty)
/* /*
* *
*/ */
static DEFINE_SPINLOCK(bdi_lock);
static unsigned int bdi_min_ratio; static unsigned int bdi_min_ratio;
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio) int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
{ {
int ret = 0; int ret = 0;
unsigned long flags;
spin_lock_irqsave(&bdi_lock, flags); mutex_lock(&bdi_lock);
if (min_ratio > bdi->max_ratio) { if (min_ratio > bdi->max_ratio) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
...@@ -340,27 +338,26 @@ int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio) ...@@ -340,27 +338,26 @@ int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
ret = -EINVAL; ret = -EINVAL;
} }
} }
spin_unlock_irqrestore(&bdi_lock, flags); mutex_unlock(&bdi_lock);
return ret; return ret;
} }
int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio) int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio)
{ {
unsigned long flags;
int ret = 0; int ret = 0;
if (max_ratio > 100) if (max_ratio > 100)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&bdi_lock, flags); mutex_lock(&bdi_lock);
if (bdi->min_ratio > max_ratio) { if (bdi->min_ratio > max_ratio) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
bdi->max_ratio = max_ratio; bdi->max_ratio = max_ratio;
bdi->max_prop_frac = (PROP_FRAC_BASE * max_ratio) / 100; bdi->max_prop_frac = (PROP_FRAC_BASE * max_ratio) / 100;
} }
spin_unlock_irqrestore(&bdi_lock, flags); mutex_unlock(&bdi_lock);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment