Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1052866rbb; Sun, 25 Feb 2024 17:32:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWy4Pv8+RLRDGUQsM/3KaLSmMAQjDXTX7Cw/QQAA7zrbVwAwGtKoqD1qlnh/ksx8Zc2qZtOOWQdJ//sVv3ita8SuNOXVDV8eOmzNSUMyA== X-Google-Smtp-Source: AGHT+IGRWussXu+9YJl2wmoIH95aqlslllIloZzJ/YLzgo9mtKNBTka1b4YcWrcsPm3qOle9VAbr X-Received: by 2002:a05:6830:120c:b0:6e4:7be4:393a with SMTP id r12-20020a056830120c00b006e47be4393amr7402683otp.5.1708911177650; Sun, 25 Feb 2024 17:32:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708911177; cv=pass; d=google.com; s=arc-20160816; b=yCa1gmhabiGKu/LVnpygqBM8TFQQHICf2Amf+TiHm5to3K3pfOQCeN0JCrqeqFYnK2 Z/9MDu3wYX3OlUjse+E2Rjxjok9oDK/EuDhlQkXUYx6lawYePZQmYSNvtjposTtyVzz7 jB9fgSMwNh002Z9JxPY9s/wRM36Aw8GAxK4DKiwRH0p/jIkar554uxq72I/xrEMhUmR2 BstMSe66n7uvUMr0ybxS0NjOniAjtGAWct7GsA5MMTwXdKap86iHT1RrFSKuOlHLNeZB uwhOkRDdqgCe4KekhSE7yQxdSWGoPuInHp/JXifMhzVnciRTJyHq19lb8IYdXB3gavta FNnQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=03glMeje/iLpaIb+B6GH7CT34zGmE/V0Lp7YdCIZMbw=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=nXb8nzrsvR3C4H2csm1gHd9KILqTlwFUWM7l+0ZDkxK58Zg15jqI2HIpo8tp7uA3eI dQF+jI11oFDam396tU8CGroUu2ahMl8tcRmusLb+akJgp6+q50BrFubZOe+zv5iwwqAg cxUcc510FncNTvt/Zx/m2mTOBJKudjVf27ayFR03aSn5HbmyWnP2JQu4dFAqOVVGNLmN ql8z0Q8MFO2fDLsp0ANx8AvJZjvjtP6f8jKVfZPuVYgMEYhBq6K8OUmYizySFppyqDgg DPqy3o3vrLj9DOus58vQCLl3qIGUxeuV7EA8O4/B61U1gd3bec7HT7eTXBFJ71hO/MUv DEtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lWyg8I8P; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id kq17-20020a056a004b1100b006e4cf39bc99si2910286pfb.383.2024.02.25.17.32.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 17:32:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lWyg8I8P; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80379-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 90CC1B21318 for ; Mon, 26 Feb 2024 01:32:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99FAF15AC4; Mon, 26 Feb 2024 01:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lWyg8I8P" 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 C16521427E for ; Mon, 26 Feb 2024 01:32:24 +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=1708911144; cv=none; b=oHgtEZJdq6mc123ASCLXx5SGVy9c8aXNXPKei+GmgFKeNpNUl5UkEAODeMdI+UqPmfE2hJKQD2JmYe1KNFHRRl+MLS50fVLCInB68g1eCrVaoj1v3seVKYoYz/4w4BStJbgK5vkaOnlh9hVTGhovDzzCy4+c2tc1Sn1BDUSX2ws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708911144; c=relaxed/simple; bh=7/djeaK+/NFoE++1IozOSNTPK98LJgs6sV030L2n1tw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gWpuCvS0FiVV1Qall2a8H1QaaWzVfl4Pb4oxJ1zamS0OFmV2uqz0Wqd0yhZwMdvKCN0Yb6B6pkXqv34gzu2gtLKLOKLi5EJ7qzNvbS5VQLaAHRgL2z3Acwj3NvH0/n0DkjZuhid6dF5VXT5AbCTQeGLAQU2GszHYp0VXWXxV/Dk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lWyg8I8P; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFF2EC43390; Mon, 26 Feb 2024 01:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708911144; bh=7/djeaK+/NFoE++1IozOSNTPK98LJgs6sV030L2n1tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lWyg8I8Pg2PCw71IP12fMFIHDuAm3fqRKfnA9rFN0gPFb6kcT91MwHqEJyIji0ByZ auPFCDznLaELDhRTAee29UojTw8lGc0gSWWUwbM43K+ynZSMCVn8pfAm6Fnt666s9v WFtPKn33AySGF6bufcBV1R/JrxZ4byX2hcHeTc36cWy0f2/DchrnpFDMQMuUR74sNQ z4SyUf0KxzHEXY/nVkxr4yxn7qgqW+MgIhbBFgMGdZVQHitGMza+yN2BZvYGkBi5Wr AGywWzms+as6pTBJiK3IpXo7sP6DDPozZm4aelQZVqSxw63U2G5YcuovxNwFwZp62v EdypU4okNf3AA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 3/4] f2fs: clean up new_curseg() Date: Mon, 26 Feb 2024 09:32:07 +0800 Message-Id: <20240226013208.2389246-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240226013208.2389246-1-chao@kernel.org> References: <20240226013208.2389246-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move f2fs_valid_pinned_area() check logic from new_curseg() to get_new_segment(), it can avoid calling __set_free() if it fails to find free segment in conventional zone for pinned file. Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 847fe0b7f29f..c159b0985596 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2715,12 +2715,19 @@ static int get_new_segment(struct f2fs_sb_info *sbi, got_it: /* set it as dirty segment in free segmap */ f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap)); + + /* no free section in conventional zone */ + if (new_sec && pinning && + !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) { + ret = -EAGAIN; + goto out_unlock; + } __set_inuse(sbi, segno); *newseg = segno; out_unlock: spin_unlock(&free_i->segmap_lock); - if (ret) { + if (ret == -ENOSPC) { f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT); f2fs_bug_on(sbi, 1); } @@ -2796,19 +2803,17 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) struct curseg_info *curseg = CURSEG_I(sbi, type); unsigned int segno = curseg->segno; bool pinning = type == CURSEG_COLD_DATA_PINNED; + int ret; if (curseg->inited) write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, segno)); segno = __get_next_segno(sbi, type); - if (get_new_segment(sbi, &segno, new_sec, pinning)) { - curseg->segno = NULL_SEGNO; - return -ENOSPC; - } - if (new_sec && pinning && - !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) { - __set_free(sbi, segno); - return -EAGAIN; + ret = get_new_segment(sbi, &segno, new_sec, pinning); + if (ret) { + if (ret == -ENOSPC) + curseg->segno = NULL_SEGNO; + return ret; } curseg->next_segno = segno; -- 2.40.1