Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1495628rdb; Mon, 19 Feb 2024 19:15:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVyqdqiOUqCp4P0m3E59H8QedR/l27gNN2qoDizEZUKNwAMp3k2+FhoZhaH1ZG/q2RBCxUi82f+2hl6Dw8bPUZvM2KkKoKuXYg39B2ZJA== X-Google-Smtp-Source: AGHT+IHS1WYP8yzvijSswHFqTO3Wvxpf69Y8H+tgZdt8mefQDIbUtFCyoJXyrdDvkzr56Q0cOWtD X-Received: by 2002:a05:6402:34f:b0:564:66d3:530f with SMTP id r15-20020a056402034f00b0056466d3530fmr3157570edw.28.1708398933665; Mon, 19 Feb 2024 19:15:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708398933; cv=pass; d=google.com; s=arc-20160816; b=VaYkqDkS3T2sjuJamtfh/65WZFBwPRHpqyCR9WFbhmw+3uT4IUhB4Wlc0DfUF4esow davuu82keG8fjKQ2MPghQbhxuWZU4l8ccqbDWN/eXXP6Iw5iEm9yF9Gshn8y06raHPG2 zQt5mjgOxXjG8t+IUrgSVE6mmpB89J/Lr0xWeic1GYO9brzjHmYMCH2OSoGDMuuGyfFG +ifp9kZMda7sM7thaWbfs2CYShAS4poEattzYc0N+MbKvL9QV8U71vNRqRkC2gqNUh2j nyj8TW5IFIOZvzQFo+4/lfBvAenSbvIOpi+ilJvS7CCZA5P635Xa9Xgo7s8bjov8JOLG FRzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=06PphD0oXgjFxwdPvufxNI79cxiLrUpOhjS1/ncqxwQ=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=IVMLESMGkofQrF0twtlXkn78nhNx2r4PkVz4sdj+OzfaVmPrvA1hiVEBJp4AlvNVEs 8FSyAjTnGCqWMHufviF1BBFcg10lWM47lqW1TNt3JcEu5FPi+tCedHsi1ygq6JO1+wGg CIiO90R4qRjXtfKUqeiiJgIOm30a0812IYfQpvybdP73Md9Gkg1ClpY7Aa68yChJu93P ltcBUtox/9A7mbBX0AlHWTE17B67rb4uIgHVKIEYb5zg9O7S8qghmAc2IfaT6nZFNM/A wKBZV6uBOqDabSrNX4x0HlQTnkCxlNTiIpp4KK1I9NYJOkBPb+X/RB9W4+tfqfdfdkqq uANA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eLRUaBYX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-72255-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72255-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y20-20020a056402359400b005641883d724si2939954edc.674.2024.02.19.19.15.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:15:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72255-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eLRUaBYX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-72255-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72255-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6C8A71F23E2E for ; Tue, 20 Feb 2024 03:15:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2630E433CB; Tue, 20 Feb 2024 03:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eLRUaBYX" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 452834A3F for ; Tue, 20 Feb 2024 03:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708398926; cv=none; b=O7HrYaRM2XnPEc5diPBeRrRfR3JzgKZR2AJ0AJvFfp8jXAqKkO2H34Ev7Bz7qVDnMuUXo4kapMxJWrGe2dclpQ8pXKRQS7JnYGc+IcQn3nvG5+gPJBehLnmwm3+Deaiej6j1GjSuxIdQMgDP7x70cfXeRMid729c976O/WmsfDs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708398926; c=relaxed/simple; bh=wcGy26e5hKuwjbVHIKAwO6Zpao1Gq1LGw3qoshIq2tI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jiDZLSuI6RkxvPPdB6/+fr2rLxfoY4tksi87truAY3/4XVFmWokEzUY2jbYoIx1XM6263xw0s4ZWdQBp+hQPutQhNKK3MopNxzKqqpk76qaBmQwyyNkPjiHfEDx056y8OFxyHZEpLqOfISGidCWWFiPLxYLiwjlTvQO3hiK6T7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eLRUaBYX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE5CAC433F1; Tue, 20 Feb 2024 03:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708398925; bh=wcGy26e5hKuwjbVHIKAwO6Zpao1Gq1LGw3qoshIq2tI=; h=From:To:Cc:Subject:Date:From; b=eLRUaBYXEuPPYJHEymbnuz8iJrOunSt540tSXCPYysJL+xjSYLrR0LWA/6m4suEd5 1pJtd/3Crt9VAzdwOEHQwzDRYrAg4g5dEW+swJGkk9QEN4kdpEWmOGFXl+lqQfm83S e+cifTigiAvVx0nRhXfmIGuPWxMrNy+gaSba/ZduSqUST3sbk3pV90DyQpnsqBQr41 UauM7dqweIOjs6PbfYsOwkeQmkCn7H7Jtn8WcVOEpBtI5qn1fEueNS0dZ0fTH8kUzV j5+aqdFx41g3erZRQTmcn++HW7hRjjiDxqTxKjljwHFmmW6KGh1jap7M9sGQS1tOqz yiHCk0SujT2nQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v2] f2fs: introduce get_available_block_count() for cleanup Date: Tue, 20 Feb 2024 11:15:15 +0800 Message-Id: <20240220031515.4039498-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There are very similar codes in inc_valid_block_count() and inc_valid_node_count() which is used for available user block count calculation. This patch introduces a new helper get_available_block_count() to include those common codes, and used it to clean up codes. Signed-off-by: Chao Yu --- v2: - rebase to last dev-test branch fs/f2fs/f2fs.h | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2b6c8de8737e..a1640be7dcbe 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2278,6 +2278,27 @@ static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, return false; } +static inline unsigned int get_available_block_count(struct f2fs_sb_info *sbi, + struct inode *inode, bool cap) +{ + block_t avail_user_block_count; + + avail_user_block_count = sbi->user_block_count - + sbi->current_reserved_blocks; + + if (!__allow_reserved_blocks(sbi, inode, cap)) + avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; + + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { + if (avail_user_block_count > sbi->unusable_block_count) + avail_user_block_count -= sbi->unusable_block_count; + else + avail_user_block_count = 0; + } + + return avail_user_block_count; +} + static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, struct inode *inode, blkcnt_t *count, bool partial) @@ -2303,18 +2324,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); sbi->total_valid_block_count += (block_t)(*count); - avail_user_block_count = sbi->user_block_count - - sbi->current_reserved_blocks; + avail_user_block_count = get_available_block_count(sbi, inode, true); - if (!__allow_reserved_blocks(sbi, inode, true)) - avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; - - if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { - if (avail_user_block_count > sbi->unusable_block_count) - avail_user_block_count -= sbi->unusable_block_count; - else - avail_user_block_count = 0; - } if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { if (!partial) { spin_unlock(&sbi->stat_lock); @@ -2610,7 +2621,8 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, struct inode *inode, bool is_inode) { block_t valid_block_count; - unsigned int valid_node_count, user_block_count; + unsigned int valid_node_count; + unsigned int avail_user_block_count; int err; if (is_inode) { @@ -2630,17 +2642,10 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); - valid_block_count = sbi->total_valid_block_count + - sbi->current_reserved_blocks + 1; - - if (!__allow_reserved_blocks(sbi, inode, false)) - valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; - - user_block_count = sbi->user_block_count; - if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) - user_block_count -= sbi->unusable_block_count; + valid_block_count = sbi->total_valid_block_count + 1; + avail_user_block_count = get_available_block_count(sbi, inode, false); - if (unlikely(valid_block_count > user_block_count)) { + if (unlikely(valid_block_count > avail_user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; } -- 2.40.1