From: Andreas Dilger <adilger@whamcloud.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, Andreas Dilger <adilger@whamcloud.com>
Subject: [PATCH 4/9] e2fsck: reduce memory usage for many directories
Date: Thu, 6 Feb 2020 18:09:41 -0700 [thread overview]
Message-ID: <1581037786-62789-4-git-send-email-adilger@whamcloud.com> (raw)
In-Reply-To: <1581037786-62789-1-git-send-email-adilger@whamcloud.com>
Pack struct dx_dir_info and dx_dirblock_info properly in memory, to
avoid holes, and fields are not larger than necessary. This reduces
the memory needed for each hashed dir, according to pahole(1) from:
struct dx_dir_info {
/* size: 32, cachelines: 1, members: 6 */
/* sum members: 26, holes: 1, sum holes: 2 */
/* padding: 4 */
};
struct dx_dirblock_info {
/* size: 56, cachelines: 1, members: 9 */
/* sum members: 48, holes: 2, sum holes: 8 */
/* last cacheline: 56 bytes */
};
to 8 bytes less for each directory and directory block, and leaves
space for future use if needed (e.g. larger numblocks):
struct dx_dir_info {
/* size: 24, cachelines: 1, members: 6 */
/* sum members: 20, holes: 1, sum holes: 4 */
/* bit holes: 1, sum bit holes: 7 bits */
};
struct dx_dirblock_info {
/* size: 48, cachelines: 1, members: 9 */
};
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
---
e2fsck/dx_dirinfo.c | 3 +--
e2fsck/e2fsck.h | 14 +++++++-------
e2fsck/pass2.c | 12 ++++++------
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/e2fsck/dx_dirinfo.c b/e2fsck/dx_dirinfo.c
index f0f6084..caca3e3 100644
--- a/e2fsck/dx_dirinfo.c
+++ b/e2fsck/dx_dirinfo.c
@@ -73,11 +73,10 @@ void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, struct ext2_inode *inode,
dir->ino = ino;
dir->numblocks = num_blocks;
dir->hashversion = 0;
- dir->casefolded_hash = inode->i_flags & EXT4_CASEFOLD_FL;
+ dir->casefolded_hash = !!(inode->i_flags & EXT4_CASEFOLD_FL);
dir->dx_block = e2fsck_allocate_memory(ctx, num_blocks
* sizeof (struct dx_dirblock_info),
"dx_block info array");
-
}
/*
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index 5e7db42..feb605c 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -104,12 +104,12 @@ struct dir_info {
* directories which contain a hash tree index.
*/
struct dx_dir_info {
- ext2_ino_t ino; /* Inode number */
- int numblocks; /* number of blocks */
- int hashversion;
- short depth; /* depth of tree */
- struct dx_dirblock_info *dx_block; /* Array of size numblocks */
- int casefolded_hash;
+ ext2_ino_t ino; /* Inode number */
+ short depth; /* depth of tree (15 bits) */
+ __u8 hashversion;
+ __u8 casefolded_hash:1;
+ blk_t numblocks; /* number of blocks in dir */
+ struct dx_dirblock_info *dx_block; /* Array of size numblocks */
};
#define DX_DIRBLOCK_ROOT 1
@@ -120,8 +120,8 @@ struct dx_dir_info {
struct dx_dirblock_info {
int type;
- blk64_t phys;
int flags;
+ blk64_t phys;
blk64_t parent;
blk64_t previous;
ext2_dirhash_t min_hash;
diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 5c3f7b8..0fa6233 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -71,8 +71,8 @@ static int allocate_dir_block(e2fsck_t ctx,
struct ext2_db_entry2 *dir_blocks_info,
char *buf, struct problem_context *pctx);
static void clear_htree(e2fsck_t ctx, ext2_ino_t ino);
-static int htree_depth(struct dx_dir_info *dx_dir,
- struct dx_dirblock_info *dx_db);
+static short htree_depth(struct dx_dir_info *dx_dir,
+ struct dx_dirblock_info *dx_db);
static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b);
struct check_dir_struct {
@@ -132,7 +132,7 @@ void e2fsck_pass2(e2fsck_t ctx)
struct dx_dirblock_info *dx_db;
int b;
ext2_ino_t i;
- int depth;
+ short depth;
problem_t code;
int bad_dir;
int (*check_dir_func)(ext2_filsys fs,
@@ -311,10 +311,10 @@ cleanup:
}
#define MAX_DEPTH 32000
-static int htree_depth(struct dx_dir_info *dx_dir,
- struct dx_dirblock_info *dx_db)
+static short htree_depth(struct dx_dir_info *dx_dir,
+ struct dx_dirblock_info *dx_db)
{
- int depth = 0;
+ short depth = 0;
while (dx_db->type != DX_DIRBLOCK_ROOT && depth < MAX_DEPTH) {
dx_db = &dx_dir->dx_block[dx_db->parent];
--
1.8.0
next prev parent reply other threads:[~2020-02-07 1:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-07 1:09 [PATCH 1/9] e2fsck: fix e2fsck_allocate_memory() overflow Andreas Dilger
2020-02-07 1:09 ` [PATCH 2/9] e2fsck: use proper types for variables Andreas Dilger
2020-02-29 23:27 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 3/9] e2fsck: avoid mallinfo() if over 2GB allocated Andreas Dilger
2020-02-29 23:28 ` Theodore Y. Ts'o
2020-02-07 1:09 ` Andreas Dilger [this message]
2020-02-29 23:29 ` [PATCH 4/9] e2fsck: reduce memory usage for many directories Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 5/9] debugfs: allow comment lines in command file Andreas Dilger
2020-02-29 23:32 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 6/9] debugfs: print inode numbers as unsigned Andreas Dilger
2020-02-29 23:34 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 7/9] e2fsck: fix overflow if more than 4B inodes Andreas Dilger
2020-02-29 23:35 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 8/9] e2fsck: consistently use ext2fs_get_mem() Andreas Dilger
2020-02-29 23:36 ` Theodore Y. Ts'o
2020-03-04 23:23 ` Theodore Y. Ts'o
2020-02-07 1:09 ` [PATCH 9/9] misc: handle very large files with filefrag Andreas Dilger
2020-03-04 23:27 ` Theodore Y. Ts'o
2020-02-12 0:58 ` [PATCH] " Andreas Dilger
2020-02-12 1:09 ` Andreas Dilger
2020-02-12 1:07 ` [PATCH] e2fsck: avoid overflow with very large dirs Andreas Dilger
2020-03-04 23:39 ` Theodore Y. Ts'o
2020-02-29 23:25 ` [PATCH 1/9] e2fsck: fix e2fsck_allocate_memory() overflow Theodore Y. Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1581037786-62789-4-git-send-email-adilger@whamcloud.com \
--to=adilger@whamcloud.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).