lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 19 Jun 2020 00:27:51 +0900
From:   Wang Shilong <wangshilong1991@...il.com>
To:     linux-ext4@...r.kernel.org
Cc:     lixi@....com, adilger@...ger.ca, wangshilong1991@...il.com,
        sihara@....com, Wang Shilong <wshilong@....com>
Subject: [RFC PATCH v2 48/51] e2fsck: only setup threads if -m option required

From: Wang Shilong <wshilong@....com>

For smaller fs(less than TiB filesystem), it doesn't
make sense to setup threads, and default behavior will
be kept as single threads.

Signed-off-by: Wang Shilong <wshilong@....com>
---
 e2fsck/pass1.c | 60 +++++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 45e8090b..969475b4 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -1293,6 +1293,27 @@ static void e2fsck_pass1_set_thread_num(e2fsck_t ctx)
 	ctx->fs_num_threads = num_threads;
 }
 
+static void init_ext2_max_sizes()
+{
+	int	i;
+	__u64	max_sizes;
+
+	/*
+	 * Init ext2_max_sizes which will be immutable and shared between
+	 * threads
+	 */
+#define EXT2_BPP(bits) (1ULL << ((bits) - 2))
+
+	for (i = EXT2_MIN_BLOCK_LOG_SIZE; i <= EXT2_MAX_BLOCK_LOG_SIZE; i++) {
+		max_sizes = EXT2_NDIR_BLOCKS + EXT2_BPP(i);
+		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i);
+		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i) * EXT2_BPP(i);
+		max_sizes = (max_sizes * (1UL << i));
+		ext2_max_sizes[i - EXT2_MIN_BLOCK_LOG_SIZE] = max_sizes;
+	}
+#undef EXT2_BPP
+}
+
 /*
  * We need call mark_table_blocks() before multiple
  * thread start, since all known system blocks should be
@@ -1304,6 +1325,7 @@ static int _e2fsck_pass1_prepare(e2fsck_t ctx)
 	ext2_filsys fs = ctx->fs;
 	unsigned long long readahead_kb;
 
+	init_ext2_max_sizes();
 	e2fsck_pass1_set_thread_num(ctx);
 	/* If we can do readahead, figure out how many groups to pull in. */
 	if (!e2fsck_can_readahead(ctx->fs))
@@ -1944,6 +1966,10 @@ void _e2fsck_pass1(e2fsck_t ctx)
 
 		if (ino == EXT2_BAD_INO) {
 			struct process_block_struct pb;
+			e2fsck_t global_ctx = ctx;
+
+			if (ctx->global_ctx)
+				global_ctx = ctx->global_ctx;
 
 			if ((failed_csum || inode->i_mode || inode->i_uid ||
 			     inode->i_gid || inode->i_links_count ||
@@ -1959,7 +1985,7 @@ void _e2fsck_pass1(e2fsck_t ctx)
 			}
 
 			e2fsck_pass1_block_map_r_lock(ctx);
-			pctx.errcode = ext2fs_copy_bitmap(ctx->global_ctx->block_found_map,
+			pctx.errcode = ext2fs_copy_bitmap(global_ctx->block_found_map,
 							  &pb.fs_meta_blocks);
 			e2fsck_pass1_block_map_r_unlock(ctx);
 			if (pctx.errcode) {
@@ -3297,39 +3323,13 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
 	return 0;
 }
 
-static void init_ext2_max_sizes()
-{
-	int	i;
-	__u64	max_sizes;
-
-	/*
-	 * Init ext2_max_sizes which will be immutable and shared between
-	 * threads
-	 */
-#define EXT2_BPP(bits) (1ULL << ((bits) - 2))
-
-	for (i = EXT2_MIN_BLOCK_LOG_SIZE; i <= EXT2_MAX_BLOCK_LOG_SIZE; i++) {
-		max_sizes = EXT2_NDIR_BLOCKS + EXT2_BPP(i);
-		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i);
-		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i) * EXT2_BPP(i);
-		max_sizes = (max_sizes * (1UL << i));
-		ext2_max_sizes[i - EXT2_MIN_BLOCK_LOG_SIZE] = max_sizes;
-	}
-#undef EXT2_BPP
-}
-
 static void e2fsck_pass1_multithread(e2fsck_t global_ctx)
 {
 	struct e2fsck_thread_info	*infos = NULL;
 	errcode_t			 retval;
 
-	retval = _e2fsck_pass1_prepare(global_ctx);
-	if (retval)
-		goto out_abort;
-
 	pthread_mutex_init(&global_ctx->fs_fix_mutex, NULL);
 	pthread_rwlock_init(&global_ctx->fs_block_map_rwlock, NULL);
-	init_ext2_max_sizes();
 	retval = e2fsck_pass1_threads_start(&infos, global_ctx);
 	if (retval) {
 		com_err(global_ctx->program_name, retval,
@@ -3351,7 +3351,11 @@ out_abort:
 
 void e2fsck_pass1(e2fsck_t ctx)
 {
-	e2fsck_pass1_multithread(ctx);
+	_e2fsck_pass1_prepare(ctx);
+	if (ctx->options & E2F_OPT_MULTITHREAD)
+		e2fsck_pass1_multithread(ctx);
+	else
+		_e2fsck_pass1(ctx);
 	_e2fsck_pass1_post(ctx);
 }
 
-- 
2.25.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ