diff mbox series

[RFCv1,18/72] libext2fs: Add support to get average group count

Message ID 7e4f563719aee1970dd1058ca45b0609ae4c7c5f.1667822611.git.ritesh.list@gmail.com
State Under Review
Delegated to: Theodore Ts'o
Headers show
Series e2fsprogs: Parallel fsck support | expand

Commit Message

Ritesh Harjani (IBM) Nov. 7, 2022, 12:21 p.m. UTC
From: Wang Shilong <wshilong@ddn.com>

number of threads in pfsck should not exceed flex bg numbers.
This patch adds the support in libext2fs to calculate
ext2fs_get_avg_group() which returns an average group
count which each thread has to scan.

fs->fs_num_threads will be set by the client, in this case e2fsck.
No. of threads will be passed along with -m option while running e2fsck.
That will also set fs->fs_num_threads, which will help in controlling
the amount of memory consumed to maintain in memory data structures (per
thread) in case of multiple parallel threads (pfsck) to avoid oom.

Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
 lib/ext2fs/ext2fs.h | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

Comments

Andreas Dilger Dec. 14, 2022, 9:24 p.m. UTC | #1
On Nov 7, 2022, at 5:21 AM, Ritesh Harjani (IBM) <ritesh.list@gmail.com> wrote:
> 
> From: Wang Shilong <wshilong@ddn.com>
> 
> number of threads in pfsck should not exceed flex bg numbers.
> This patch adds the support in libext2fs to calculate
> ext2fs_get_avg_group() which returns an average group
> count which each thread has to scan.
> 
> fs->fs_num_threads will be set by the client, in this case e2fsck.
> No. of threads will be passed along with -m option while running e2fsck.
> That will also set fs->fs_num_threads, which will help in controlling
> the amount of memory consumed to maintain in memory data structures (per
> thread) in case of multiple parallel threads (pfsck) to avoid oom.
> 
> Signed-off-by: Wang Shilong <wshilong@ddn.com>
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> ---
> lib/ext2fs/ext2fs.h | 32 +++++++++++++++++++++++++++++++-
> 1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
> index b1505f95..6b4926ce 100644
> --- a/lib/ext2fs/ext2fs.h
> +++ b/lib/ext2fs/ext2fs.h
> @@ -279,10 +279,11 @@ struct struct_ext2_filsys {
> 	int				cluster_ratio_bits;
> 	__u16				default_bitmap_type;
> 	__u16				pad;
> +	__u32				fs_num_threads;

From later cleanup patch, fs_num_threads should just use "__u16 pad" field.

Otherwise, looks OK.


> 	/*
> 	 * Reserved for future expansion
> 	 */
> -	__u32				reserved[5];
> +	__u32				reserved[4];
> 
> 	/*
> 	 * Reserved for the use of the calling application.
> @@ -2231,6 +2232,35 @@ ext2fs_orphan_block_tail(ext2_filsys fs, char *buf)
> 		sizeof(struct ext4_orphan_block_tail));
> }
> 
> +static dgrp_t ext2fs_get_avg_group(ext2_filsys fs)
> +{
> +#ifdef HAVE_PTHREAD
> +	dgrp_t average_group;
> +	unsigned flexbg_size;
> +
> +	if (fs->fs_num_threads <= 1)
> +		return fs->group_desc_count;
> +
> +	average_group = fs->group_desc_count / fs->fs_num_threads;
> +	if (average_group <= 1)
> +		return 1;
> +
> +	if (ext2fs_has_feature_flex_bg(fs->super)) {
> +		int times = 1;
> +
> +		flexbg_size = 1 << fs->super->s_log_groups_per_flex;
> +		if (average_group % flexbg_size) {
> +			times = average_group / flexbg_size;
> +			average_group = times * flexbg_size;
> +		}
> +	}
> +
> +	return average_group;
> +#else
> +	return fs->group_desc_count;
> +#endif
> +}
> +
> #undef _INLINE_
> #endif
> 
> --
> 2.37.3
> 


Cheers, Andreas
diff mbox series

Patch

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index b1505f95..6b4926ce 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -279,10 +279,11 @@  struct struct_ext2_filsys {
 	int				cluster_ratio_bits;
 	__u16				default_bitmap_type;
 	__u16				pad;
+	__u32				fs_num_threads;
 	/*
 	 * Reserved for future expansion
 	 */
-	__u32				reserved[5];
+	__u32				reserved[4];
 
 	/*
 	 * Reserved for the use of the calling application.
@@ -2231,6 +2232,35 @@  ext2fs_orphan_block_tail(ext2_filsys fs, char *buf)
 		sizeof(struct ext4_orphan_block_tail));
 }
 
+static dgrp_t ext2fs_get_avg_group(ext2_filsys fs)
+{
+#ifdef HAVE_PTHREAD
+	dgrp_t average_group;
+	unsigned flexbg_size;
+
+	if (fs->fs_num_threads <= 1)
+		return fs->group_desc_count;
+
+	average_group = fs->group_desc_count / fs->fs_num_threads;
+	if (average_group <= 1)
+		return 1;
+
+	if (ext2fs_has_feature_flex_bg(fs->super)) {
+		int times = 1;
+
+		flexbg_size = 1 << fs->super->s_log_groups_per_flex;
+		if (average_group % flexbg_size) {
+			times = average_group / flexbg_size;
+			average_group = times * flexbg_size;
+		}
+	}
+
+	return average_group;
+#else
+	return fs->group_desc_count;
+#endif
+}
+
 #undef _INLINE_
 #endif