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 @@ -2411,12 +2505,56 @@
147 sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
148 sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
149 sbi->s_mb_stats = MB_DEFAULT_STATS;
150 - sbi->s_mb_stream_request = MB_DEFAULT_STREAM_THRESHOLD;
151 sbi->s_mb_order2_reqs = MB_DEFAULT_ORDER2_REQS;
152 - sbi->s_mb_group_prealloc = MB_DEFAULT_GROUP_PREALLOC;
154 + if (sbi->s_stripe == 0) {
155 + sbi->s_mb_prealloc_table_size = 10;
156 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
157 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
158 + if (sbi->s_mb_prealloc_table == NULL) {
159 + kfree(sbi->s_mb_offsets);
160 + kfree(sbi->s_mb_maxs);
163 + memset(sbi->s_mb_prealloc_table, 0, i);
165 + ext4_mb_prealloc_table_add(sbi, 4);
166 + ext4_mb_prealloc_table_add(sbi, 8);
167 + ext4_mb_prealloc_table_add(sbi, 16);
168 + ext4_mb_prealloc_table_add(sbi, 32);
169 + ext4_mb_prealloc_table_add(sbi, 64);
170 + ext4_mb_prealloc_table_add(sbi, 128);
171 + ext4_mb_prealloc_table_add(sbi, 256);
172 + ext4_mb_prealloc_table_add(sbi, 512);
173 + ext4_mb_prealloc_table_add(sbi, 1024);
174 + ext4_mb_prealloc_table_add(sbi, 2048);
176 + sbi->s_mb_small_req = 256;
177 + sbi->s_mb_large_req = 1024;
178 + sbi->s_mb_group_prealloc = 512;
180 + sbi->s_mb_prealloc_table_size = 3;
181 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
182 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
183 + if (sbi->s_mb_prealloc_table == NULL) {
184 + kfree(sbi->s_mb_offsets);
185 + kfree(sbi->s_mb_maxs);
188 + memset(sbi->s_mb_prealloc_table, 0, i);
190 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe);
191 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 2);
192 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 4);
194 + sbi->s_mb_small_req = sbi->s_stripe;
195 + sbi->s_mb_large_req = sbi->s_stripe * 8;
196 + sbi->s_mb_group_prealloc = sbi->s_stripe * 4;
199 sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
200 if (sbi->s_locality_groups == NULL) {
201 + kfree(sbi->s_mb_prealloc_table);
202 kfree(sbi->s_mb_offsets);
203 kfree(sbi->s_mb_maxs);
205 @@ -2430,9 +2568,18 @@
206 spin_lock_init(&lg->lg_prealloc_lock);
211 + struct proc_dir_entry *p;
212 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
213 &ext4_mb_seq_groups_fops, sb);
214 + p = create_proc_entry(EXT4_MB_PREALLOC_TABLE, S_IFREG |
215 + S_IRUGO | S_IWUSR, sbi->s_proc);
218 + p->read_proc = ext4_mb_prealloc_table_proc_read;
219 + p->write_proc = ext4_mb_prealloc_table_proc_write;
224 sbi->s_journal->j_commit_callback = release_blocks_on_commit;
225 @@ -2512,8 +2659,10 @@
228 free_percpu(sbi->s_locality_groups);
231 remove_proc_entry("mb_groups", sbi->s_proc);
232 + remove_proc_entry(EXT4_MB_PREALLOC_TABLE, sbi->s_proc);
237 @@ -2807,11 +2956,12 @@
238 ext4_mb_normalize_request(struct ext4_allocation_context *ac,
239 struct ext4_allocation_request *ar)
242 + int bsbits, i, wind;
244 - loff_t size, orig_size, start_off;
245 + loff_t size, orig_size;
246 ext4_lblk_t start, orig_start;
247 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
248 + struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
249 struct ext4_prealloc_space *pa;
251 /* do normalize only data requests, metadata requests
252 @@ -2841,49 +2991,35 @@
253 size = size << bsbits;
254 if (size < i_size_read(ac->ac_inode))
255 size = i_size_read(ac->ac_inode);
256 + size = (size + ac->ac_sb->s_blocksize - 1) >> bsbits;
258 - /* max size of free chunks */
262 -#define NRL_CHECK_SIZE(req, size, max, chunk_size) \
263 - (req <= (size) || max <= (chunk_size))
264 + /* let's choose preallocation window depending on file size */
265 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
266 + if (size <= sbi->s_mb_prealloc_table[i]) {
267 + wind = sbi->s_mb_prealloc_table[i];
273 - /* first, try to predict filesize */
274 - /* XXX: should this table be tunable? */
276 - if (size <= 16 * 1024) {
278 - } else if (size <= 32 * 1024) {
280 - } else if (size <= 64 * 1024) {
282 - } else if (size <= 128 * 1024) {
284 - } else if (size <= 256 * 1024) {
286 - } else if (size <= 512 * 1024) {
288 - } else if (size <= 1024 * 1024) {
289 - size = 1024 * 1024;
290 - } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) {
291 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
292 - (21 - bsbits)) << 21;
293 - size = 2 * 1024 * 1024;
294 - } else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) {
295 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
296 - (22 - bsbits)) << 22;
297 - size = 4 * 1024 * 1024;
298 - } else if (NRL_CHECK_SIZE(ac->ac_o_ex.fe_len,
299 - (8<<20)>>bsbits, max, 8 * 1024)) {
300 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
301 - (23 - bsbits)) << 23;
302 - size = 8 * 1024 * 1024;
304 - start_off = (loff_t)ac->ac_o_ex.fe_logical << bsbits;
305 - size = ac->ac_o_ex.fe_len << bsbits;
307 + __u64 tstart, tend;
308 + /* file is quite large, we now preallocate with
309 + * the biggest configured window with regart to
310 + * logical offset */
311 + wind = sbi->s_mb_prealloc_table[i - 1];
312 + tstart = ac->ac_o_ex.fe_logical;
313 + do_div(tstart, wind);
314 + start = tstart * wind;
315 + tend = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len - 1;
316 + do_div(tend, wind);
317 + tend = tend * wind + wind;
318 + size = tend - start;
320 - orig_size = size = size >> bsbits;
321 - orig_start = start = start_off >> bsbits;
323 + orig_start = start;
325 /* don't cover already allocated blocks in selected range */
326 if (ar->pleft && start <= ar->lleft) {
327 @@ -2955,7 +3091,6 @@
329 BUG_ON(start + size <= ac->ac_o_ex.fe_logical &&
330 start > ac->ac_o_ex.fe_logical);
331 - BUG_ON(size <= 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb));
333 /* now prepare goal request */
335 @@ -3939,11 +4074,19 @@
337 /* don't use group allocation for large files */
338 size = max(size, isize);
339 - if (size > sbi->s_mb_stream_request) {
340 + if ((ac->ac_o_ex.fe_len >= sbi->s_mb_small_req) ||
341 + (size >= sbi->s_mb_large_req)) {
342 ac->ac_flags |= EXT4_MB_STREAM_ALLOC;
347 + * request is so large that we don't care about
348 + * streaming - it overweights any possible seek
350 + if (ac->ac_o_ex.fe_len >= sbi->s_mb_large_req)
353 BUG_ON(ac->ac_lg != NULL);
355 * locality group prealloc space are per cpu. The reason for having
356 Index: linux-stage/fs/ext4/super.c
357 ===================================================================
358 --- linux-stage.orig/fs/ext4/super.c 2011-03-11 14:16:56.000000000 +0800
359 +++ linux-stage/fs/ext4/super.c 2011-03-11 14:19:24.664467626 +0800
360 @@ -2632,7 +2632,8 @@
361 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
362 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
363 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
364 -EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
365 +EXT4_RW_ATTR_SBI_UI(mb_small_req, s_mb_small_req);
366 +EXT4_RW_ATTR_SBI_UI(mb_large_req, s_mb_large_req);
367 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
368 EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
370 @@ -2647,7 +2648,8 @@
371 ATTR_LIST(mb_max_to_scan),
372 ATTR_LIST(mb_min_to_scan),
373 ATTR_LIST(mb_order2_req),
374 - ATTR_LIST(mb_stream_req),
375 + ATTR_LIST(mb_small_req),
376 + ATTR_LIST(mb_large_req),
377 ATTR_LIST(mb_group_prealloc),
378 ATTR_LIST(max_writeback_mb_bump),