1 Index: linux-stage/fs/ext4/ext4.h
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/ext4.h 2011-03-11 14:17:02.000000000 +0800
4 +++ linux-stage/fs/ext4/ext4.h 2011-03-11 14:20:08.269063193 +0800
8 unsigned long s_stripe;
9 - unsigned int s_mb_stream_request;
10 + unsigned long s_mb_small_req;
11 + unsigned long s_mb_large_req;
12 unsigned int s_mb_max_to_scan;
13 unsigned int s_mb_min_to_scan;
14 unsigned int s_mb_stats;
15 unsigned int s_mb_order2_reqs;
16 + unsigned long *s_mb_prealloc_table;
17 + unsigned long s_mb_prealloc_table_size;
18 unsigned int s_mb_group_prealloc;
19 unsigned int s_max_writeback_mb_bump;
20 /* where last allocation was done - for stream allocation */
21 Index: linux-stage/fs/ext4/inode.c
22 ===================================================================
23 @@ -3028,6 +3028,11 @@ static int ext4_da_writepages(struct add
24 if (unlikely(sbi->s_mount_flags & EXT4_MF_FS_ABORTED))
27 + if (wbc->nr_to_write < sbi->s_mb_small_req) {
28 + nr_to_writebump = sbi->s_mb_small_req - wbc->nr_to_write;
29 + wbc->nr_to_write = sbi->s_mb_small_req;
32 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
35 Index: linux-stage/fs/ext4/mballoc.c
36 ===================================================================
37 --- linux-stage.orig/fs/ext4/mballoc.c 2011-03-11 14:03:32.000000000 +0800
38 +++ linux-stage/fs/ext4/mballoc.c 2011-03-11 14:44:49.106543493 +0800
39 @@ -1823,6 +1823,26 @@
43 +static void ext4_mb_prealloc_table_add(struct ext4_sb_info *sbi, int value)
47 + if (value > (sbi->s_blocks_per_group - 1 - 1 - sbi->s_itb_per_group))
50 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
51 + if (sbi->s_mb_prealloc_table[i] == 0) {
52 + sbi->s_mb_prealloc_table[i] = value;
56 + /* they should add values in order */
57 + if (value <= sbi->s_mb_prealloc_table[i])
63 static int ext4_mb_good_group(struct ext4_allocation_context *ac,
64 ext4_group_t group, int cr)
66 @@ -2173,6 +2193,80 @@
67 .show = ext4_mb_seq_groups_show,
70 +#define EXT4_MB_PREALLOC_TABLE "prealloc_table"
72 +static int ext4_mb_prealloc_table_proc_read(char *page, char **start, off_t off,
73 + int count, int *eof, void *data)
75 + struct ext4_sb_info *sbi = data;
83 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++)
84 + len += sprintf(page + len, "%ld ",
85 + sbi->s_mb_prealloc_table[i]);
86 + len += sprintf(page + len, "\n");
92 +static int ext4_mb_prealloc_table_proc_write(struct file *file,
93 + const char __user *buf,
94 + unsigned long cnt, void *data)
96 + struct ext4_sb_info *sbi = data;
97 + unsigned long value;
98 + unsigned long prev = 0;
102 + unsigned long *new_table;
106 + if (cnt >= sizeof(str))
108 + if (copy_from_user(str, buf, cnt))
114 + while (cur < end) {
115 + while ((cur < end) && (*cur == ' ')) cur++;
116 + value = simple_strtol(cur, &cur, 0);
125 + new_table = kmalloc(num * sizeof(*new_table), GFP_KERNEL);
126 + if (new_table == NULL)
128 + kfree(sbi->s_mb_prealloc_table);
129 + memset(new_table, 0, num * sizeof(*new_table));
130 + sbi->s_mb_prealloc_table = new_table;
131 + sbi->s_mb_prealloc_table_size = num;
134 + while (cur < end && i < num) {
135 + while ((cur < end) && (*cur == ' ')) cur++;
136 + value = simple_strtol(cur, &cur, 0);
137 + ext4_mb_prealloc_table_add(sbi, value);
144 static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
146 struct super_block *sb = PDE(inode)->data;
147 @@ -2411,12 +2505,56 @@
148 sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
149 sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
150 sbi->s_mb_stats = MB_DEFAULT_STATS;
151 - sbi->s_mb_stream_request = MB_DEFAULT_STREAM_THRESHOLD;
152 sbi->s_mb_order2_reqs = MB_DEFAULT_ORDER2_REQS;
153 - sbi->s_mb_group_prealloc = MB_DEFAULT_GROUP_PREALLOC;
155 + if (sbi->s_stripe == 0) {
156 + sbi->s_mb_prealloc_table_size = 10;
157 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
158 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
159 + if (sbi->s_mb_prealloc_table == NULL) {
160 + kfree(sbi->s_mb_offsets);
161 + kfree(sbi->s_mb_maxs);
164 + memset(sbi->s_mb_prealloc_table, 0, i);
166 + ext4_mb_prealloc_table_add(sbi, 4);
167 + ext4_mb_prealloc_table_add(sbi, 8);
168 + ext4_mb_prealloc_table_add(sbi, 16);
169 + ext4_mb_prealloc_table_add(sbi, 32);
170 + ext4_mb_prealloc_table_add(sbi, 64);
171 + ext4_mb_prealloc_table_add(sbi, 128);
172 + ext4_mb_prealloc_table_add(sbi, 256);
173 + ext4_mb_prealloc_table_add(sbi, 512);
174 + ext4_mb_prealloc_table_add(sbi, 1024);
175 + ext4_mb_prealloc_table_add(sbi, 2048);
177 + sbi->s_mb_small_req = 256;
178 + sbi->s_mb_large_req = 1024;
179 + sbi->s_mb_group_prealloc = 512;
181 + sbi->s_mb_prealloc_table_size = 3;
182 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
183 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
184 + if (sbi->s_mb_prealloc_table == NULL) {
185 + kfree(sbi->s_mb_offsets);
186 + kfree(sbi->s_mb_maxs);
189 + memset(sbi->s_mb_prealloc_table, 0, i);
191 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe);
192 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 2);
193 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 4);
195 + sbi->s_mb_small_req = sbi->s_stripe;
196 + sbi->s_mb_large_req = sbi->s_stripe * 8;
197 + sbi->s_mb_group_prealloc = sbi->s_stripe * 4;
200 sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
201 if (sbi->s_locality_groups == NULL) {
202 + kfree(sbi->s_mb_prealloc_table);
203 kfree(sbi->s_mb_offsets);
204 kfree(sbi->s_mb_maxs);
206 @@ -2430,9 +2568,18 @@
207 spin_lock_init(&lg->lg_prealloc_lock);
212 + struct proc_dir_entry *p;
213 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
214 &ext4_mb_seq_groups_fops, sb);
215 + p = create_proc_entry(EXT4_MB_PREALLOC_TABLE, S_IFREG |
216 + S_IRUGO | S_IWUSR, sbi->s_proc);
219 + p->read_proc = ext4_mb_prealloc_table_proc_read;
220 + p->write_proc = ext4_mb_prealloc_table_proc_write;
225 sbi->s_journal->j_commit_callback = release_blocks_on_commit;
226 @@ -2512,8 +2659,10 @@
229 free_percpu(sbi->s_locality_groups);
232 remove_proc_entry("mb_groups", sbi->s_proc);
233 + remove_proc_entry(EXT4_MB_PREALLOC_TABLE, sbi->s_proc);
238 @@ -2807,11 +2956,12 @@
239 ext4_mb_normalize_request(struct ext4_allocation_context *ac,
240 struct ext4_allocation_request *ar)
243 + int bsbits, i, wind;
245 - loff_t size, orig_size, start_off;
246 + loff_t size, orig_size;
247 ext4_lblk_t start, orig_start;
248 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
249 + struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
250 struct ext4_prealloc_space *pa;
252 /* do normalize only data requests, metadata requests
253 @@ -2841,49 +2991,35 @@
254 size = size << bsbits;
255 if (size < i_size_read(ac->ac_inode))
256 size = i_size_read(ac->ac_inode);
257 + size = (size + ac->ac_sb->s_blocksize - 1) >> bsbits;
259 - /* max size of free chunks */
263 -#define NRL_CHECK_SIZE(req, size, max, chunk_size) \
264 - (req <= (size) || max <= (chunk_size))
265 + /* let's choose preallocation window depending on file size */
266 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
267 + if (size <= sbi->s_mb_prealloc_table[i]) {
268 + wind = sbi->s_mb_prealloc_table[i];
274 - /* first, try to predict filesize */
275 - /* XXX: should this table be tunable? */
277 - if (size <= 16 * 1024) {
279 - } else if (size <= 32 * 1024) {
281 - } else if (size <= 64 * 1024) {
283 - } else if (size <= 128 * 1024) {
285 - } else if (size <= 256 * 1024) {
287 - } else if (size <= 512 * 1024) {
289 - } else if (size <= 1024 * 1024) {
290 - size = 1024 * 1024;
291 - } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) {
292 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
293 - (21 - bsbits)) << 21;
294 - size = 2 * 1024 * 1024;
295 - } else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) {
296 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
297 - (22 - bsbits)) << 22;
298 - size = 4 * 1024 * 1024;
299 - } else if (NRL_CHECK_SIZE(ac->ac_o_ex.fe_len,
300 - (8<<20)>>bsbits, max, 8 * 1024)) {
301 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
302 - (23 - bsbits)) << 23;
303 - size = 8 * 1024 * 1024;
305 - start_off = (loff_t)ac->ac_o_ex.fe_logical << bsbits;
306 - size = ac->ac_o_ex.fe_len << bsbits;
308 + __u64 tstart, tend;
309 + /* file is quite large, we now preallocate with
310 + * the biggest configured window with regart to
311 + * logical offset */
312 + wind = sbi->s_mb_prealloc_table[i - 1];
313 + tstart = ac->ac_o_ex.fe_logical;
314 + do_div(tstart, wind);
315 + start = tstart * wind;
316 + tend = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len - 1;
317 + do_div(tend, wind);
318 + tend = tend * wind + wind;
319 + size = tend - start;
321 - orig_size = size = size >> bsbits;
322 - orig_start = start = start_off >> bsbits;
324 + orig_start = start;
326 /* don't cover already allocated blocks in selected range */
327 if (ar->pleft && start <= ar->lleft) {
328 @@ -2955,7 +3091,6 @@
330 BUG_ON(start + size <= ac->ac_o_ex.fe_logical &&
331 start > ac->ac_o_ex.fe_logical);
332 - BUG_ON(size <= 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb));
334 /* now prepare goal request */
336 @@ -3939,11 +4074,19 @@
338 /* don't use group allocation for large files */
339 size = max(size, isize);
340 - if (size > sbi->s_mb_stream_request) {
341 + if ((ac->ac_o_ex.fe_len >= sbi->s_mb_small_req) ||
342 + (size >= sbi->s_mb_large_req)) {
343 ac->ac_flags |= EXT4_MB_STREAM_ALLOC;
348 + * request is so large that we don't care about
349 + * streaming - it overweights any possible seek
351 + if (ac->ac_o_ex.fe_len >= sbi->s_mb_large_req)
354 BUG_ON(ac->ac_lg != NULL);
356 * locality group prealloc space are per cpu. The reason for having
357 Index: linux-stage/fs/ext4/super.c
358 ===================================================================
359 --- linux-stage.orig/fs/ext4/super.c 2011-03-11 14:16:56.000000000 +0800
360 +++ linux-stage/fs/ext4/super.c 2011-03-11 14:19:24.664467626 +0800
361 @@ -2632,7 +2632,8 @@
362 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
363 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
364 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
365 -EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
366 +EXT4_RW_ATTR_SBI_UI(mb_small_req, s_mb_small_req);
367 +EXT4_RW_ATTR_SBI_UI(mb_large_req, s_mb_large_req);
368 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
369 EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
371 @@ -2647,7 +2648,8 @@
372 ATTR_LIST(mb_max_to_scan),
373 ATTR_LIST(mb_min_to_scan),
374 ATTR_LIST(mb_order2_req),
375 - ATTR_LIST(mb_stream_req),
376 + ATTR_LIST(mb_small_req),
377 + ATTR_LIST(mb_large_req),
378 ATTR_LIST(mb_group_prealloc),
379 ATTR_LIST(max_writeback_mb_bump),