From patchwork Fri Jan 14 22:05:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Kali X-Patchwork-Id: 79015 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9DD46B6EED for ; Sat, 15 Jan 2011 09:05:41 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753818Ab1ANWFi (ORCPT ); Fri, 14 Jan 2011 17:05:38 -0500 Received: from smtp-out.google.com ([216.239.44.51]:5833 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753817Ab1ANWFi (ORCPT ); Fri, 14 Jan 2011 17:05:38 -0500 Received: from kpbe18.cbf.corp.google.com (kpbe18.cbf.corp.google.com [172.25.105.82]) by smtp-out.google.com with ESMTP id p0EM5bLI009037 for ; Fri, 14 Jan 2011 14:05:37 -0800 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1295042737; bh=3CSgYDoll5GK9QDw9yWUQZk3UZg=; h=MIME-Version:From:Date:Message-ID:Subject:To:Content-Type; b=GezOFTDWd/eRZOinX0oaNokVbasaiAK2Z6hLZSeKlhWyZzA3lSjZi8g9wF4uypMDg 9ALJh4h5bnrxI5U48XMLw== Received: from pxi2 (pxi2.prod.google.com [10.243.27.2]) by kpbe18.cbf.corp.google.com with ESMTP id p0EM5aIg005162 for ; Fri, 14 Jan 2011 14:05:36 -0800 Received: by pxi2 with SMTP id 2so551750pxi.12 for ; Fri, 14 Jan 2011 14:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=wvgA31U59795YFizadnAycCzCdvE8nyqvqqogjaIJbc=; b=lIWAtU7fKG1XVm0z1oBjUHTkVbN2wOxR673FUUw0Wt1X/c5AkTs2XMse+WBOujGlYQ ThASyxry+Y6mMj9BsAFw== DomainKey-Signature: a=rsa-sha1; c=nofws; d=google.com; s=beta; h=mime-version:from:date:message-id:subject:to:content-type; b=PZhnYr4kSaxosXSmVxDpEwh4sPpP8JBOAVnsP+2Bk91bDF8ae5iAnTmY73CHBiecYe DvQDOsWQRnD9wftaHsRg== Received: by 10.142.131.21 with SMTP id e21mr1161003wfd.428.1295042735916; Fri, 14 Jan 2011 14:05:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.166.9 with HTTP; Fri, 14 Jan 2011 14:05:15 -0800 (PST) From: Aditya Kali Date: Fri, 14 Jan 2011 14:05:15 -0800 Message-ID: Subject: [PATCH] ext4: Avoid unnecessary calls to ext4_mb_load_buddy while reading mb_groups proc file To: tytso@mit.edu, linux-ext4@vger.kernel.org X-System-Of-Record: true Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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//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 --- fs/ext4/mballoc.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) ext4_grpblk_t counters[16]; @@ -2189,15 +2190,21 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) i = (sb->s_blocksize_bits + 2) * sizeof(sg.info.bb_counters[0]) + sizeof(struct ext4_group_info); - err = ext4_mb_load_buddy(sb, group, &e4b); - if (err) { - seq_printf(seq, "#%-5u: I/O error\n", group); - return 0; + grinfo = ext4_get_group_info(sb, group); + /* Load the group info in memory only if not already loaded. */ + if (unlikely(EXT4_MB_GRP_NEED_INIT(grinfo))) { + err = ext4_mb_load_buddy(sb, group, &e4b); + if (err) { + seq_printf(seq, "#%-5u: I/O error\n", group); + return 0; + } + buddy_loaded = 1; } - ext4_lock_group(sb, group); + memcpy(&sg, ext4_get_group_info(sb, group), i); - ext4_unlock_group(sb, group); - ext4_mb_unload_buddy(&e4b); + + if (buddy_loaded) + ext4_mb_unload_buddy(&e4b); seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free, sg.info.bb_fragments, sg.info.bb_first_free); diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 851f49b..5738082 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -2171,8 +2171,9 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) struct super_block *sb = seq->private; ext4_group_t group = (ext4_group_t) ((unsigned long) v); int i; - int err; + int err, buddy_loaded = 0; struct ext4_buddy e4b; + struct ext4_group_info *grinfo; struct sg { struct ext4_group_info info;