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,25 @@
44 +static void ext4_mb_prealloc_table_add(struct ext4_sb_info *sbi, int value)
48 + if (value > (sbi->s_blocks_per_group - 1 - 1 - sbi->s_itb_per_group))
51 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
52 + if (sbi->s_mb_prealloc_table[i] == 0) {
53 + sbi->s_mb_prealloc_table[i] = value;
57 + /* they should add values in order */
58 + 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)
65 @@ -2173,6 +2193,80 @@
66 .show = ext4_mb_seq_groups_show,
69 +#define EXT4_MB_PREALLOC_TABLE "prealloc_table"
71 +static int ext4_mb_prealloc_table_proc_read(char *page, char **start, off_t off,
72 + int count, int *eof, void *data)
74 + struct ext4_sb_info *sbi = data;
82 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++)
83 + len += sprintf(page + len, "%ld ",
84 + sbi->s_mb_prealloc_table[i]);
85 + len += sprintf(page + len, "\n");
91 +static int ext4_mb_prealloc_table_proc_write(struct file *file,
92 + const char __user *buf,
93 + unsigned long cnt, void *data)
95 + struct ext4_sb_info *sbi = data;
96 + unsigned long value;
97 + unsigned long prev = 0;
101 + unsigned long *new_table;
105 + if (cnt >= sizeof(str))
107 + if (copy_from_user(str, buf, cnt))
113 + while (cur < end) {
114 + while ((cur < end) && (*cur == ' ')) cur++;
115 + value = simple_strtol(cur, &cur, 0);
124 + new_table = kmalloc(num * sizeof(*new_table), GFP_KERNEL);
125 + if (new_table == NULL)
127 + kfree(sbi->s_mb_prealloc_table);
128 + memset(new_table, 0, num * sizeof(*new_table));
129 + sbi->s_mb_prealloc_table = new_table;
130 + sbi->s_mb_prealloc_table_size = num;
133 + while (cur < end && i < num) {
134 + while ((cur < end) && (*cur == ' ')) cur++;
135 + value = simple_strtol(cur, &cur, 0);
136 + ext4_mb_prealloc_table_add(sbi, value);
143 static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
145 struct super_block *sb = PDE(inode)->data;
146 @@ -2397,14 +2497,6 @@ int ext4_mb_init(struct super_block *sb,
148 } while (i <= sb->s_blocksize_bits + 1);
150 - /* init file for buddy data */
151 - ret = ext4_mb_init_backend(sb);
153 - kfree(sbi->s_mb_offsets);
154 - kfree(sbi->s_mb_maxs);
158 spin_lock_init(&sbi->s_md_lock);
159 spin_lock_init(&sbi->s_bal_lock);
161 @@ -2411,12 +2505,56 @@
162 sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
163 sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
164 sbi->s_mb_stats = MB_DEFAULT_STATS;
165 - sbi->s_mb_stream_request = MB_DEFAULT_STREAM_THRESHOLD;
166 sbi->s_mb_order2_reqs = MB_DEFAULT_ORDER2_REQS;
167 - sbi->s_mb_group_prealloc = MB_DEFAULT_GROUP_PREALLOC;
169 + if (sbi->s_stripe == 0) {
170 + sbi->s_mb_prealloc_table_size = 10;
171 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
172 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
173 + if (sbi->s_mb_prealloc_table == NULL) {
174 + kfree(sbi->s_mb_offsets);
175 + kfree(sbi->s_mb_maxs);
178 + memset(sbi->s_mb_prealloc_table, 0, i);
180 + ext4_mb_prealloc_table_add(sbi, 4);
181 + ext4_mb_prealloc_table_add(sbi, 8);
182 + ext4_mb_prealloc_table_add(sbi, 16);
183 + ext4_mb_prealloc_table_add(sbi, 32);
184 + ext4_mb_prealloc_table_add(sbi, 64);
185 + ext4_mb_prealloc_table_add(sbi, 128);
186 + ext4_mb_prealloc_table_add(sbi, 256);
187 + ext4_mb_prealloc_table_add(sbi, 512);
188 + ext4_mb_prealloc_table_add(sbi, 1024);
189 + ext4_mb_prealloc_table_add(sbi, 2048);
191 + sbi->s_mb_small_req = 256;
192 + sbi->s_mb_large_req = 1024;
193 + sbi->s_mb_group_prealloc = 512;
195 + sbi->s_mb_prealloc_table_size = 3;
196 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
197 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
198 + if (sbi->s_mb_prealloc_table == NULL) {
199 + kfree(sbi->s_mb_offsets);
200 + kfree(sbi->s_mb_maxs);
203 + memset(sbi->s_mb_prealloc_table, 0, i);
205 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe);
206 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 2);
207 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 4);
209 + sbi->s_mb_small_req = sbi->s_stripe;
210 + sbi->s_mb_large_req = sbi->s_stripe * 8;
211 + sbi->s_mb_group_prealloc = sbi->s_stripe * 4;
214 sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
215 if (sbi->s_locality_groups == NULL) {
216 + kfree(sbi->s_mb_prealloc_table);
217 kfree(sbi->s_mb_offsets);
218 kfree(sbi->s_mb_maxs);
220 @@ -2430,9 +2568,27 @@
221 spin_lock_init(&lg->lg_prealloc_lock);
224 + /* init file for buddy data */
225 + ret = ext4_mb_init_backend(sb);
227 + kfree(sbi->s_mb_prealloc_table);
228 + kfree(sbi->s_mb_offsets);
229 + kfree(sbi->s_mb_maxs);
235 + struct proc_dir_entry *p;
236 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
237 &ext4_mb_seq_groups_fops, sb);
238 + p = create_proc_entry(EXT4_MB_PREALLOC_TABLE, S_IFREG |
239 + S_IRUGO | S_IWUSR, sbi->s_proc);
242 + p->read_proc = ext4_mb_prealloc_table_proc_read;
243 + p->write_proc = ext4_mb_prealloc_table_proc_write;
248 sbi->s_journal->j_commit_callback = release_blocks_on_commit;
249 @@ -2483,6 +2639,7 @@
250 kfree(sbi->s_group_info[i]);
251 kfree(sbi->s_group_info);
253 + kfree(sbi->s_mb_prealloc_table);
254 kfree(sbi->s_mb_offsets);
255 kfree(sbi->s_mb_maxs);
256 if (sbi->s_buddy_cache)
257 @@ -2512,8 +2668,10 @@
260 free_percpu(sbi->s_locality_groups);
263 remove_proc_entry("mb_groups", sbi->s_proc);
264 + remove_proc_entry(EXT4_MB_PREALLOC_TABLE, sbi->s_proc);
269 @@ -2807,11 +2965,12 @@
270 ext4_mb_normalize_request(struct ext4_allocation_context *ac,
271 struct ext4_allocation_request *ar)
274 + int bsbits, i, wind;
276 - loff_t size, orig_size, start_off;
277 + loff_t size, orig_size;
278 ext4_lblk_t start, orig_start;
279 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
280 + struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
281 struct ext4_prealloc_space *pa;
283 /* do normalize only data requests, metadata requests
284 @@ -2841,49 +3000,35 @@
285 size = size << bsbits;
286 if (size < i_size_read(ac->ac_inode))
287 size = i_size_read(ac->ac_inode);
288 + size = (size + ac->ac_sb->s_blocksize - 1) >> bsbits;
290 - /* max size of free chunks */
294 -#define NRL_CHECK_SIZE(req, size, max, chunk_size) \
295 - (req <= (size) || max <= (chunk_size))
296 + /* let's choose preallocation window depending on file size */
297 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
298 + if (size <= sbi->s_mb_prealloc_table[i]) {
299 + wind = sbi->s_mb_prealloc_table[i];
305 - /* first, try to predict filesize */
306 - /* XXX: should this table be tunable? */
308 - if (size <= 16 * 1024) {
310 - } else if (size <= 32 * 1024) {
312 - } else if (size <= 64 * 1024) {
314 - } else if (size <= 128 * 1024) {
316 - } else if (size <= 256 * 1024) {
318 - } else if (size <= 512 * 1024) {
320 - } else if (size <= 1024 * 1024) {
321 - size = 1024 * 1024;
322 - } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) {
323 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
324 - (21 - bsbits)) << 21;
325 - size = 2 * 1024 * 1024;
326 - } else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) {
327 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
328 - (22 - bsbits)) << 22;
329 - size = 4 * 1024 * 1024;
330 - } else if (NRL_CHECK_SIZE(ac->ac_o_ex.fe_len,
331 - (8<<20)>>bsbits, max, 8 * 1024)) {
332 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
333 - (23 - bsbits)) << 23;
334 - size = 8 * 1024 * 1024;
336 - start_off = (loff_t)ac->ac_o_ex.fe_logical << bsbits;
337 - size = ac->ac_o_ex.fe_len << bsbits;
339 + __u64 tstart, tend;
340 + /* file is quite large, we now preallocate with
341 + * the biggest configured window with regart to
342 + * logical offset */
343 + wind = sbi->s_mb_prealloc_table[i - 1];
344 + tstart = ac->ac_o_ex.fe_logical;
345 + do_div(tstart, wind);
346 + start = tstart * wind;
347 + tend = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len - 1;
348 + do_div(tend, wind);
349 + tend = tend * wind + wind;
350 + size = tend - start;
352 - orig_size = size = size >> bsbits;
353 - orig_start = start = start_off >> bsbits;
355 + orig_start = start;
357 /* don't cover already allocated blocks in selected range */
358 if (ar->pleft && start <= ar->lleft) {
359 @@ -2955,7 +3100,6 @@
361 BUG_ON(start + size <= ac->ac_o_ex.fe_logical &&
362 start > ac->ac_o_ex.fe_logical);
363 - BUG_ON(size <= 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb));
365 /* now prepare goal request */
367 @@ -3939,11 +4083,19 @@
369 /* don't use group allocation for large files */
370 size = max(size, isize);
371 - if (size > sbi->s_mb_stream_request) {
372 + if ((ac->ac_o_ex.fe_len >= sbi->s_mb_small_req) ||
373 + (size >= sbi->s_mb_large_req)) {
374 ac->ac_flags |= EXT4_MB_STREAM_ALLOC;
379 + * request is so large that we don't care about
380 + * streaming - it overweights any possible seek
382 + if (ac->ac_o_ex.fe_len >= sbi->s_mb_large_req)
385 BUG_ON(ac->ac_lg != NULL);
387 * locality group prealloc space are per cpu. The reason for having
388 Index: linux-stage/fs/ext4/super.c
389 ===================================================================
390 --- linux-stage.orig/fs/ext4/super.c 2011-03-11 14:16:56.000000000 +0800
391 +++ linux-stage/fs/ext4/super.c 2011-03-11 14:19:24.664467626 +0800
392 @@ -2632,7 +2632,8 @@
393 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
394 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
395 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
396 -EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
397 +EXT4_RW_ATTR_SBI_UI(mb_small_req, s_mb_small_req);
398 +EXT4_RW_ATTR_SBI_UI(mb_large_req, s_mb_large_req);
399 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
400 EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
402 @@ -2647,7 +2648,8 @@
403 ATTR_LIST(mb_max_to_scan),
404 ATTR_LIST(mb_min_to_scan),
405 ATTR_LIST(mb_order2_req),
406 - ATTR_LIST(mb_stream_req),
407 + ATTR_LIST(mb_small_req),
408 + ATTR_LIST(mb_large_req),
409 ATTR_LIST(mb_group_prealloc),
410 ATTR_LIST(max_writeback_mb_bump),