Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp910055rdb; Fri, 26 Jan 2024 15:08:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdluRFqrcpdEifTF1LifK+WxZaQXVZlpclpy2GVkt4D04TJVNsnqmIQ4QSLItQpkMMNrwj X-Received: by 2002:a17:906:3584:b0:a35:5b6:1e0f with SMTP id o4-20020a170906358400b00a3505b61e0fmr273547ejb.71.1706310505810; Fri, 26 Jan 2024 15:08:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706310505; cv=pass; d=google.com; s=arc-20160816; b=lwm5dDyzwNIJLT+JdMRN9zudsxCktWz5zFOyg2Ov+H/O4Ag+I4BrIeDDdjhcui15mL jeVvMTbsdgGkJo6KcFdA+dWZfktqWFky2gQB5lG/e0A0N7yNV/A07W++tJqkwNYbgJ2W h7enlt2SSY4NtVjBxpp6Nv4XivOLG1/rSob65hdnLK9jY5yRj6aFdI7AUC5dv2bxYDCP yhw1qAwcWi/QJyOGDdGjO+chMSl8D2Z3E9PU6kp9AgIOuqzJJAcKOECSY5EdFLQ5mniS jhcr4a+1fp0oH8TWd4UNCJif9lwY3fOrMthsD5DqcbtCAZSuEWwpZ5vyitJ4lEjvNcBt tbfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=cDgvlw2+zZg4+vBGbt35PcUSP+w9v5YJ81LThm3Va5I=; fh=lfmhT74OC6w7UVnwGNLw42Vak+xOQR6OdVNWZdRXGOA=; b=dMI1a2iem2ke3svlbQwKgNILaLuu3JoIvGyKysPar2B3FvS+KF5xlOG3969+ys9YMw j/yWGbCqVfotbnwvvFEwBOkRvc1f/sFuhQK8q0XybZ1Z6ZN0zGyrEYftGg92RxUyxPvp jeIrs0triLxwbVaNtBF+auncVrNPzzGDn5TwV3lg6R9Ekf8l6T/3J3cp0iqb52PSROMy tV+xw2nbBcF2Y/Z1063pTItD3SNX6Hai0m9BojsnHPxuEOfAp4JQ+fv+t1mgqR004f/F VsWM4P0xCTLbwiyEWtk2Ttlw4tHJGw+b2vISg36EHvmFqiTrEIroGbayXt169RqSNjJU Sx8w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OXelBLKM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-40803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40803-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qk16-20020a170906d9d000b00a2e92042f51si957156ejb.247.2024.01.26.15.08.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 15:08:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40803-linux.lists.archive=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=@kernel.org header.s=k20201202 header.b=OXelBLKM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-40803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40803-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 6149F1F24870 for ; Fri, 26 Jan 2024 23:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D0EC56779; Fri, 26 Jan 2024 23:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OXelBLKM" 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 9767D55E57 for ; Fri, 26 Jan 2024 23:08:16 +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=1706310496; cv=none; b=tG/pJzn9eQjc8Fh3vS7UgGHNYskTyGDOBe4qzSpIZT8qkDP18gDIBpaDGKXJ6Q3pM3BFi1JKNkW5JAzk0/ILKl2pv036KAFm5+vevVH+qUJg2Iv/rjMdMDrEzf2sNq1A71sWhKQ7TryCS+rGXjhDW6eTrqG/0eEUT9TNvWeRnDM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706310496; c=relaxed/simple; bh=gtDQI+hKL0TQ2S0fIwbLd2/StC1wd1X9UG/XGhPc+u0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IRD3iAthW34cl56YMpt050S7mshbOss4tNgCJzG3Fe8xqKVyc5OIgejXXplnpf65+emOhf7kJn5XvaiQfwMM2xwIWP2S6UZUoExMPasKzNY12aXHhaHG7BHorhP0TXetz+CTa8gb99OTFkN8iYypu2j8DYdE2tiIMUx2tpoI+Vc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OXelBLKM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DE71C433F1; Fri, 26 Jan 2024 23:08:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706310496; bh=gtDQI+hKL0TQ2S0fIwbLd2/StC1wd1X9UG/XGhPc+u0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OXelBLKMoeU91iMzptcxcM+mQaJSEpgO+jrwD6fwJBA2GkYx+erSHvnEqaEecJ7ys L9UR+moDECJyZTNAQStBJ1gqSu5Jo3jJb361fwbSboiVHV/p0YUsN9tkSs+y6gLuMd RM4TB7dkNB+Sq2ezTxik+577gPYickgUpAX0Pl2B1ezh1CV1XENFR1r4dA2nhp9qJ/ 0haeFt1yoLgoBcVaL0dkDQoPqPRIihKVZA//P8H+bBkf0INz8Fq1lEqopVaqZRfjpy Hz6QN8dXokICkd7xEjTGsy5qLKgFWycDOoof+b/7THMJ43wRjTyrsiamf/DlywMiWR YFNnxDfWK+faA== Date: Fri, 26 Jan 2024 15:08:14 -0800 From: Jaegeuk Kim To: Wenjie Cc: chao@kernel.org, guoweichao@oppo.com, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, hustqwj@hust.edu.cn Subject: Re: [PATCH v2] f2fs: fix max open zone constraints Message-ID: References: <20240109035804.642-1-qwjhust@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240109035804.642-1-qwjhust@gmail.com> On 01/09, Wenjie wrote: > From: Wenjie Qi > > 1. If the max active zones of zoned devices are less than > the active logs of F2FS, the device may error due to > insufficient zone resources when multiple active logs are > being written at the same time. > > 2. 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. > > 3. The original code for determining zone end was > after "out":, which would have missed some fio's > where is_end_zone_blkaddr(sbi, fio->new_blkaddr) > was true. I've moved this code before "skip:" to > make sure it's done for each fio. Could you please keep #3 as a separate patch? > > Signed-off-by: Wenjie Qi > --- > fs/f2fs/data.c | 38 ++++++++++++++++++++++++++++---------- > fs/f2fs/f2fs.h | 2 ++ > fs/f2fs/super.c | 9 +++++++++ > 3 files changed, 39 insertions(+), 10 deletions(-) > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index dce8defdf4c7..6b11364e94b8 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, > @@ -1080,22 +1093,27 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > io->last_block_in_bio = fio->new_blkaddr; > > trace_f2fs_submit_page_write(fio->page, fio); > -skip: > - if (fio->in_list) > - goto next; > -out: > #ifdef CONFIG_BLK_DEV_ZONED > if (f2fs_sb_has_blkzoned(sbi) && 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 > +skip: > + if (fio->in_list) > + goto next; > +out: > if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || > !f2fs_is_checkpoint_ready(sbi)) > __submit_merged_bio(io); > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 65294e3b0bef..1b1833e1d10e 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 */ > #endif > > /* for node-related operations */ > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > index 206d03c82d96..c79919425d63 100644 > --- a/fs/f2fs/super.c > +++ b/fs/f2fs/super.c > @@ -3932,6 +3932,15 @@ 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 && (sbi->max_active_zones < F2FS_OPTION(sbi).active_logs)) { > + f2fs_err(sbi, > + "zoned: max active zones %u is too small, need at least %u active zones", > + sbi->max_active_zones, F2FS_OPTION(sbi).active_logs); > + return -EINVAL; > + } > + 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"); > -- > 2.34.1