aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Shilong <wshilong@ddn.com>2020-05-27 07:14:23 +0000
committerTheodore Ts'o <tytso@mit.edu>2021-01-25 15:18:42 -0500
commited2cec54da604efe1af2734182985d1730674138 (patch)
treef1f1d72425679002f74b081657efe2ba6868e378
parent41f40f4215fd9a357a3d250a34745eb953982bda (diff)
downloade2fsprogs-ed2cec54da604efe1af2734182985d1730674138.tar.gz
e2fsck: avoid too much memory allocation for pfsck
e2fsck init memory according to filesystem inodes/dir numbers recorded in the superblock, this should be aware of filesystem number of threads, otherwise, oom happen. Signed-off-by: Wang Shilong <wshilong@ddn.com> Reviewed-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--lib/ext2fs/dblist.c2
-rw-r--r--lib/ext2fs/icount.c4
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c
index 1fdd8f432..c4e712fd9 100644
--- a/lib/ext2fs/dblist.c
+++ b/lib/ext2fs/dblist.c
@@ -58,6 +58,8 @@ static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size,
if (retval)
goto cleanup;
dblist->size = (num_dirs * 2) + 12;
+ if (fs->fs_num_threads)
+ dblist->size /= fs->fs_num_threads;
}
len = (size_t) sizeof(struct ext2_db_entry2) * dblist->size;
dblist->count = count;
diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c
index 766eccca0..48665c7ec 100644
--- a/lib/ext2fs/icount.c
+++ b/lib/ext2fs/icount.c
@@ -237,6 +237,8 @@ errcode_t ext2fs_create_icount_tdb(ext2_filsys fs EXT2FS_NO_TDB_UNUSED,
* value.
*/
num_inodes = fs->super->s_inodes_count - fs->super->s_free_inodes_count;
+ if (fs->fs_num_threads)
+ num_inodes /= fs->fs_num_threads;
icount->tdb = tdb_open(fn, num_inodes, TDB_NOLOCK | TDB_NOSYNC,
O_RDWR | O_CREAT | O_TRUNC, 0600);
@@ -288,6 +290,8 @@ errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, unsigned int size,
if (retval)
goto errout;
icount->size += fs->super->s_inodes_count / 50;
+ if (fs->fs_num_threads)
+ icount->size /= fs->fs_num_threads;
}
bytes = (size_t) (icount->size * sizeof(struct ext2_icount_el));