altalloc patch (you know, faster fsck) for 2.3.8

Pavel Machek (pavel@bug.ucw.cz)
Sat, 26 Jun 1999 22:45:23 +0200


Hi!

Here it is. I did not even tried to boot that kernel, and given that
2.3.8 is known corrupter with ld I'm not sure I want to boot
that. Patch schould work.

Pavel
PS: More info should appear on http://www.suse.cz/development... Soon.

--- clean/include/linux/ext2_fs.h Sat Jun 26 22:37:33 1999
+++ linux/include/linux/ext2_fs.h Sat Jun 26 22:20:05 1999
@@ -310,6 +310,7 @@
#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
+#define EXT2_MOUNT_ALTALLOC 0x0100 /* Alloc indirect blocks close to each other */

#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
--- clean/include/linux/ext2_fs_i.h Fri May 14 20:42:46 1999
+++ linux/include/linux/ext2_fs_i.h Wed Jun 9 00:14:59 1999
@@ -37,6 +37,8 @@
__u32 i_prealloc_count;
__u32 i_high_size;
int i_new_inode:1; /* Is a freshly allocated inode */
+ int i_alloc_elsewhere:1;
+ __u32 i_elsewhere_goal;
};

#endif /* _LINUX_EXT2_FS_I */
--- clean/fs/ext2/inode.c Sat Jun 26 22:37:27 1999
+++ linux/fs/ext2/inode.c Sat Jun 26 22:27:17 1999
@@ -103,6 +103,21 @@
wait_on_super (inode->i_sb);

#ifdef EXT2_PREALLOCATE
+ if (inode->u.ext2_i.i_alloc_elsewhere) {
+ if (!inode->u.ext2_i.i_elsewhere_goal) {
+ goal = (inode->u.ext2_i.i_block_group *
+ EXT2_BLOCKS_PER_GROUP(inode->i_sb)) +
+ le32_to_cpu(inode->i_sb->u.ext2_sb.s_es->s_first_data_block);
+ if (goal > 512)
+ goal -= 512;
+ } else goal = inode->u.ext2_i.i_elsewhere_goal;
+// printk( "Allocating goal = %d, ", goal );
+ result = ext2_new_block (inode, goal, 0, 0, err);
+ inode->u.ext2_i.i_elsewhere_goal = result;
+// printk( "got = %d\n", result );
+ return result;
+ }
+
if (inode->u.ext2_i.i_prealloc_count &&
(goal == inode->u.ext2_i.i_prealloc_block ||
goal + 1 == inode->u.ext2_i.i_prealloc_block))
@@ -311,8 +326,8 @@
}

ext2_debug ("goal = %d.\n", goal);
-
tmp = ext2_alloc_block (inode, goal, err);
+
if (!tmp)
return NULL;
if (metadata) {
@@ -337,8 +352,11 @@
}
*p = cpu_to_le32(tmp);

- inode->u.ext2_i.i_next_alloc_block = new_block;
- inode->u.ext2_i.i_next_alloc_goal = tmp;
+ if (!inode->u.ext2_i.i_alloc_elsewhere) {
+ inode->u.ext2_i.i_next_alloc_block = new_block;
+ inode->u.ext2_i.i_next_alloc_goal = tmp;
+ }
+
inode->i_ctime = CURRENT_TIME;
inode->i_blocks += blocks;
if (IS_SYNC(inode) || inode->u.ext2_i.i_osync)
@@ -457,8 +475,10 @@
inode->i_ctime = CURRENT_TIME;
inode->i_blocks += blocks;
mark_inode_dirty(inode);
- inode->u.ext2_i.i_next_alloc_block = new_block;
- inode->u.ext2_i.i_next_alloc_goal = tmp;
+ if (!inode->u.ext2_i.i_alloc_elsewhere) {
+ inode->u.ext2_i.i_next_alloc_block = new_block;
+ inode->u.ext2_i.i_next_alloc_goal = tmp;
+ }
brelse (bh);
return result;
}
@@ -511,9 +531,12 @@
err, 0, &phys_block, created);
goto out;
}
+ if (test_opt(inode->i_sb, ALTALLOC))
+ inode->u.ext2_i.i_alloc_elsewhere = 1;
block -= EXT2_NDIR_BLOCKS;
if (block < addr_per_block) {
bh = inode_getblk (inode, EXT2_IND_BLOCK, create, b, err, 1, NULL, NULL);
+ inode->u.ext2_i.i_alloc_elsewhere = 0;
tmp = block_getblk (inode, bh, block, create,
inode->i_sb->s_blocksize, b, err, 0, &phys_block, created);
goto out;
@@ -523,6 +546,7 @@
bh = inode_getblk (inode, EXT2_DIND_BLOCK, create, b, err, 1, NULL, NULL);
bh = block_getblk (inode, bh, block >> addr_per_block_bits,
create, inode->i_sb->s_blocksize, b, err, 1, NULL, NULL);
+ inode->u.ext2_i.i_alloc_elsewhere = 0;
tmp = block_getblk (inode, bh, block & (addr_per_block - 1),
create, inode->i_sb->s_blocksize, b, err, 0, &phys_block, created);
goto out;
@@ -534,6 +558,7 @@
bh = block_getblk (inode, bh, (block >> addr_per_block_bits) &
(addr_per_block - 1), create, inode->i_sb->s_blocksize,
b, err, 1, NULL,NULL);
+ inode->u.ext2_i.i_alloc_elsewhere = 0;
tmp = block_getblk (inode, bh, block & (addr_per_block - 1), create,
inode->i_sb->s_blocksize, b, err, 0, &phys_block, created);

@@ -684,6 +709,8 @@
inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
inode->i_version = ++event;
inode->u.ext2_i.i_new_inode = 0;
+ inode->u.ext2_i.i_alloc_elsewhere = 0;
+ inode->u.ext2_i.i_elsewhere_goal = 0;
inode->u.ext2_i.i_flags = le32_to_cpu(raw_inode->i_flags);
inode->u.ext2_i.i_faddr = le32_to_cpu(raw_inode->i_faddr);
inode->u.ext2_i.i_frag_no = raw_inode->i_frag;
--- clean/fs/ext2/super.c Tue Jun 15 11:25:38 1999
+++ linux/fs/ext2/super.c Sun Jun 20 00:10:44 1999
@@ -181,6 +181,8 @@
}
else if (!strcmp (this_char, "debug"))
set_opt (*mount_options, DEBUG);
+ else if (!strcmp (this_char, "altalloc"))
+ set_opt (*mount_options, ALTALLOC);
else if (!strcmp (this_char, "errors")) {
if (!value || !*value) {
printk ("EXT2-fs: the errors option requires "

-- 
I'm really pavel@ucw.cz. Look at http://195.113.31.123/~pavel.  Pavel
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/