diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2009-09-09 03:08:54 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2009-09-11 03:20:25 -0400 |
commit | 03ba3782e8dcc5b0e1efe440d33084f066e38cae (patch) | |
tree | e5a6513b411de16a46199530ec98ef9b7f1efc50 /include/linux | |
parent | 66f3b8e2e103a0b93b945764d98e9ba46cb926dd (diff) |
writeback: switch to per-bdi threads for flushing data
This gets rid of pdflush for bdi writeout and kupdated style cleaning.
pdflush writeout suffers from lack of locality and also requires more
threads to handle the same workload, since it has to work in a
non-blocking fashion against each queue. This also introduces lumpy
behaviour and potential request starvation, since pdflush can be starved
for queue access if others are accessing it. A sample ffsb workload that
does random writes to files is about 8% faster here on a simple SATA drive
during the benchmark phase. File layout also seems a LOT more smooth in
vmstat:
r b swpd free buff cache si so bi bo in cs us sy id wa
0 1 0 608848 2652 375372 0 0 0 71024 604 24 1 10 48 42
0 1 0 549644 2712 433736 0 0 0 60692 505 27 1 8 48 44
1 0 0 476928 2784 505192 0 0 4 29540 553 24 0 9 53 37
0 1 0 457972 2808 524008 0 0 0 54876 331 16 0 4 38 58
0 1 0 366128 2928 614284 0 0 4 92168 710 58 0 13 53 34
0 1 0 295092 3000 684140 0 0 0 62924 572 23 0 9 53 37
0 1 0 236592 3064 741704 0 0 4 58256 523 17 0 8 48 44
0 1 0 165608 3132 811464 0 0 0 57460 560 21 0 8 54 38
0 1 0 102952 3200 873164 0 0 4 74748 540 29 1 10 48 41
0 1 0 48604 3252 926472 0 0 0 53248 469 29 0 7 47 45
where vanilla tends to fluctuate a lot in the creation phase:
r b swpd free buff cache si so bi bo in cs us sy id wa
1 1 0 678716 5792 303380 0 0 0 74064 565 50 1 11 52 36
1 0 0 662488 5864 319396 0 0 4 352 302 329 0 2 47 51
0 1 0 599312 5924 381468 0 0 0 78164 516 55 0 9 51 40
0 1 0 519952 6008 459516 0 0 4 78156 622 56 1 11 52 37
1 1 0 436640 6092 541632 0 0 0 82244 622 54 0 11 48 41
0 1 0 436640 6092 541660 0 0 0 8 152 39 0 0 51 49
0 1 0 332224 6200 644252 0 0 4 102800 728 46 1 13 49 36
1 0 0 274492 6260 701056 0 0 4 12328 459 49 0 7 50 43
0 1 0 211220 6324 763356 0 0 0 106940 515 37 1 10 51 39
1 0 0 160412 6376 813468 0 0 0 8224 415 43 0 6 49 45
1 1 0 85980 6452 886556 0 0 4 113516 575 39 1 11 54 34
0 2 0 85968 6452 886620 0 0 0 1640 158 211 0 0 46 54
A 10 disk test with btrfs performs 26% faster with per-bdi flushing. A
SSD based writeback test on XFS performs over 20% better as well, with
the throughput being very stable around 1GB/sec, where pdflush only
manages 750MB/sec and fluctuates wildly while doing so. Random buffered
writes to many files behave a lot better as well, as does random mmap'ed
writes.
A separate thread is added to sync the super blocks. In the long term,
adding sync_supers_bdi() functionality could get rid of this thread again.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/backing-dev.h | 55 | ||||
-rw-r--r-- | include/linux/fs.h | 2 | ||||
-rw-r--r-- | include/linux/writeback.h | 8 |
3 files changed, 55 insertions, 10 deletions
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 928cd5484f4d..d045f5f615c7 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h | |||
@@ -13,6 +13,8 @@ | |||
13 | #include <linux/proportions.h> | 13 | #include <linux/proportions.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/fs.h> | 15 | #include <linux/fs.h> |
16 | #include <linux/sched.h> | ||
17 | #include <linux/writeback.h> | ||
16 | #include <asm/atomic.h> | 18 | #include <asm/atomic.h> |
17 | 19 | ||
18 | struct page; | 20 | struct page; |
@@ -23,7 +25,8 @@ struct dentry; | |||
23 | * Bits in backing_dev_info.state | 25 | * Bits in backing_dev_info.state |
24 | */ | 26 | */ |
25 | enum bdi_state { | 27 | enum bdi_state { |
26 | BDI_pdflush, /* A pdflush thread is working this device */ | 28 | BDI_pending, /* On its way to being activated */ |
29 | BDI_wb_alloc, /* Default embedded wb allocated */ | ||
27 | BDI_async_congested, /* The async (write) queue is getting full */ | 30 | BDI_async_congested, /* The async (write) queue is getting full */ |
28 | BDI_sync_congested, /* The sync queue is getting full */ | 31 | BDI_sync_congested, /* The sync queue is getting full */ |
29 | BDI_unused, /* Available bits start here */ | 32 | BDI_unused, /* Available bits start here */ |
@@ -39,9 +42,22 @@ enum bdi_stat_item { | |||
39 | 42 | ||
40 | #define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids))) | 43 | #define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids))) |
41 | 44 | ||
45 | struct bdi_writeback { | ||
46 | struct list_head list; /* hangs off the bdi */ | ||
47 | |||
48 | struct backing_dev_info *bdi; /* our parent bdi */ | ||
49 | unsigned int nr; | ||
50 | |||
51 | unsigned long last_old_flush; /* last old data flush */ | ||
52 | |||
53 | struct task_struct *task; /* writeback task */ | ||
54 | struct list_head b_dirty; /* dirty inodes */ | ||
55 | struct list_head b_io; /* parked for writeback */ | ||
56 | struct list_head b_more_io; /* parked for more writeback */ | ||
57 | }; | ||
58 | |||
42 | struct backing_dev_info { | 59 | struct backing_dev_info { |
43 | struct list_head bdi_list; | 60 | struct list_head bdi_list; |
44 | |||
45 | unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ | 61 | unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ |
46 | unsigned long state; /* Always use atomic bitops on this */ | 62 | unsigned long state; /* Always use atomic bitops on this */ |
47 | unsigned int capabilities; /* Device capabilities */ | 63 | unsigned int capabilities; /* Device capabilities */ |
@@ -58,11 +74,15 @@ struct backing_dev_info { | |||
58 | unsigned int min_ratio; | 74 | unsigned int min_ratio; |
59 | unsigned int max_ratio, max_prop_frac; | 75 | unsigned int max_ratio, max_prop_frac; |
60 | 76 | ||
61 | struct device *dev; | 77 | struct bdi_writeback wb; /* default writeback info for this bdi */ |
78 | spinlock_t wb_lock; /* protects update side of wb_list */ | ||
79 | struct list_head wb_list; /* the flusher threads hanging off this bdi */ | ||
80 | unsigned long wb_mask; /* bitmask of registered tasks */ | ||
81 | unsigned int wb_cnt; /* number of registered tasks */ | ||
62 | 82 | ||
63 | struct list_head b_dirty; /* dirty inodes */ | 83 | struct list_head work_list; |
64 | struct list_head b_io; /* parked for writeback */ | 84 | |
65 | struct list_head b_more_io; /* parked for more writeback */ | 85 | struct device *dev; |
66 | 86 | ||
67 | #ifdef CONFIG_DEBUG_FS | 87 | #ifdef CONFIG_DEBUG_FS |
68 | struct dentry *debug_dir; | 88 | struct dentry *debug_dir; |
@@ -77,10 +97,20 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent, | |||
77 | const char *fmt, ...); | 97 | const char *fmt, ...); |
78 | int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev); | 98 | int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev); |
79 | void bdi_unregister(struct backing_dev_info *bdi); | 99 | void bdi_unregister(struct backing_dev_info *bdi); |
100 | void bdi_start_writeback(struct writeback_control *wbc); | ||
101 | int bdi_writeback_task(struct bdi_writeback *wb); | ||
102 | int bdi_has_dirty_io(struct backing_dev_info *bdi); | ||
80 | 103 | ||
81 | extern struct mutex bdi_lock; | 104 | extern spinlock_t bdi_lock; |
82 | extern struct list_head bdi_list; | 105 | extern struct list_head bdi_list; |
83 | 106 | ||
107 | static inline int wb_has_dirty_io(struct bdi_writeback *wb) | ||
108 | { | ||
109 | return !list_empty(&wb->b_dirty) || | ||
110 | !list_empty(&wb->b_io) || | ||
111 | !list_empty(&wb->b_more_io); | ||
112 | } | ||
113 | |||
84 | static inline void __add_bdi_stat(struct backing_dev_info *bdi, | 114 | static inline void __add_bdi_stat(struct backing_dev_info *bdi, |
85 | enum bdi_stat_item item, s64 amount) | 115 | enum bdi_stat_item item, s64 amount) |
86 | { | 116 | { |
@@ -270,6 +300,11 @@ static inline bool bdi_cap_swap_backed(struct backing_dev_info *bdi) | |||
270 | return bdi->capabilities & BDI_CAP_SWAP_BACKED; | 300 | return bdi->capabilities & BDI_CAP_SWAP_BACKED; |
271 | } | 301 | } |
272 | 302 | ||
303 | static inline bool bdi_cap_flush_forker(struct backing_dev_info *bdi) | ||
304 | { | ||
305 | return bdi == &default_backing_dev_info; | ||
306 | } | ||
307 | |||
273 | static inline bool mapping_cap_writeback_dirty(struct address_space *mapping) | 308 | static inline bool mapping_cap_writeback_dirty(struct address_space *mapping) |
274 | { | 309 | { |
275 | return bdi_cap_writeback_dirty(mapping->backing_dev_info); | 310 | return bdi_cap_writeback_dirty(mapping->backing_dev_info); |
@@ -285,4 +320,10 @@ static inline bool mapping_cap_swap_backed(struct address_space *mapping) | |||
285 | return bdi_cap_swap_backed(mapping->backing_dev_info); | 320 | return bdi_cap_swap_backed(mapping->backing_dev_info); |
286 | } | 321 | } |
287 | 322 | ||
323 | static inline int bdi_sched_wait(void *word) | ||
324 | { | ||
325 | schedule(); | ||
326 | return 0; | ||
327 | } | ||
328 | |||
288 | #endif /* _LINUX_BACKING_DEV_H */ | 329 | #endif /* _LINUX_BACKING_DEV_H */ |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 56371be1be65..26da98f61116 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1786,6 +1786,7 @@ extern int get_sb_pseudo(struct file_system_type *, char *, | |||
1786 | struct vfsmount *mnt); | 1786 | struct vfsmount *mnt); |
1787 | extern void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); | 1787 | extern void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); |
1788 | int __put_super_and_need_restart(struct super_block *sb); | 1788 | int __put_super_and_need_restart(struct super_block *sb); |
1789 | void put_super(struct super_block *sb); | ||
1789 | 1790 | ||
1790 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ | 1791 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ |
1791 | #define fops_get(fops) \ | 1792 | #define fops_get(fops) \ |
@@ -2182,7 +2183,6 @@ extern int bdev_read_only(struct block_device *); | |||
2182 | extern int set_blocksize(struct block_device *, int); | 2183 | extern int set_blocksize(struct block_device *, int); |
2183 | extern int sb_set_blocksize(struct super_block *, int); | 2184 | extern int sb_set_blocksize(struct super_block *, int); |
2184 | extern int sb_min_blocksize(struct super_block *, int); | 2185 | extern int sb_min_blocksize(struct super_block *, int); |
2185 | extern int sb_has_dirty_inodes(struct super_block *); | ||
2186 | 2186 | ||
2187 | extern int generic_file_mmap(struct file *, struct vm_area_struct *); | 2187 | extern int generic_file_mmap(struct file *, struct vm_area_struct *); |
2188 | extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); | 2188 | extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); |
diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 07039299603d..cef75527a14c 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h | |||
@@ -40,6 +40,8 @@ enum writeback_sync_modes { | |||
40 | struct writeback_control { | 40 | struct writeback_control { |
41 | struct backing_dev_info *bdi; /* If !NULL, only write back this | 41 | struct backing_dev_info *bdi; /* If !NULL, only write back this |
42 | queue */ | 42 | queue */ |
43 | struct super_block *sb; /* if !NULL, only write inodes from | ||
44 | this super_block */ | ||
43 | enum writeback_sync_modes sync_mode; | 45 | enum writeback_sync_modes sync_mode; |
44 | unsigned long *older_than_this; /* If !NULL, only write back inodes | 46 | unsigned long *older_than_this; /* If !NULL, only write back inodes |
45 | older than this */ | 47 | older than this */ |
@@ -76,10 +78,13 @@ struct writeback_control { | |||
76 | /* | 78 | /* |
77 | * fs/fs-writeback.c | 79 | * fs/fs-writeback.c |
78 | */ | 80 | */ |
79 | void writeback_inodes(struct writeback_control *wbc); | 81 | struct bdi_writeback; |
80 | int inode_wait(void *); | 82 | int inode_wait(void *); |
81 | long writeback_inodes_sb(struct super_block *); | 83 | long writeback_inodes_sb(struct super_block *); |
82 | long sync_inodes_sb(struct super_block *); | 84 | long sync_inodes_sb(struct super_block *); |
85 | void writeback_inodes_wbc(struct writeback_control *wbc); | ||
86 | long wb_do_writeback(struct bdi_writeback *wb, int force_wait); | ||
87 | void wakeup_flusher_threads(long nr_pages); | ||
83 | 88 | ||
84 | /* writeback.h requires fs.h; it, too, is not included from here. */ | 89 | /* writeback.h requires fs.h; it, too, is not included from here. */ |
85 | static inline void wait_on_inode(struct inode *inode) | 90 | static inline void wait_on_inode(struct inode *inode) |
@@ -99,7 +104,6 @@ static inline void inode_sync_wait(struct inode *inode) | |||
99 | /* | 104 | /* |
100 | * mm/page-writeback.c | 105 | * mm/page-writeback.c |
101 | */ | 106 | */ |
102 | int wakeup_pdflush(long nr_pages); | ||
103 | void laptop_io_completion(void); | 107 | void laptop_io_completion(void); |
104 | void laptop_sync_completion(void); | 108 | void laptop_sync_completion(void); |
105 | void throttle_vm_writeout(gfp_t gfp_mask); | 109 | void throttle_vm_writeout(gfp_t gfp_mask); |