Whamcloud - gitweb
LU-8465 e2fsck: avoid too much memory allocation for pfsck 49/39849/9
authorWang Shilong <wshilong@ddn.com>
Wed, 27 May 2020 07:14:23 +0000 (07:14 +0000)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 26 Sep 2020 06:38:54 +0000 (06:38 +0000)
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>
Change-Id: I99b7415231e0eb3670acec82a8a7b85b20dd36d5
Reviewed-on: https://review.whamcloud.com/39849
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lib/ext2fs/dblist.c
lib/ext2fs/icount.c

index 1fdd8f4..c4e712f 100644 (file)
@@ -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;
index 764788e..093f51b 100644 (file)
@@ -238,6 +238,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);
@@ -289,6 +291,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));