Commit 4667a0ec32867865fd4deccf834594b3ea831baf

Authored by Steven Whitehouse
1 parent f42ab08529

GFS2: Make writeback more responsive to system conditions

This patch adds writeback_control to writing back the AIL
list. This means that we can then take advantage of the
information we get in ->write_inode() in order to set off
some pre-emptive writeback.

In addition, the AIL code is cleaned up a bit to make it
a bit simpler to understand.

There is still more which can usefully be done in this area,
but this is a good start at least.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

Showing 8 changed files with 98 additions and 90 deletions Side-by-side Diff

... ... @@ -139,7 +139,7 @@
139 139 struct gfs2_sbd *sdp = sb->s_fs_info;
140 140 struct inode *inode;
141 141  
142   - inode = gfs2_ilookup(sb, inum->no_addr);
  142 + inode = gfs2_ilookup(sb, inum->no_addr, 0);
143 143 if (inode) {
144 144 if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) {
145 145 iput(inode);
... ... @@ -649,7 +649,7 @@
649 649 /* Note: Unsafe to dereference ip as we don't hold right refs/locks */
650 650  
651 651 if (ip)
652   - inode = gfs2_ilookup(sdp->sd_vfs, no_addr);
  652 + inode = gfs2_ilookup(sdp->sd_vfs, no_addr, 1);
653 653 else
654 654 inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED);
655 655 if (inode && !IS_ERR(inode)) {
... ... @@ -20,7 +20,6 @@
20 20  
21 21 #define DIO_WAIT 0x00000010
22 22 #define DIO_METADATA 0x00000020
23   -#define DIO_ALL 0x00000100
24 23  
25 24 struct gfs2_log_operations;
26 25 struct gfs2_log_element;
... ... @@ -377,8 +376,6 @@
377 376 unsigned int ai_first;
378 377 struct list_head ai_ail1_list;
379 378 struct list_head ai_ail2_list;
380   -
381   - u64 ai_sync_gen;
382 379 };
383 380  
384 381 struct gfs2_journal_extent {
... ... @@ -657,7 +654,6 @@
657 654 spinlock_t sd_ail_lock;
658 655 struct list_head sd_ail1_list;
659 656 struct list_head sd_ail2_list;
660   - u64 sd_ail_sync_gen;
661 657  
662 658 /* Replay stuff */
663 659  
... ... @@ -74,14 +74,14 @@
74 74 return 0;
75 75 }
76 76  
77   -struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr)
  77 +struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr, int non_block)
78 78 {
79 79 unsigned long hash = (unsigned long)no_addr;
80 80 struct gfs2_skip_data data;
81 81  
82 82 data.no_addr = no_addr;
83 83 data.skipped = 0;
84   - data.non_block = 0;
  84 + data.non_block = non_block;
85 85 return ilookup5(sb, hash, iget_test, &data);
86 86 }
87 87  
... ... @@ -102,7 +102,7 @@
102 102 extern struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
103 103 u64 *no_formal_ino,
104 104 unsigned int blktype);
105   -extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr);
  105 +extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr, int nonblock);
106 106  
107 107 extern int gfs2_inode_refresh(struct gfs2_inode *ip);
108 108  
... ... @@ -18,6 +18,7 @@
18 18 #include <linux/kthread.h>
19 19 #include <linux/freezer.h>
20 20 #include <linux/bio.h>
  21 +#include <linux/writeback.h>
21 22  
22 23 #include "gfs2.h"
23 24 #include "incore.h"
24 25  
25 26  
26 27  
27 28  
28 29  
29 30  
30 31  
31 32  
32 33  
33 34  
34 35  
35 36  
36 37  
... ... @@ -83,60 +84,100 @@
83 84 /**
84 85 * gfs2_ail1_start_one - Start I/O on a part of the AIL
85 86 * @sdp: the filesystem
86   - * @tr: the part of the AIL
  87 + * @wbc: The writeback control structure
  88 + * @ai: The ail structure
87 89 *
88 90 */
89 91  
90   -static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
  92 +static void gfs2_ail1_start_one(struct gfs2_sbd *sdp,
  93 + struct writeback_control *wbc,
  94 + struct gfs2_ail *ai)
91 95 __releases(&sdp->sd_ail_lock)
92 96 __acquires(&sdp->sd_ail_lock)
93 97 {
94 98 struct gfs2_glock *gl = NULL;
  99 + struct address_space *mapping;
95 100 struct gfs2_bufdata *bd, *s;
96 101 struct buffer_head *bh;
97   - int retry;
98 102  
99   - do {
100   - retry = 0;
  103 +restart:
  104 + list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, bd_ail_st_list) {
  105 + bh = bd->bd_bh;
101 106  
102   - list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
103   - bd_ail_st_list) {
104   - bh = bd->bd_bh;
  107 + gfs2_assert(sdp, bd->bd_ail == ai);
105 108  
106   - gfs2_assert(sdp, bd->bd_ail == ai);
  109 + if (!buffer_busy(bh)) {
  110 + if (!buffer_uptodate(bh))
  111 + gfs2_io_error_bh(sdp, bh);
  112 + list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
  113 + continue;
  114 + }
107 115  
108   - if (!buffer_busy(bh)) {
109   - if (!buffer_uptodate(bh))
110   - gfs2_io_error_bh(sdp, bh);
111   - list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
112   - continue;
113   - }
  116 + if (!buffer_dirty(bh))
  117 + continue;
  118 + if (gl == bd->bd_gl)
  119 + continue;
  120 + gl = bd->bd_gl;
  121 + list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
  122 + mapping = bh->b_page->mapping;
  123 + spin_unlock(&sdp->sd_ail_lock);
  124 + generic_writepages(mapping, wbc);
  125 + spin_lock(&sdp->sd_ail_lock);
  126 + if (wbc->nr_to_write <= 0)
  127 + break;
  128 + goto restart;
  129 + }
  130 +}
114 131  
115   - if (!buffer_dirty(bh))
116   - continue;
117   - if (gl == bd->bd_gl)
118   - continue;
119   - gl = bd->bd_gl;
120   - list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
121 132  
122   - spin_unlock(&sdp->sd_ail_lock);
123   - filemap_fdatawrite(gfs2_glock2aspace(gl));
124   - spin_lock(&sdp->sd_ail_lock);
  133 +/**
  134 + * gfs2_ail1_flush - start writeback of some ail1 entries
  135 + * @sdp: The super block
  136 + * @wbc: The writeback control structure
  137 + *
  138 + * Writes back some ail1 entries, according to the limits in the
  139 + * writeback control structure
  140 + */
125 141  
126   - retry = 1;
  142 +void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)
  143 +{
  144 + struct list_head *head = &sdp->sd_ail1_list;
  145 + struct gfs2_ail *ai;
  146 +
  147 + spin_lock(&sdp->sd_ail_lock);
  148 + list_for_each_entry_reverse(ai, head, ai_list) {
  149 + if (wbc->nr_to_write <= 0)
127 150 break;
128   - }
129   - } while (retry);
  151 + gfs2_ail1_start_one(sdp, wbc, ai); /* This may drop ail lock */
  152 + }
  153 + spin_unlock(&sdp->sd_ail_lock);
130 154 }
131 155  
132 156 /**
  157 + * gfs2_ail1_start - start writeback of all ail1 entries
  158 + * @sdp: The superblock
  159 + */
  160 +
  161 +static void gfs2_ail1_start(struct gfs2_sbd *sdp)
  162 +{
  163 + struct writeback_control wbc = {
  164 + .sync_mode = WB_SYNC_NONE,
  165 + .nr_to_write = LONG_MAX,
  166 + .range_start = 0,
  167 + .range_end = LLONG_MAX,
  168 + };
  169 +
  170 + return gfs2_ail1_flush(sdp, &wbc);
  171 +}
  172 +
  173 +/**
133 174 * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
134 175 * @sdp: the filesystem
135 176 * @ai: the AIL entry
136 177 *
137 178 */
138 179  
139   -static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
  180 +static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
140 181 {
141 182 struct gfs2_bufdata *bd, *s;
142 183 struct buffer_head *bh;
143 184  
144 185  
145 186  
146 187  
147 188  
148 189  
149 190  
150 191  
151 192  
152 193  
... ... @@ -144,71 +185,37 @@
144 185 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
145 186 bd_ail_st_list) {
146 187 bh = bd->bd_bh;
147   -
148 188 gfs2_assert(sdp, bd->bd_ail == ai);
149   -
150   - if (buffer_busy(bh)) {
151   - if (flags & DIO_ALL)
152   - continue;
153   - else
154   - break;
155   - }
156   -
  189 + if (buffer_busy(bh))
  190 + continue;
157 191 if (!buffer_uptodate(bh))
158 192 gfs2_io_error_bh(sdp, bh);
159   -
160 193 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
161 194 }
162 195  
163   - return list_empty(&ai->ai_ail1_list);
164 196 }
165 197  
166   -static void gfs2_ail1_start(struct gfs2_sbd *sdp)
167   -{
168   - struct list_head *head;
169   - u64 sync_gen;
170   - struct gfs2_ail *ai;
171   - int done = 0;
  198 +/**
  199 + * gfs2_ail1_empty - Try to empty the ail1 lists
  200 + * @sdp: The superblock
  201 + *
  202 + * Tries to empty the ail1 lists, starting with the oldest first
  203 + */
172 204  
173   - spin_lock(&sdp->sd_ail_lock);
174   - head = &sdp->sd_ail1_list;
175   - if (list_empty(head)) {
176   - spin_unlock(&sdp->sd_ail_lock);
177   - return;
178   - }
179   - sync_gen = sdp->sd_ail_sync_gen++;
180   -
181   - while(!done) {
182   - done = 1;
183   - list_for_each_entry_reverse(ai, head, ai_list) {
184   - if (ai->ai_sync_gen >= sync_gen)
185   - continue;
186   - ai->ai_sync_gen = sync_gen;
187   - gfs2_ail1_start_one(sdp, ai); /* This may drop ail lock */
188   - done = 0;
189   - break;
190   - }
191   - }
192   -
193   - spin_unlock(&sdp->sd_ail_lock);
194   -}
195   -
196   -static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
  205 +static int gfs2_ail1_empty(struct gfs2_sbd *sdp)
197 206 {
198 207 struct gfs2_ail *ai, *s;
199 208 int ret;
200 209  
201 210 spin_lock(&sdp->sd_ail_lock);
202   -
203 211 list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
204   - if (gfs2_ail1_empty_one(sdp, ai, flags))
  212 + gfs2_ail1_empty_one(sdp, ai);
  213 + if (list_empty(&ai->ai_ail1_list))
205 214 list_move(&ai->ai_list, &sdp->sd_ail2_list);
206   - else if (!(flags & DIO_ALL))
  215 + else
207 216 break;
208 217 }
209   -
210 218 ret = list_empty(&sdp->sd_ail1_list);
211   -
212 219 spin_unlock(&sdp->sd_ail_lock);
213 220  
214 221 return ret;
... ... @@ -569,7 +576,7 @@
569 576 set_buffer_uptodate(bh);
570 577 clear_buffer_dirty(bh);
571 578  
572   - gfs2_ail1_empty(sdp, 0);
  579 + gfs2_ail1_empty(sdp);
573 580 tail = current_tail(sdp);
574 581  
575 582 lh = (struct gfs2_log_header *)bh->b_data;
... ... @@ -864,7 +871,7 @@
864 871 gfs2_log_flush(sdp, NULL);
865 872 for (;;) {
866 873 gfs2_ail1_start(sdp);
867   - if (gfs2_ail1_empty(sdp, DIO_ALL))
  874 + if (gfs2_ail1_empty(sdp))
868 875 break;
869 876 msleep(10);
870 877 }
871 878  
872 879  
873 880  
... ... @@ -900,17 +907,15 @@
900 907  
901 908 preflush = atomic_read(&sdp->sd_log_pinned);
902 909 if (gfs2_jrnl_flush_reqd(sdp) || t == 0) {
903   - gfs2_ail1_empty(sdp, DIO_ALL);
  910 + gfs2_ail1_empty(sdp);
904 911 gfs2_log_flush(sdp, NULL);
905   - gfs2_ail1_empty(sdp, DIO_ALL);
906 912 }
907 913  
908 914 if (gfs2_ail_flush_reqd(sdp)) {
909 915 gfs2_ail1_start(sdp);
910 916 io_schedule();
911   - gfs2_ail1_empty(sdp, 0);
  917 + gfs2_ail1_empty(sdp);
912 918 gfs2_log_flush(sdp, NULL);
913   - gfs2_ail1_empty(sdp, DIO_ALL);
914 919 }
915 920  
916 921 wake_up(&sdp->sd_log_waitq);
... ... @@ -12,6 +12,7 @@
12 12  
13 13 #include <linux/list.h>
14 14 #include <linux/spinlock.h>
  15 +#include <linux/writeback.h>
15 16 #include "incore.h"
16 17  
17 18 /**
... ... @@ -59,6 +60,7 @@
59 60 extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl);
60 61 extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
61 62 extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
  63 +extern void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc);
62 64  
63 65 extern void gfs2_log_shutdown(struct gfs2_sbd *sdp);
64 66 extern void gfs2_meta_syncfs(struct gfs2_sbd *sdp);
... ... @@ -23,6 +23,7 @@
23 23 #include <linux/time.h>
24 24 #include <linux/wait.h>
25 25 #include <linux/writeback.h>
  26 +#include <linux/backing-dev.h>
26 27  
27 28 #include "gfs2.h"
28 29 #include "incore.h"
... ... @@ -714,6 +715,7 @@
714 715 struct gfs2_inode *ip = GFS2_I(inode);
715 716 struct gfs2_sbd *sdp = GFS2_SB(inode);
716 717 struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl);
  718 + struct backing_dev_info *bdi = metamapping->backing_dev_info;
717 719 struct gfs2_holder gh;
718 720 struct buffer_head *bh;
719 721 struct timespec atime;
... ... @@ -747,6 +749,8 @@
747 749 if (wbc->sync_mode == WB_SYNC_ALL)
748 750 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
749 751 filemap_fdatawrite(metamapping);
  752 + if (bdi->dirty_exceeded)
  753 + gfs2_ail1_flush(sdp, wbc);
750 754 if (!ret && (wbc->sync_mode == WB_SYNC_ALL))
751 755 ret = filemap_fdatawait(metamapping);
752 756 if (ret)
... ... @@ -1366,7 +1370,8 @@
1366 1370 if (error)
1367 1371 goto out_rindex_relse;
1368 1372  
1369   - error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1);
  1373 + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA,
  1374 + sdp->sd_jdesc->jd_blocks);
1370 1375 if (error)
1371 1376 goto out_rg_gunlock;
1372 1377