From patchwork Tue Jan 16 14:34:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenjie Qi X-Patchwork-Id: 188538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp295948dye; Tue, 16 Jan 2024 06:34:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt+n3fuWGdYY5VgzYo08JaIT+dYEotpZsOeR5uwW1EPMZK8bY4ZTTTzTU37Bese5ZL8HOg X-Received: by 2002:a17:907:a094:b0:a2b:5d55:c322 with SMTP id hu20-20020a170907a09400b00a2b5d55c322mr3729346ejc.25.1705415698805; Tue, 16 Jan 2024 06:34:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705415698; cv=none; d=google.com; s=arc-20160816; b=TU51Za1/lw42Ggs5yYMAQFZr8Q9MEIyQFBrj/vn1dCfvtReTvBXOQfpY0LMprSpUGJ DZiPIJmNr2Vtzw6V58u8zNOFZvYr6j2YCV7W4fwP4KUSurxAsb1X/qHiEN/hkfwE8t5h KSca+U4fOrThCNo8zmhuyPdKutHerbiD6fH5zhA/9O4hX+9DO7pWj5p98YfebAtbZAru bv4UH3r34MI679d2X3Uo8f8R3hoMJDqSSRi4zbpyMvL70ArnQvk5A041Cp1yeVcfwN0H edb567y0oR3eT/9bIECFc5RH5jpzidGuUtcxpF3Tdg5Yur3Xl8EVLB6F7cn0tf/9jq3S 86eg== ARC-Message-Signature: i=1; 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=wVLeCLs+UC4LCws3JCkyo7iN6KY4LoEJi4nfZy2Uvf0=; fh=nDl6znmQbhlaWAOtC9VQsGq/L9X4vKYd1lZnUV6gntg=; b=uDnQigYfC5f1CEZ0C28mqd/9Ad1YBAcZ4x5D4bfw5H12fgBPXgnTuoRV5JzraAh8re /D44t7wFPx+P8wwI8f3/dyr8+Hxz7GsWJwhegdPqhQKsB3UBlhX5l3u6qFvU+f4jtvp+ i3kFv2tShxyJbo1zi6BDzMER6iHXx6tinKXNup5651x367OJzkChuJpJ2fULvMs74Zgw hKpceQWqyRolm37e4sFkMyYTItEl9pAB0DjJ9aMQkMpO+Lqj5aaxJHb2NDdfPsLIUFSq Qk1OtV4f+rXv9EIZRc8/vIvBefbHHeG3XyS8fDh4yMD5GSVjaD0JRZ9vrD+DCXk1K8Ju nd1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="dla/Q3AF"; spf=pass (google.com: domain of linux-kernel+bounces-27465-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27465-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m12-20020a170906580c00b00a297d2fae1csi4762760ejq.594.2024.01.16.06.34.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 06:34:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27465-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="dla/Q3AF"; spf=pass (google.com: domain of linux-kernel+bounces-27465-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27465-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 6C23E1F23F4D for ; Tue, 16 Jan 2024 14:34:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2840F1BF41; Tue, 16 Jan 2024 14:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dla/Q3AF" Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E3781BF26 for ; Tue, 16 Jan 2024 14:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5cec32dedf3so4471343a12.0 for ; Tue, 16 Jan 2024 06:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705415679; x=1706020479; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wVLeCLs+UC4LCws3JCkyo7iN6KY4LoEJi4nfZy2Uvf0=; b=dla/Q3AFbrjHtLCE6mravsOD8rJxf9R975TBaD4tzH8ducKywK0BMeWgWf8Zp2PdyK fcS2TwHBUKjN8GsVeJqd7VWtpHzYx2eVDesDw5XArgm+4U7AGzOvdx6m9n/sbG/kmgXa h3ZR/70OiHORJ65cSh4yWymHM7fHfN0UVGaNeE90NCz28fY/acg/ZBH5pLubbNuWz3BI +CrMsFiLKy13S1F8gDybymCVEZEfM7gBGKW+Heye+kYINTUojreztLYzc1xRVrJcd4Sx ehis4WsfnmYUJLnMP7awxZad7kcZ3LlogLhKDmowsJTBNDi4WmBtyI9N6lex4+6Xf4VX 6wtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705415679; x=1706020479; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wVLeCLs+UC4LCws3JCkyo7iN6KY4LoEJi4nfZy2Uvf0=; b=OzTO4FG1dTm3fT2omFkLjoQ/1dXKtrL+TV0hnzmGaxQkS9DSiQ8mWNPZDvVziVnfKF DlGKsL+eawL8/QSEZXa/Xaped18f5BlOss7wUd3b0L34dsxEQKuNgUUFKVKZXKX4beWG dg7dGGgtX8zcw9Ye5Jq/7EKswU+1DW9dBtTd7ddLfM7bNPW7qNkxBwNY7K+9myz5YPn9 UmWEktHBxJRgG6bfv4yaGqvDGP1uHdtxdca47KhzGZpqE9V1DPJB98Tm3ok/2V1uA+Wv FpPJv0OamXv6QQMW1oJ0MPXooaP53GvSmck77yu4uccA5MuiEN66swNuzKa+VciU4u3U SpBg== X-Gm-Message-State: AOJu0Yw8+Z+VKG+3CoQMwDeKDj/3K32bHkuk2nmRpvGZN53A7ji9p85S ZzqJNDYH+ZO7hH4vIjb9PWU= X-Received: by 2002:a17:902:c409:b0:1d4:f77c:a8e4 with SMTP id k9-20020a170902c40900b001d4f77ca8e4mr4207509plk.79.1705415679435; Tue, 16 Jan 2024 06:34:39 -0800 (PST) Received: from localhost.localdomain ([2001:250:4000:8246:8dd2:f82d:e185:367f]) by smtp.gmail.com with ESMTPSA id g13-20020a170902f74d00b001d3c23a6862sm9402603plw.25.2024.01.16.06.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 06:34:39 -0800 (PST) From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: hustqwj@hust.edu.cn, Wenjie Qi Subject: [PATCH v1] f2fs: fix max open zone constraints Date: Tue, 16 Jan 2024 22:34:22 +0800 Message-ID: <20240116143422.1268-1-qwjhust@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788257971809481897 X-GMAIL-MSGID: 1788257971809481897 We can get the number of remaining available zone resources by subtracting the number of active logs from the number of max active zones of zoned devices. We can use these available zone resources to reduce the number of pending bio when switching zones. If max active zones is 0, there is no limit. Signed-off-by: Wenjie Qi --- fs/f2fs/data.c | 32 +++++++++++++++++++++++++------- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/super.c | 11 +++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index dce8defdf4c7..0b62ca296074 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -392,6 +392,19 @@ static void f2fs_zone_write_end_io(struct bio *bio) complete(&io->zone_wait); f2fs_write_end_io(bio); } + +static void f2fs_zone_write_end_io_nowait(struct bio *bio) +{ +#ifdef CONFIG_F2FS_IOSTAT + struct bio_iostat_ctx *iostat_ctx = bio->bi_private; + struct f2fs_sb_info *sbi = iostat_ctx->sbi; +#else + struct f2fs_sb_info *sbi = (struct f2fs_sb_info *)bio->bi_private; +#endif + + atomic_inc(&sbi->available_active_zones); + f2fs_write_end_io(bio); +} #endif struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, @@ -1085,14 +1098,19 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) goto next; out: #ifdef CONFIG_BLK_DEV_ZONED - if (f2fs_sb_has_blkzoned(sbi) && btype < META && + if (f2fs_sb_has_blkzoned(sbi) && sbi->max_active_zones && btype < META && is_end_zone_blkaddr(sbi, fio->new_blkaddr)) { - bio_get(io->bio); - reinit_completion(&io->zone_wait); - io->bi_private = io->bio->bi_private; - io->bio->bi_private = io; - io->bio->bi_end_io = f2fs_zone_write_end_io; - io->zone_pending_bio = io->bio; + if (!atomic_add_negative(-1, &sbi->available_active_zones)) { + io->bio->bi_end_io = f2fs_zone_write_end_io_nowait; + } else { + atomic_inc(&sbi->available_active_zones); + bio_get(io->bio); + reinit_completion(&io->zone_wait); + io->bi_private = io->bio->bi_private; + io->bio->bi_private = io; + io->bio->bi_end_io = f2fs_zone_write_end_io; + io->zone_pending_bio = io->bio; + } __submit_merged_bio(io); } #endif diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 65294e3b0bef..2aade367ac66 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1551,6 +1551,8 @@ struct f2fs_sb_info { #ifdef CONFIG_BLK_DEV_ZONED unsigned int blocks_per_blkz; /* F2FS blocks per zone */ + unsigned int max_active_zones; /* max zone resources of the zoned device */ + atomic_t available_active_zones; /* remaining zone resources for zone switch */ #endif /* for node-related operations */ diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 206d03c82d96..6711283ff187 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2385,6 +2385,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) if (err) goto restore_opts; +#ifdef CONFIG_BLK_DEV_ZONED + if (sbi->max_active_zones) + atomic_set(&sbi->available_active_zones, + sbi->max_active_zones - F2FS_OPTION(sbi).active_logs); +#endif + /* flush outstanding errors before changing fs state */ flush_work(&sbi->s_error_work); @@ -3932,6 +3938,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) if (!f2fs_sb_has_blkzoned(sbi)) return 0; + sbi->max_active_zones = bdev_max_active_zones(bdev); + if (sbi->max_active_zones) + atomic_set(&sbi->available_active_zones, + sbi->max_active_zones - F2FS_OPTION(sbi).active_logs); + zone_sectors = bdev_zone_sectors(bdev); if (!is_power_of_2(zone_sectors)) { f2fs_err(sbi, "F2FS does not support non power of 2 zone sizes\n");