Skip to contentSkip to conversation

BIG_BG: block group descriptor modifications

RFC PATCH In review Valerie Clement 3 participants 4 messages Nov 24, 2006 – Nov 30, 2006 ext4 file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 4/4 BIG_BG: block group descriptor modifications

This patch adds the high 16 bits for the free block/inode counts and for the used directory count in the block group descriptor to support larger block groups.

 fs/ext4/balloc.c        |   22 +++++------
 fs/ext4/ialloc.c        |   89 ++++++++++++++++++++++++++++++------------------
 fs/ext4/resize.c        |    4 +-
 include/linux/ext4_fs.h |   28 +++++++++++++++
 4 files changed, 96 insertions(+), 47 deletions(-)
fs/ext4/balloc.c +10 -12
Index: linux-2.6.19-rc6/fs/ext4/balloc.c
===================================================================
@@ -623,9 +623,7 @@ do_more_bitmap:
 	}
 
 	spin_lock(sb_bgl_lock(sbi, block_group));
-	desc->bg_free_blocks_count =
-		cpu_to_le16(le16_to_cpu(desc->bg_free_blocks_count) +
-			group_freed);
+	EXT4_ADD_SPLIT_LE32(sb, desc->bg_free_blocks_count, group_freed);
 	spin_unlock(sb_bgl_lock(sbi, block_group));
 	percpu_counter_mod(&sbi->s_freeblocks_counter, count);
 
@@ -1525,7 +1523,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
 	struct ext4_sb_info *sbi;
 	struct ext4_reserve_window_node *my_rsv = NULL;
 	struct ext4_block_alloc_info *block_i;
-	unsigned short windowsz = 0;
+	unsigned long windowsz = 0;
 #ifdef EXT4FS_DEBUG
 	static int goal_hits, goal_attempts;
 #endif
@@ -1580,7 +1578,7 @@ retry_alloc:
 	if (!gdp)
 		goto io_error;
 
-	free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
+	free_blocks = EXT4_READ_SPLIT_LE32(sb, gdp->bg_free_blocks_count);
 	/*
 	 * if there is not enough free blocks to make a new resevation
 	 * turn off reservation for this allocation
@@ -1615,7 +1613,7 @@ retry_alloc:
 			*errp = -EIO;
 			goto out;
 		}
-		free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
+		free_blocks = EXT4_READ_SPLIT_LE32(sb, gdp->bg_free_blocks_count);
 		/*
 		 * skip this group if the number of
 		 * free blocks is less than half of the reservation
@@ -1654,7 +1652,8 @@ retry_alloc:
 allocated:
 
 	ext4_debug("using block group %d(%d)\n",
-			group_no, gdp->bg_free_blocks_count);
+			group_no,
+			EXT4_READ_SPLIT_LE32(sb, gdp->bg_free_blocks_count));
 
 	BUFFER_TRACE(gdp_bh, "get_write_access");
 	fatal = ext4_journal_get_write_access(handle, gdp_bh);
@@ -1712,8 +1711,7 @@ allocated:
 			ret_block, goal_hits, goal_attempts);
 
 	spin_lock(sb_bgl_lock(sbi, group_no));
-	gdp->bg_free_blocks_count =
-			cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num);
+	EXT4_SUB_SPLIT_LE32(sb, gdp->bg_free_blocks_count, num);
 	spin_unlock(sb_bgl_lock(sbi, group_no));
 	percpu_counter_mod(&sbi->s_freeblocks_counter, -num);
 
@@ -1782,7 +1780,7 @@ ext4_fsblk_t ext4_count_free_blocks(stru
 		gdp = ext4_get_group_desc(sb, i, NULL);
 		if (!gdp)
 			continue;
-		desc_count += le16_to_cpu(gdp->bg_free_blocks_count);
+		desc_count += EXT4_READ_SPLIT_LE32(sb, gdp->bg_free_blocks_count);
 		for (j = 0, x = 0;
 		     j < (EXT4_BLOCKS_PER_GROUP(sb) >> EXT4_BITS_PER_BLOCK_BITS(sb));
 		     j++) {
@@ -1793,7 +1791,7 @@ ext4_fsblk_t ext4_count_free_blocks(stru
 			x += ext4_count_free(bitmap_bh, sb->s_blocksize);
 		}
 		printk("group %d: stored = %d, counted = %lu\n",
-			i, le16_to_cpu(gdp->bg_free_blocks_count), x);
+			i, EXT4_READ_SPLIT_LE32(sb, gdp->bg_free_blocks_count), x);
 		bitmap_count += x;
 	}
 	brelse(bitmap_bh);
@@ -1809,7 +1807,7 @@ ext4_fsblk_t ext4_count_free_blocks(stru
 		gdp = ext4_get_group_desc(sb, i, NULL);
 		if (!gdp)
 			continue;
-		desc_count += le16_to_cpu(gdp->bg_free_blocks_count);
+		desc_count += EXT4_READ_SPLIT_LE32(sb, gdp->bg_free_blocks_count);
 	}
 
 	return desc_count;
fs/ext4/ialloc.c +56 -33

190 lines not on this page · raw message

include/linux/ext4_fs.h +28 -0
Index: linux-2.6.19-rc6/include/linux/ext4_fs.h
===================================================================
@@ -133,6 +133,9 @@ struct ext4_group_desc
 	__le32	bg_block_bitmap_hi;	/* Blocks bitmap block MSB */
 	__le32	bg_inode_bitmap_hi;	/* Inodes bitmap block MSB */
 	__le32	bg_inode_table_hi;	/* Inodes table block MSB */
+	__le16	bg_free_blocks_count_hi;	/* Free blocks count MSB */
+	__le16	bg_free_inodes_count_hi;	/* Free inodes count MSB */
+	__le16	bg_used_dirs_count_hi;	/* Directories count MSB */
 };
 
 #ifdef __KERNEL__
@@ -163,6 +166,31 @@ struct ext4_group_desc
 # define EXT4_INODES_PER_GROUP(s)	((s)->s_inodes_per_group)
 #endif
 
+#define EXT4_READ_SPLIT_LE32(__sb, __field)	\
+	((__u32)le16_to_cpu(__field) +		\
+	 (EXT4_HAS_INCOMPAT_FEATURE((__sb), EXT4_FEATURE_INCOMPAT_64BIT) ? \
+	 (__u32)le16_to_cpu(__field##_hi) << 16 : 0))
+
+#define EXT4_WRITE_SPLIT_LE32(__sb, __field,__value)	\
+do { \
+	__u32 __tmp = __value; \
+	__field = cpu_to_le16((__tmp) & 0xFFFF);	\
+	if (EXT4_HAS_INCOMPAT_FEATURE((__sb), EXT4_FEATURE_INCOMPAT_64BIT)) \
+		__field##_hi = cpu_to_le16((__u32)(__tmp) >> 16); \
+} while(0)
+
+#define EXT4_ADD_SPLIT_LE32(__sb, __field,__value)	\
+	EXT4_WRITE_SPLIT_LE32(__sb, __field,		\
+			EXT4_READ_SPLIT_LE32(__sb, __field) + (__u32)__value)
+
+#define EXT4_SUB_SPLIT_LE32(__sb, __field,__value)	\
+	EXT4_WRITE_SPLIT_LE32(__sb, __field,		\
+			EXT4_READ_SPLIT_LE32(__sb, __field) - (__u32)__value)
+
+#define EXT4_DEC_SPLIT_LE32(__sb, __field) EXT4_SUB_SPLIT_LE32(__sb, __field,1)
+
+#define EXT4_INC_SPLIT_LE32(__sb, __field) EXT4_ADD_SPLIT_LE32(__sb, __field,1)
+
 /*
  * Constants relative to the data blocks
  */
fs/ext4/resize.c +2 -2
Index: linux-2.6.19-rc6/fs/ext4/resize.c
===================================================================
@@ -842,8 +842,8 @@ int ext4_group_add(struct super_block *s
 	ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */
 	ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */
 	ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */
-	gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count);
-	gdp->bg_free_inodes_count = cpu_to_le16(EXT4_INODES_PER_GROUP(sb));
+	EXT4_WRITE_SPLIT_LE32(sb, gdp->bg_free_blocks_count, input->free_blocks_count);
+	EXT4_WRITE_SPLIT_LE32(sb, gdp->bg_free_inodes_count, EXT4_INODES_PER_GROUP(sb));
 
 	/*
 	 * Make the new blocks and inodes valid next.  We do this before
#1 lore raw

include/linux/ext4_fs.h struct ext4_group_desc · line 139

Quoted 8 lines · Valerie Clement
include/linux/ext4_fs.h +3 -0
@@ -133,6 +133,9 @@ struct ext4_group_desc
 	__le32	bg_block_bitmap_hi;	/* Blocks bitmap block MSB */
 	__le32	bg_inode_bitmap_hi;	/* Inodes bitmap block MSB */
 	__le32	bg_inode_table_hi;	/* Inodes table block MSB */
+	__le16	bg_free_blocks_count_hi;	/* Free blocks count MSB */
+	__le16	bg_free_inodes_count_hi;	/* Free inodes count MSB */
+	__le16	bg_used_dirs_count_hi;	/* Directories count MSB */
 };

Does the ext4 code already avoid using "sizeof(struct ext4_group_desc)" or "sizeof(*gdp)" everywhere? Otherwise this is very dangerous.

Also note that the on-disk layout of this struct in e2fsprogs is a bit incorrect - it has the above 3 __u16, but then immediately __u32 bg_reserved so those fields are padded incorrectly. I think it isn't a fatal problem, just something to be aware of and fix.

include/linux/ext4_fs.h struct ext4_group_desc · line 172

Quoted 4 lines
include/linux/ext4_fs.h +4 -0
+#define EXT4_READ_SPLIT_LE32(__sb, __field)	\
+	((__u32)le16_to_cpu(__field) +		\
+	 (EXT4_HAS_INCOMPAT_FEATURE((__sb), EXT4_FEATURE_INCOMPAT_64BIT) ? \
+	 (__u32)le16_to_cpu(__field##_hi) << 16 : 0))

Is it better to make this INCOMPAT_64BIT or s_desc_size? Does INCOMPAT_64BIT always imply s_desc_size > 32? Hmm, I guess it does, or we have no place to store the _hi part of the block addresses for a group.

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.

#2 lore raw
Quoted 12 lines · Andreas Dilger

include/linux/ext4_fs.h struct ext4_group_desc · line 139

Quoted 8 lines · Valerie Clement
include/linux/ext4_fs.h +3 -0
@@ -133,6 +133,9 @@ struct ext4_group_desc
 	__le32	bg_block_bitmap_hi;	/* Blocks bitmap block MSB */
 	__le32	bg_inode_bitmap_hi;	/* Inodes bitmap block MSB */
 	__le32	bg_inode_table_hi;	/* Inodes table block MSB */
+	__le16	bg_free_blocks_count_hi;	/* Free blocks count MSB */
+	__le16	bg_free_inodes_count_hi;	/* Free inodes count MSB */
+	__le16	bg_used_dirs_count_hi;	/* Directories count MSB */
 };

Does the ext4 code already avoid using "sizeof(struct ext4_group_desc)" or "sizeof(*gdp)" everywhere? Otherwise this is very dangerous.

Currently, the code doesn't use sizeof of the structure or of a group descriptor, but do you mean that adding padding to the structure is better?

Quoted 5 lines

Also note that the on-disk layout of this struct in e2fsprogs is a bit incorrect - it has the above 3 __u16, but then immediately __u32 bg_reserved so those fields are padded incorrectly. I think it isn't a fatal problem, just something to be aware of and fix.

OK.

Quoted 9 lines

include/linux/ext4_fs.h struct ext4_group_desc · line 172

Quoted 5 lines
include/linux/ext4_fs.h +4 -0
+#define EXT4_READ_SPLIT_LE32(__sb, __field)	\
+	((__u32)le16_to_cpu(__field) +		\
+	 (EXT4_HAS_INCOMPAT_FEATURE((__sb), EXT4_FEATURE_INCOMPAT_64BIT) ? \
+	 (__u32)le16_to_cpu(__field##_hi) << 16 : 0))

Is it better to make this INCOMPAT_64BIT or s_desc_size? Does INCOMPAT_64BIT always imply s_desc_size > 32? Hmm, I guess it does, or we have no place to store the _hi part of the block addresses for a group.

I prefer using INCOMPAT_64BIT rather than s_desc_size.
Thank you Andreas to point that out, I missed to update my e2fsprogs version to initialize s_desc_size with the right value in some cases.

Valérie

maintainer
#3 lore raw
In reply to Andreas Dilger
Quoted 4 lines · Andreas Dilger

Also note that the on-disk layout of this struct in e2fsprogs is a bit incorrect - it has the above 3 __u16, but then immediately __u32 bg_reserved so those fields are padded incorrectly. I think it isn't a fatal problem, just something to be aware of and fix.

Thanks for pointing this out; I've fixed this in Mercurial repository for e2fsprogs.

- Ted