}
out:
ctx->fs_num_threads = num_threads;
+ ctx->fs->fs_num_threads = num_threads;
}
#endif
}
static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thread_ctx,
- int thread_index, int num_threads)
+ int thread_index, int num_threads,
+ dgrp_t average_group)
{
errcode_t retval;
e2fsck_t thread_context;
ext2_filsys thread_fs;
ext2_filsys global_fs = global_ctx->fs;
struct e2fsck_thread *tinfo;
- dgrp_t average_group;
assert(global_ctx->inode_used_map == NULL);
assert(global_ctx->inode_dir_map == NULL);
thread_context->thread_info.et_thread_index = thread_index;
set_up_logging(thread_context);
- /*
- * Distribute work to multiple threads:
- * Each thread work on fs->group_desc_count / nthread groups.
- */
tinfo = &thread_context->thread_info;
- average_group = thread_fs->group_desc_count / num_threads;
- if (average_group == 0)
- average_group = 1;
tinfo->et_group_start = average_group * thread_index;
- if (thread_index == num_threads - 1)
+ if (thread_index == global_fs->fs_num_threads - 1)
tinfo->et_group_end = thread_fs->group_desc_count;
else
tinfo->et_group_end = average_group * (thread_index + 1);
}
static int e2fsck_pass1_threads_join(struct e2fsck_thread_info *infos,
- int num_threads, e2fsck_t global_ctx)
+ e2fsck_t global_ctx)
{
errcode_t rc;
errcode_t ret = 0;
int i;
struct e2fsck_thread_info *pinfo;
+ int num_threads = global_ctx->fs_num_threads;
/* merge invalid bitmaps will recalculate it */
global_ctx->invalid_bitmaps = 0;
}
static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
- int num_threads, e2fsck_t global_ctx)
+ e2fsck_t global_ctx)
{
struct e2fsck_thread_info *infos;
pthread_attr_t attr;
struct e2fsck_thread_info *tmp_pinfo;
int i;
e2fsck_t thread_ctx;
+ dgrp_t average_group;
+ int num_threads = global_ctx->fs_num_threads;
#ifdef DEBUG_THREADS
struct e2fsck_thread_debug thread_debug =
{PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0};
return retval;
}
+ average_group = ext2fs_get_avg_group(global_ctx->fs);
for (i = 0; i < num_threads; i++) {
tmp_pinfo = &infos[i];
tmp_pinfo->eti_thread_index = i;
tmp_pinfo->eti_debug = &thread_debug;
#endif
retval = e2fsck_pass1_thread_prepare(global_ctx, &thread_ctx,
- i, num_threads);
+ i, num_threads,
+ average_group);
if (retval) {
com_err(global_ctx->program_name, retval,
_("while preparing pass1 thread\n"));
}
if (retval) {
- e2fsck_pass1_threads_join(infos, num_threads, global_ctx);
+ e2fsck_pass1_threads_join(infos, global_ctx);
return retval;
}
*pinfo = infos;
static void e2fsck_pass1_multithread(e2fsck_t global_ctx)
{
struct e2fsck_thread_info *infos = NULL;
- int num_threads = global_ctx->fs_num_threads;
errcode_t retval;
- retval = e2fsck_pass1_threads_start(&infos, num_threads, global_ctx);
+ retval = e2fsck_pass1_threads_start(&infos, global_ctx);
if (retval) {
com_err(global_ctx->program_name, retval,
_("while starting pass1 threads\n"));
goto out_abort;
}
- retval = e2fsck_pass1_threads_join(infos, num_threads, global_ctx);
+ retval = e2fsck_pass1_threads_join(infos, global_ctx);
if (retval) {
com_err(global_ctx->program_name, retval,
_("while joining pass1 threads\n"));
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.
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