diff options
author | Aditya Kali <adityakali@google.com> | 2012-06-30 19:10:57 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-06-30 19:10:57 -0400 |
commit | 1c8457cadc9cefe7ec920a2f3537ff1fe20f4061 (patch) | |
tree | 432621e536d959468f6206b8001a6023e9306fe7 /fs | |
parent | 6887a4131da3adaab011613776d865f4bcfb5678 (diff) |
ext4: avoid uneeded calls to ext4_mb_load_buddy() while reading mb_groups
Currently ext4_mb_load_buddy is called for every group, irrespective
of whether the group info is already in memory, while reading
/proc/fs/ext4/<partition>/mb_groups proc file. For the purpose of
mb_groups proc file, it is unnecessary to load the file group info
from disk if it was loaded in past. These calls to ext4_mb_load_buddy
make reading the mb_groups proc file expensive.
Also, the locks around ext4_get_group_info are not required.
This patch modifies the code to call ext4_mb_load_buddy only if the
group info had never been loaded into memory in past. It also removes
the mb group locking around ext4_get_group_info call.
Signed-off-by: Aditya Kali <adityakali@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/mballoc.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 1cd6994fc446..9f1e655979b9 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -2077,8 +2077,9 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) | |||
2077 | struct super_block *sb = seq->private; | 2077 | struct super_block *sb = seq->private; |
2078 | ext4_group_t group = (ext4_group_t) ((unsigned long) v); | 2078 | ext4_group_t group = (ext4_group_t) ((unsigned long) v); |
2079 | int i; | 2079 | int i; |
2080 | int err; | 2080 | int err, buddy_loaded = 0; |
2081 | struct ext4_buddy e4b; | 2081 | struct ext4_buddy e4b; |
2082 | struct ext4_group_info *grinfo; | ||
2082 | struct sg { | 2083 | struct sg { |
2083 | struct ext4_group_info info; | 2084 | struct ext4_group_info info; |
2084 | ext4_grpblk_t counters[16]; | 2085 | ext4_grpblk_t counters[16]; |
@@ -2095,15 +2096,21 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) | |||
2095 | 2096 | ||
2096 | i = (sb->s_blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) + | 2097 | i = (sb->s_blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) + |
2097 | sizeof(struct ext4_group_info); | 2098 | sizeof(struct ext4_group_info); |
2098 | err = ext4_mb_load_buddy(sb, group, &e4b); | 2099 | grinfo = ext4_get_group_info(sb, group); |
2099 | if (err) { | 2100 | /* Load the group info in memory only if not already loaded. */ |
2100 | seq_printf(seq, "#%-5u: I/O error\n", group); | 2101 | if (unlikely(EXT4_MB_GRP_NEED_INIT(grinfo))) { |
2101 | return 0; | 2102 | err = ext4_mb_load_buddy(sb, group, &e4b); |
2103 | if (err) { | ||
2104 | seq_printf(seq, "#%-5u: I/O error\n", group); | ||
2105 | return 0; | ||
2106 | } | ||
2107 | buddy_loaded = 1; | ||
2102 | } | 2108 | } |
2103 | ext4_lock_group(sb, group); | 2109 | |
2104 | memcpy(&sg, ext4_get_group_info(sb, group), i); | 2110 | memcpy(&sg, ext4_get_group_info(sb, group), i); |
2105 | ext4_unlock_group(sb, group); | 2111 | |
2106 | ext4_mb_unload_buddy(&e4b); | 2112 | if (buddy_loaded) |
2113 | ext4_mb_unload_buddy(&e4b); | ||
2107 | 2114 | ||
2108 | seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free, | 2115 | seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free, |
2109 | sg.info.bb_fragments, sg.info.bb_first_free); | 2116 | sg.info.bb_fragments, sg.info.bb_first_free); |