From patchwork Sun Mar 20 21:32:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Amir G." X-Patchwork-Id: 87671 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 A6C07B6EED for ; Mon, 21 Mar 2011 08:34:20 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751410Ab1CTVeT (ORCPT ); Sun, 20 Mar 2011 17:34:19 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:39539 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751349Ab1CTVeT (ORCPT ); Sun, 20 Mar 2011 17:34:19 -0400 Received: by mail-fx0-f46.google.com with SMTP id 17so5008530fxm.19 for ; Sun, 20 Mar 2011 14:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=10TxDWN8AGQdtdVxXd++HWvXtWHEH+Badnfg7ufoTKg=; b=Jcuh3vSFfYA4mG/VGr9IRmtie56LBokjUBfSBpGU++Ps5HampafKcSxh22ZghL/wBX W8tYovGMBdtpgNV6NCSSlISLuyd2pWeuInvl1tq8D/dkDoNZ7kThtBiYp7Lb7GFPFGAI 7UmbMkUQ+4MCbhkJQKL0c32mgpKEyke0Ul7xA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=IOq8xwytDuKjG36h4ASejG6phYRj6m/Jo9+Nxdke+RKGliYuVauleJUTgsZVJ0ThsA 3/3ia2qQ4TSmRBvlh63R7CNK6m4OqC0Yhg3JRfKtTisRrVZFySDksC9T4rFx/KNJUhMB v4V04OmuBoeSOAML/gvlyoL/3jtMWnBdNr/HI= Received: by 10.223.56.220 with SMTP id z28mr1099923fag.11.1300656858548; Sun, 20 Mar 2011 14:34:18 -0700 (PDT) Received: from localhost.localdomain (bzq-79-177-0-154.red.bezeqint.net [79.177.0.154]) by mx.google.com with ESMTPS id o17sm2225506fal.1.2011.03.20.14.34.15 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 20 Mar 2011 14:34:17 -0700 (PDT) From: amir73il@users.sourceforge.net To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Amir Goldstein Subject: [PATCH 2/5] ext4: implement ext4_add_groupblocks() by freeing blocks Date: Sun, 20 Mar 2011 23:32:47 +0200 Message-Id: <1300656770-14994-3-git-send-email-amir73il@users.sourceforge.net> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1300656770-14994-1-git-send-email-amir73il@users.sourceforge.net> References: <1300656770-14994-1-git-send-email-amir73il@users.sourceforge.net> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Amir Goldstein The old imlementation used to take grp->alloc_sem and set the GROUP_NEED_INIT flag, so that the buddy cache would be reloaded. The new implementation updates the buddy cache by freeing the added blocks and making them available for use, so there is no need to reload the buddy cache and there is no need to take grp->alloc_sem. Signed-off-by: Amir Goldstein --- fs/ext4/mballoc.c | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index c15f667..c7c9288 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4724,6 +4724,7 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, unsigned int i; struct ext4_group_desc *desc; struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_buddy e4b; int err = 0, ret, blk_free_count; ext4_grpblk_t blocks_freed; struct ext4_group_info *grp; @@ -4775,15 +4776,10 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, err = ext4_journal_get_write_access(handle, gd_bh); if (err) goto error_return; - /* - * make sure we don't allow a parallel init on other groups in the - * same buddy cache - */ - down_write(&grp->alloc_sem); + for (i = 0, blocks_freed = 0; i < count; i++) { BUFFER_TRACE(bitmap_bh, "clear bit"); - if (!ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group), - bit + i, bitmap_bh->b_data)) { + if (!mb_test_bit(bit + i, bitmap_bh->b_data)) { ext4_error(sb, "bit already cleared for block %llu", (ext4_fsblk_t)(block + i)); BUFFER_TRACE(bitmap_bh, "bit already cleared"); @@ -4791,7 +4787,19 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, blocks_freed++; } } + + err = ext4_mb_load_buddy(sb, block_group, &e4b); + if (err) + goto error_return; + + /* + * need to update group_info->bb_free and bitmap + * with group lock held. generate_buddy look at + * them with group lock_held + */ ext4_lock_group(sb, block_group); + mb_clear_bits(bitmap_bh->b_data, bit, count); + mb_free_blocks(NULL, &e4b, bit, count); blk_free_count = blocks_freed + ext4_free_blks_count(sb, desc); ext4_free_blks_set(sb, desc, blk_free_count); desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); @@ -4803,13 +4811,8 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, atomic_add(blocks_freed, &sbi->s_flex_groups[flex_group].free_blocks); } - /* - * request to reload the buddy with the - * new bitmap information - */ - set_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state)); - grp->bb_free += blocks_freed; - up_write(&grp->alloc_sem); + + ext4_mb_unload_buddy(&e4b); /* We dirtied the bitmap block */ BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");