Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1460120pxb; Wed, 2 Feb 2022 05:34:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFPFkDoyT99eeXbwNzW9yh5qDlNo7yb58QKBMwPQSBGzOSQwvXvGqp0TTR4OaK9akuaGtP X-Received: by 2002:a17:903:2302:: with SMTP id d2mr30518542plh.18.1643808865690; Wed, 02 Feb 2022 05:34:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643808865; cv=none; d=google.com; s=arc-20160816; b=jgiMIgnTy0qsHWG8p83ksdfyNvbtFKQW9lr4kvEKhP5Icjr4XfQROS8EelgKAaa9O3 pHBt95OcuAGqlzKF7/Xsx2aKTAvPMRO13uY2SCxsb4wgU2cLIxV5GMIRWFjsbOu3r1Mb 4dYj8Wwh4393ZKsW1aTFiMDUqAs9pviST5d/twFsAa9icaMjQ8qGn8zw54Oxou/Nog/0 KpypI8wm+ji8DAS6IbC0CovuA0Cy4++sR2Ppgba8oWzr03Q4lYhVcnhY11FSaSdnjsTA jDZhpi8A3BRz6/k8Miz0Lgxlp2VfC5p4QMnkfTxUxkDjmzbUiQ4uV0CAkdtrZaZNRLVQ fFOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=4tHl1C+itQG6ufp4601MZgCGqjYvoSJJwvMt7UZ9Mcc=; b=EaZMHSB8rbiD6xDDWaIVdpgKGMqwZZdSFV4x8ieFO0nMWPmSz+1Z5tlY11sIVztSUA 0Fom1wePDAMwK5Pqu2CDWzjY5H1aMgTghjWOvRLlHQwHgzg8DBcMPHfstDrDccifR2S3 88VxPGNbGeVyWIWliw/L+NeGMctji7Vcfv25eqXt06aAkKWbBrflSj/HNhGZdfCBUSFm XAyAkTKmaGYJ4RkD6qTolZadxf38+wqqowccOCylx2Fs1Cy3xSuj6mx0DfqNHTPnsBIX JAcB8JEkXiYYCymLVefM26wSWOc1fyLc8RJOhJtFPoVfCQn9fXThoO1CT9kUxqiOtge6 2S0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=LGbAmDVg; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Le8cHBBL; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16si20325231plg.315.2022.02.02.05.34.06; Wed, 02 Feb 2022 05:34:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=LGbAmDVg; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Le8cHBBL; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237338AbiBALlB (ORCPT + 99 others); Tue, 1 Feb 2022 06:41:01 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:56914 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbiBALlA (ORCPT ); Tue, 1 Feb 2022 06:41:00 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 960AD218DF; Tue, 1 Feb 2022 11:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1643715659; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4tHl1C+itQG6ufp4601MZgCGqjYvoSJJwvMt7UZ9Mcc=; b=LGbAmDVgS0xnAaR2ttWl0A7NxbQggwwajh543DAEvRWlGV7Ul/h3BtJVsHXqcOovWiAluM kCTmyNiuY8EvvvJP2y3q9tPg9hxYSd5aXvWm8ahq3SmUf3qYdre97j00QimbV+hq1wQLXe 7TkgtVzg2/q2x6Xw9Sdgt+RSt/07MFI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1643715659; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4tHl1C+itQG6ufp4601MZgCGqjYvoSJJwvMt7UZ9Mcc=; b=Le8cHBBL+P7DumRe9+ddt9tFlMVofGzEeP7urmRsu1jbyvKhfJPvHK9n4xDxzlXzpeNqM+ ZsflwVfLGgy4T4DQ== Received: from quack3.suse.cz (unknown [10.163.28.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7F3D2A3B81; Tue, 1 Feb 2022 11:40:59 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 21985A05B1; Tue, 1 Feb 2022 12:40:59 +0100 (CET) Date: Tue, 1 Feb 2022 12:40:59 +0100 From: Jan Kara To: Ritesh Harjani Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Theodore Ts'o , Jan Kara , Harshad Shirwadkar Subject: Re: [RFC 5/6] ext4: Refactor ext4_free_blocks() to pull out ext4_mb_clear_bb() Message-ID: <20220201114059.chy3rauebk3ytszx@quack3.lan> References: <426fd12a24d7876e445aea3f14a6e09c2eba8fe3.1643642105.git.riteshh@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <426fd12a24d7876e445aea3f14a6e09c2eba8fe3.1643642105.git.riteshh@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon 31-01-22 20:46:54, Ritesh Harjani wrote: > ext4_free_blocks() function became too long and confusing, this patch > just pulls out the ext4_mb_clear_bb() function logic from it > which clears the block bitmap and frees it. > > No functionality change in this patch > > Signed-off-by: Ritesh Harjani Yeah, the function was rather long. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/ext4/mballoc.c | 180 ++++++++++++++++++++++++++-------------------- > 1 file changed, 102 insertions(+), 78 deletions(-) > > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c > index 2f931575e6c2..5f20e355d08c 100644 > --- a/fs/ext4/mballoc.c > +++ b/fs/ext4/mballoc.c > @@ -5870,7 +5870,8 @@ static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block, > } > > /** > - * ext4_free_blocks() -- Free given blocks and update quota > + * ext4_mb_clear_bb() -- helper function for freeing blocks. > + * Used by ext4_free_blocks() > * @handle: handle for this transaction > * @inode: inode > * @bh: optional buffer of the block to be freed > @@ -5878,9 +5879,9 @@ static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block, > * @count: number of blocks to be freed > * @flags: flags used by ext4_free_blocks > */ > -void ext4_free_blocks(handle_t *handle, struct inode *inode, > - struct buffer_head *bh, ext4_fsblk_t block, > - unsigned long count, int flags) > +static void ext4_mb_clear_bb(handle_t *handle, struct inode *inode, > + ext4_fsblk_t block, unsigned long count, > + int flags) > { > struct buffer_head *bitmap_bh = NULL; > struct super_block *sb = inode->i_sb; > @@ -5897,80 +5898,6 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, > > sbi = EXT4_SB(sb); > > - if (sbi->s_mount_state & EXT4_FC_REPLAY) { > - ext4_free_blocks_simple(inode, block, count); > - return; > - } > - > - might_sleep(); > - if (bh) { > - if (block) > - BUG_ON(block != bh->b_blocknr); > - else > - block = bh->b_blocknr; > - } > - > - if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) && > - !ext4_inode_block_valid(inode, block, count)) { > - ext4_error(sb, "Freeing blocks not in datazone - " > - "block = %llu, count = %lu", block, count); > - goto error_return; > - } > - > - ext4_debug("freeing block %llu\n", block); > - trace_ext4_free_blocks(inode, block, count, flags); > - > - if (bh && (flags & EXT4_FREE_BLOCKS_FORGET)) { > - BUG_ON(count > 1); > - > - ext4_forget(handle, flags & EXT4_FREE_BLOCKS_METADATA, > - inode, bh, block); > - } > - > - /* > - * If the extent to be freed does not begin on a cluster > - * boundary, we need to deal with partial clusters at the > - * beginning and end of the extent. Normally we will free > - * blocks at the beginning or the end unless we are explicitly > - * requested to avoid doing so. > - */ > - overflow = EXT4_PBLK_COFF(sbi, block); > - if (overflow) { > - if (flags & EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER) { > - overflow = sbi->s_cluster_ratio - overflow; > - block += overflow; > - if (count > overflow) > - count -= overflow; > - else > - return; > - } else { > - block -= overflow; > - count += overflow; > - } > - } > - overflow = EXT4_LBLK_COFF(sbi, count); > - if (overflow) { > - if (flags & EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER) { > - if (count > overflow) > - count -= overflow; > - else > - return; > - } else > - count += sbi->s_cluster_ratio - overflow; > - } > - > - if (!bh && (flags & EXT4_FREE_BLOCKS_FORGET)) { > - int i; > - int is_metadata = flags & EXT4_FREE_BLOCKS_METADATA; > - > - for (i = 0; i < count; i++) { > - cond_resched(); > - if (is_metadata) > - bh = sb_find_get_block(inode->i_sb, block + i); > - ext4_forget(handle, is_metadata, inode, bh, block + i); > - } > - } > - > do_more: > overflow = 0; > ext4_get_group_no_and_offset(sb, block, &block_group, &bit); > @@ -6132,6 +6059,103 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, > return; > } > > +/** > + * ext4_free_blocks() -- Free given blocks and update quota > + * @handle: handle for this transaction > + * @inode: inode > + * @bh: optional buffer of the block to be freed > + * @block: starting physical block to be freed > + * @count: number of blocks to be freed > + * @flags: flags used by ext4_free_blocks > + */ > +void ext4_free_blocks(handle_t *handle, struct inode *inode, > + struct buffer_head *bh, ext4_fsblk_t block, > + unsigned long count, int flags) > +{ > + struct super_block *sb = inode->i_sb; > + unsigned int overflow; > + struct ext4_sb_info *sbi; > + > + sbi = EXT4_SB(sb); > + > + if (sbi->s_mount_state & EXT4_FC_REPLAY) { > + ext4_free_blocks_simple(inode, block, count); > + return; > + } > + > + might_sleep(); > + if (bh) { > + if (block) > + BUG_ON(block != bh->b_blocknr); > + else > + block = bh->b_blocknr; > + } > + > + if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) && > + !ext4_inode_block_valid(inode, block, count)) { > + ext4_error(sb, "Freeing blocks not in datazone - " > + "block = %llu, count = %lu", block, count); > + return; > + } > + > + ext4_debug("freeing block %llu\n", block); > + trace_ext4_free_blocks(inode, block, count, flags); > + > + if (bh && (flags & EXT4_FREE_BLOCKS_FORGET)) { > + BUG_ON(count > 1); > + > + ext4_forget(handle, flags & EXT4_FREE_BLOCKS_METADATA, > + inode, bh, block); > + } > + > + /* > + * If the extent to be freed does not begin on a cluster > + * boundary, we need to deal with partial clusters at the > + * beginning and end of the extent. Normally we will free > + * blocks at the beginning or the end unless we are explicitly > + * requested to avoid doing so. > + */ > + overflow = EXT4_PBLK_COFF(sbi, block); > + if (overflow) { > + if (flags & EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER) { > + overflow = sbi->s_cluster_ratio - overflow; > + block += overflow; > + if (count > overflow) > + count -= overflow; > + else > + return; > + } else { > + block -= overflow; > + count += overflow; > + } > + } > + overflow = EXT4_LBLK_COFF(sbi, count); > + if (overflow) { > + if (flags & EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER) { > + if (count > overflow) > + count -= overflow; > + else > + return; > + } else > + count += sbi->s_cluster_ratio - overflow; > + } > + > + if (!bh && (flags & EXT4_FREE_BLOCKS_FORGET)) { > + int i; > + int is_metadata = flags & EXT4_FREE_BLOCKS_METADATA; > + > + for (i = 0; i < count; i++) { > + cond_resched(); > + if (is_metadata) > + bh = sb_find_get_block(inode->i_sb, block + i); > + ext4_forget(handle, is_metadata, inode, bh, block + i); > + } > + } > + > + ext4_mb_clear_bb(handle, inode, block, count, flags); > + return; > +} > + > /** > * ext4_group_add_blocks() -- Add given blocks to an existing group > * @handle: handle to this transaction > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR