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/mballoc.c
22 ===================================================================
23 --- linux-stage.orig/fs/ext4/mballoc.c 2011-03-11 14:03:32.000000000 +0800
24 +++ linux-stage/fs/ext4/mballoc.c 2011-03-11 14:44:49.106543493 +0800
25 @@ -1823,6 +1823,26 @@
29 +static void ext4_mb_prealloc_table_add(struct ext4_sb_info *sbi, int value)
33 + if (value > (sbi->s_blocks_per_group - 1 - 1 - sbi->s_itb_per_group))
36 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
37 + if (sbi->s_mb_prealloc_table[i] == 0) {
38 + sbi->s_mb_prealloc_table[i] = value;
42 + /* they should add values in order */
43 + if (value <= sbi->s_mb_prealloc_table[i])
49 static int ext4_mb_good_group(struct ext4_allocation_context *ac,
50 ext4_group_t group, int cr)
52 @@ -2173,6 +2193,80 @@
53 .show = ext4_mb_seq_groups_show,
56 +#define EXT4_MB_PREALLOC_TABLE "prealloc_table"
58 +static int ext4_mb_prealloc_table_proc_read(char *page, char **start, off_t off,
59 + int count, int *eof, void *data)
61 + struct ext4_sb_info *sbi = data;
69 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++)
70 + len += sprintf(page + len, "%ld ",
71 + sbi->s_mb_prealloc_table[i]);
72 + len += sprintf(page + len, "\n");
78 +static int ext4_mb_prealloc_table_proc_write(struct file *file,
79 + const char __user *buf,
80 + unsigned long cnt, void *data)
82 + struct ext4_sb_info *sbi = data;
83 + unsigned long value;
84 + unsigned long prev = 0;
88 + unsigned long *new_table;
92 + if (cnt >= sizeof(str))
94 + if (copy_from_user(str, buf, cnt))
100 + while (cur < end) {
101 + while ((cur < end) && (*cur == ' ')) cur++;
102 + value = simple_strtol(cur, &cur, 0);
111 + new_table = kmalloc(num * sizeof(*new_table), GFP_KERNEL);
112 + if (new_table == NULL)
114 + kfree(sbi->s_mb_prealloc_table);
115 + memset(new_table, 0, num * sizeof(*new_table));
116 + sbi->s_mb_prealloc_table = new_table;
117 + sbi->s_mb_prealloc_table_size = num;
120 + while (cur < end && i < num) {
121 + while ((cur < end) && (*cur == ' ')) cur++;
122 + value = simple_strtol(cur, &cur, 0);
123 + ext4_mb_prealloc_table_add(sbi, value);
130 static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
132 struct super_block *sb = PDE(inode)->data;
133 @@ -2411,12 +2505,56 @@
134 sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
135 sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
136 sbi->s_mb_stats = MB_DEFAULT_STATS;
137 - sbi->s_mb_stream_request = MB_DEFAULT_STREAM_THRESHOLD;
138 sbi->s_mb_order2_reqs = MB_DEFAULT_ORDER2_REQS;
139 - sbi->s_mb_group_prealloc = MB_DEFAULT_GROUP_PREALLOC;
141 + if (sbi->s_stripe == 0) {
142 + sbi->s_mb_prealloc_table_size = 10;
143 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
144 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
145 + if (sbi->s_mb_prealloc_table == NULL) {
146 + kfree(sbi->s_mb_offsets);
147 + kfree(sbi->s_mb_maxs);
150 + memset(sbi->s_mb_prealloc_table, 0, i);
152 + ext4_mb_prealloc_table_add(sbi, 4);
153 + ext4_mb_prealloc_table_add(sbi, 8);
154 + ext4_mb_prealloc_table_add(sbi, 16);
155 + ext4_mb_prealloc_table_add(sbi, 32);
156 + ext4_mb_prealloc_table_add(sbi, 64);
157 + ext4_mb_prealloc_table_add(sbi, 128);
158 + ext4_mb_prealloc_table_add(sbi, 256);
159 + ext4_mb_prealloc_table_add(sbi, 512);
160 + ext4_mb_prealloc_table_add(sbi, 1024);
161 + ext4_mb_prealloc_table_add(sbi, 2048);
163 + sbi->s_mb_small_req = 256;
164 + sbi->s_mb_large_req = 1024;
165 + sbi->s_mb_group_prealloc = 512;
167 + sbi->s_mb_prealloc_table_size = 3;
168 + i = sbi->s_mb_prealloc_table_size * sizeof(unsigned long);
169 + sbi->s_mb_prealloc_table = kmalloc(i, GFP_NOFS);
170 + if (sbi->s_mb_prealloc_table == NULL) {
171 + kfree(sbi->s_mb_offsets);
172 + kfree(sbi->s_mb_maxs);
175 + memset(sbi->s_mb_prealloc_table, 0, i);
177 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe);
178 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 2);
179 + ext4_mb_prealloc_table_add(sbi, sbi->s_stripe * 4);
181 + sbi->s_mb_small_req = sbi->s_stripe;
182 + sbi->s_mb_large_req = sbi->s_stripe * 8;
183 + sbi->s_mb_group_prealloc = sbi->s_stripe * 4;
186 sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
187 if (sbi->s_locality_groups == NULL) {
188 + kfree(sbi->s_mb_prealloc_table);
189 kfree(sbi->s_mb_offsets);
190 kfree(sbi->s_mb_maxs);
192 @@ -2430,9 +2568,18 @@
193 spin_lock_init(&lg->lg_prealloc_lock);
198 + struct proc_dir_entry *p;
199 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
200 &ext4_mb_seq_groups_fops, sb);
201 + p = create_proc_entry(EXT4_MB_PREALLOC_TABLE, S_IFREG |
202 + S_IRUGO | S_IWUSR, sbi->s_proc);
205 + p->read_proc = ext4_mb_prealloc_table_proc_read;
206 + p->write_proc = ext4_mb_prealloc_table_proc_write;
211 sbi->s_journal->j_commit_callback = release_blocks_on_commit;
212 @@ -2512,8 +2659,10 @@
215 free_percpu(sbi->s_locality_groups);
218 remove_proc_entry("mb_groups", sbi->s_proc);
219 + remove_proc_entry(EXT4_MB_PREALLOC_TABLE, sbi->s_proc);
224 @@ -2807,11 +2956,12 @@
225 ext4_mb_normalize_request(struct ext4_allocation_context *ac,
226 struct ext4_allocation_request *ar)
229 + int bsbits, i, wind;
231 - loff_t size, orig_size, start_off;
232 + loff_t size, orig_size;
233 ext4_lblk_t start, orig_start;
234 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
235 + struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
236 struct ext4_prealloc_space *pa;
238 /* do normalize only data requests, metadata requests
239 @@ -2841,49 +2991,35 @@
240 size = size << bsbits;
241 if (size < i_size_read(ac->ac_inode))
242 size = i_size_read(ac->ac_inode);
243 + size = (size + ac->ac_sb->s_blocksize - 1) >> bsbits;
245 - /* max size of free chunks */
249 -#define NRL_CHECK_SIZE(req, size, max, chunk_size) \
250 - (req <= (size) || max <= (chunk_size))
251 + /* let's choose preallocation window depending on file size */
252 + for (i = 0; i < sbi->s_mb_prealloc_table_size; i++) {
253 + if (size <= sbi->s_mb_prealloc_table[i]) {
254 + wind = sbi->s_mb_prealloc_table[i];
260 - /* first, try to predict filesize */
261 - /* XXX: should this table be tunable? */
263 - if (size <= 16 * 1024) {
265 - } else if (size <= 32 * 1024) {
267 - } else if (size <= 64 * 1024) {
269 - } else if (size <= 128 * 1024) {
271 - } else if (size <= 256 * 1024) {
273 - } else if (size <= 512 * 1024) {
275 - } else if (size <= 1024 * 1024) {
276 - size = 1024 * 1024;
277 - } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) {
278 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
279 - (21 - bsbits)) << 21;
280 - size = 2 * 1024 * 1024;
281 - } else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) {
282 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
283 - (22 - bsbits)) << 22;
284 - size = 4 * 1024 * 1024;
285 - } else if (NRL_CHECK_SIZE(ac->ac_o_ex.fe_len,
286 - (8<<20)>>bsbits, max, 8 * 1024)) {
287 - start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
288 - (23 - bsbits)) << 23;
289 - size = 8 * 1024 * 1024;
291 - start_off = (loff_t)ac->ac_o_ex.fe_logical << bsbits;
292 - size = ac->ac_o_ex.fe_len << bsbits;
294 + __u64 tstart, tend;
295 + /* file is quite large, we now preallocate with
296 + * the biggest configured window with regart to
297 + * logical offset */
298 + wind = sbi->s_mb_prealloc_table[i - 1];
299 + tstart = ac->ac_o_ex.fe_logical;
300 + do_div(tstart, wind);
301 + start = tstart * wind;
302 + tend = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len - 1;
303 + do_div(tend, wind);
304 + tend = tend * wind + wind;
305 + size = tend - start;
307 - orig_size = size = size >> bsbits;
308 - orig_start = start = start_off >> bsbits;
310 + orig_start = start;
312 /* don't cover already allocated blocks in selected range */
313 if (ar->pleft && start <= ar->lleft) {
314 @@ -2955,7 +3091,6 @@
316 BUG_ON(start + size <= ac->ac_o_ex.fe_logical &&
317 start > ac->ac_o_ex.fe_logical);
318 - BUG_ON(size <= 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb));
320 /* now prepare goal request */
322 @@ -3939,11 +4074,19 @@
324 /* don't use group allocation for large files */
325 size = max(size, isize);
326 - if (size > sbi->s_mb_stream_request) {
327 + if ((ac->ac_o_ex.fe_len >= sbi->s_mb_small_req) ||
328 + (size >= sbi->s_mb_large_req)) {
329 ac->ac_flags |= EXT4_MB_STREAM_ALLOC;
334 + * request is so large that we don't care about
335 + * streaming - it overweights any possible seek
337 + if (ac->ac_o_ex.fe_len >= sbi->s_mb_large_req)
340 BUG_ON(ac->ac_lg != NULL);
342 * locality group prealloc space are per cpu. The reason for having
343 Index: linux-stage/fs/ext4/super.c
344 ===================================================================
345 --- linux-stage.orig/fs/ext4/super.c 2011-03-11 14:16:56.000000000 +0800
346 +++ linux-stage/fs/ext4/super.c 2011-03-11 14:19:24.664467626 +0800
347 @@ -2632,7 +2632,8 @@
348 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
349 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
350 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
351 -EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
352 +EXT4_RW_ATTR_SBI_UI(mb_small_req, s_mb_small_req);
353 +EXT4_RW_ATTR_SBI_UI(mb_large_req, s_mb_large_req);
354 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
355 EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
357 @@ -2647,7 +2648,8 @@
358 ATTR_LIST(mb_max_to_scan),
359 ATTR_LIST(mb_min_to_scan),
360 ATTR_LIST(mb_order2_req),
361 - ATTR_LIST(mb_stream_req),
362 + ATTR_LIST(mb_small_req),
363 + ATTR_LIST(mb_large_req),
364 ATTR_LIST(mb_group_prealloc),
365 ATTR_LIST(max_writeback_mb_bump),