Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1197723ybe; Mon, 2 Sep 2019 16:31:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyILh6hvwKTN/oyneD1Tmkx5f32hjSr30Jp6EAQMuVPaDTsr84IfbHJn50IcLYHVAOFAHQ X-Received: by 2002:a17:90a:a89:: with SMTP id 9mr4260813pjw.126.1567467085947; Mon, 02 Sep 2019 16:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567467085; cv=none; d=google.com; s=arc-20160816; b=itKYjhTE0ktcIN8AlR+zCHW9KOUvdBRe/ZefC3ufm/EBKwGXstniVzHaN7xJHXQ2e4 8En5kUwNEOmNnjEif3Wuw2sG7imL2Qdecfn6AfYxRVMujbtzNhOFryUN9q/zpY0ph+zm LB9BM694ceUvKHJOXRnMUZpKbKUv0pA6IlWLEElUaq9cwpPrZFxwJ1h3Iq9XOFi9DyKq /X8/tNXSH90rzPfyzhK/fI3jz5o3hv+DU+qE3wOlzAcy9qnW0AQslMxJakS7VzRnD4VV e9ZAN9hWIxqy0TGE2A+s1wVuFvMJI1fIy/tu6di4MUeZAfHhSNq1OX//KF6eUtCo295r YdOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=cjBQI/7cEFwDtymtq8jFW4iX4WWUp827qeUyRe9lUpY=; b=Hhfoa6VtQ4TCzrlE0PdnJyLT27RhDqXzMdwGph3TgfFvyxoo1bUp7RA8bUE9JaWfrF aciGrDwasj1sTWYN+J1Cj04Yy7MP/nE/JRffAmab6J5pFF7P+DCz6c32jrNhxoWwmAaE AXX+8QPnZZZjGROS5P2q6jFWPPqmgYTOtv8bJ6hMjndFBNBwizocCEhYYcC95ZfrYaFx Gh9sxOryNvdZlcBVZqNfzjQhhWWwwd+0fLHYLEKdqH+qSZdqZ2BXzOh8CEB4UVTX9j1T RJslOcukeeyVSXX1dPW6DJi0W6pN2copbk5j5B/puJEieny/D/t1O8zIhQaFwqQdFsYT xGsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kSTXcfEl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi3si8244837plb.423.2019.09.02.16.31.09; Mon, 02 Sep 2019 16:31:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kSTXcfEl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727733AbfIBX3y (ORCPT + 99 others); Mon, 2 Sep 2019 19:29:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:59382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726623AbfIBX3y (ORCPT ); Mon, 2 Sep 2019 19:29:54 -0400 Received: from [192.168.0.102] (unknown [180.111.100.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1949922CF7; Mon, 2 Sep 2019 23:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567466993; bh=jktFROyoNclol0SVpnEc3+lR5Zp2bhVwsBQa5fF6h1Y=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=kSTXcfElviGkco8WfWy6NIeEmeXTfRASF0B+FJaM1EHkxa8LAqPCFXflw2g8UZ/Ox xmp0eSQg2frue27ytelfXXyw63OhSo1SUz//EARj6vx6iURs2ceB8dPCcsoZsQCM2z YABV2JfJdUJCF4uXaRBEZVd8bsWzvNjr07j+BLQI= Subject: Re: [PATCH v2 1/2] f2fs: introduce get_available_block_count() for cleanup To: Jaegeuk Kim , Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20190831095401.8142-1-yuchao0@huawei.com> <20190902225413.GC71929@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: <6c5da795-4929-3bb6-fdbf-e103a2bcd431@kernel.org> Date: Tue, 3 Sep 2019 07:29:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190902225413.GC71929@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-9-3 6:54, Jaegeuk Kim wrote: > On 08/31, Chao Yu wrote: >> 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 instead for cleanup. >> >> Signed-off-by: Chao Yu >> --- >> v2: >> - fix panic during recovery >> fs/f2fs/f2fs.h | 47 +++++++++++++++++++++++++++-------------------- >> 1 file changed, 27 insertions(+), 20 deletions(-) >> >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >> index a89ad8cab821..9c010e6cba5c 100644 >> --- a/fs/f2fs/f2fs.h >> +++ b/fs/f2fs/f2fs.h >> @@ -1756,6 +1756,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) >> @@ -1782,17 +1803,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)) { >> diff = sbi->total_valid_block_count - avail_user_block_count; >> if (diff > *count) >> @@ -2005,7 +2017,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) { >> @@ -2027,16 +2040,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); > > This doesn't look like same? Actually, calculations of block count in inc_valid_node_count() and inc_valid_block_count() should be the same, I've no idea why we use different policy for reserved block for root user. Thanks, > >> >> - 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.18.0.rc1