Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3115115rwb; Mon, 15 Aug 2022 18:29:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7T00X1tgiPeTJil0KlK4TReBNsihvjxXJCTi3GC7GSQ5scNIWbHi271k6y5aJuMsNrxrmA X-Received: by 2002:a63:80c7:0:b0:41c:62dc:7d10 with SMTP id j190-20020a6380c7000000b0041c62dc7d10mr16570428pgd.313.1660613341767; Mon, 15 Aug 2022 18:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613341; cv=none; d=google.com; s=arc-20160816; b=mopYNxMnYL4ZtCPgDb/Nj1McCvrYmZpNfol0RL9LBhVh+cccTPDx4hCrMhXdZ+3ivS sAEPoc7GoS9kA2HRQOx8IxCsMyWkfX32Np8bJIbv6nGfOHjO8/nQ+ikMYbJesuk3d8xU luYOTWBAA4SfqWAfABQZD1BOo7U0Lw1Q0y2RluU8ntxTz3o941AP9l5FIqClVIdVPyG+ lK0d1HLB36KStFuUlpiPoX7lMcT6Zi2ZrlJx4OJyZaiiGbUTbUpkbHb8IZG1wR6dCDCP +1xACiePAVH3QkGAQ7U2KEc6Zidwoj+2tdYF5sJNeuz6ethcbLqZusguVkXYDjA+itwH 44DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NdGRcPJpw9y6QqCQle7sLqQHchwtFJu8qJQ0bUd+K7o=; b=KwHb1CUWPY+uEtGnuN5kPlMNfCsCAZ2gTFjxRj+Ss3PKh5yEEPm0/OgHFxeiU2L3QP pXZOOzmw1LgJ+vp9nEh82XoxYbh81cWwSzpRBlsZXCh8yjKnlRhc1/AK0VOB+N3jIyI7 OH/pbqxDeh+uL/1+qzADQxfA64a9xQk3Rpfc8EjL5qSAhXUpkCC40E2ewo3IAzZOfWCp qQ7W8P+SZwx/z1iOWDvk9687F9LCP1DyNM/c/2ApIeiCm8+v7SfHzXllf0eIHb6IVt2+ db6OBbbzv8PqQhjXcoIUX7tFGtnkdf9c+bwgHR0109rPTtI22UOsPR4fEALeJWsRx5PC qqSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wQ8eTpQw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r83-20020a632b56000000b00419be2b2b2fsi12571262pgr.735.2022.08.15.18.28.50; Mon, 15 Aug 2022 18:29:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wQ8eTpQw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344930AbiHPBEW (ORCPT + 99 others); Mon, 15 Aug 2022 21:04:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348959AbiHPA54 (ORCPT ); Mon, 15 Aug 2022 20:57:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736A51A1524; Mon, 15 Aug 2022 13:49:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 19AA7B811A0; Mon, 15 Aug 2022 20:49:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F6E1C433D6; Mon, 15 Aug 2022 20:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596559; bh=Laq28zTtiS0G9s9VzXihgBdykSB7/ytUfDPl+DvERXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wQ8eTpQwVpmmAqEeEbmZwfpASriNxCKr3PX7vK6HRvYV1LTUUwf7Fes2CqGUe9Fl+ H1HyysEVvThZ8YlM7ZYtz+YsJ2HwJbIJaczT8INTQ3NXWplsTLN26ffjq+mYbCat/v ww5wJDwa/pTDX7VrMCBWajBZ62DQzNTrqaJxpDn0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , Naohiro Aota , David Sterba , Sasha Levin Subject: [PATCH 5.19 1085/1157] btrfs: zoned: revive max_zone_append_bytes Date: Mon, 15 Aug 2022 20:07:21 +0200 Message-Id: <20220815180523.577596003@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naohiro Aota [ Upstream commit c2ae7b772ef4e86c5ddf3fd47bf59045ae96a414 ] This patch is basically a revert of commit 5a80d1c6a270 ("btrfs: zoned: remove max_zone_append_size logic"), but without unnecessary ASSERT and check. The max_zone_append_size will be used as a hint to estimate the number of extents to cover delalloc/writeback region in the later commits. The size of a ZONE APPEND bio is also limited by queue_max_segments(), so this commit considers it to calculate max_zone_append_size. Technically, a bio can be larger than queue_max_segments() * PAGE_SIZE if the pages are contiguous. But, it is safe to consider "queue_max_segments() * PAGE_SIZE" as an upper limit of an extent size to calculate the number of extents needed to write data. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/ctree.h | 2 ++ fs/btrfs/zoned.c | 17 +++++++++++++++++ fs/btrfs/zoned.h | 1 + 3 files changed, 20 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 9c21e214d29e..7abfbfd7c94c 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1047,6 +1047,8 @@ struct btrfs_fs_info { */ u64 zone_size; + /* Max size to emit ZONE_APPEND write command */ + u64 max_zone_append_size; struct mutex zoned_meta_io_lock; spinlock_t treelog_bg_lock; u64 treelog_bg; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index d99026df6f67..52607569cf49 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -415,6 +415,16 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) nr_sectors = bdev_nr_sectors(bdev); zone_info->zone_size_shift = ilog2(zone_info->zone_size); zone_info->nr_zones = nr_sectors >> ilog2(zone_sectors); + /* + * We limit max_zone_append_size also by max_segments * + * PAGE_SIZE. Technically, we can have multiple pages per segment. But, + * since btrfs adds the pages one by one to a bio, and btrfs cannot + * increase the metadata reservation even if it increases the number of + * extents, it is safe to stick with the limit. + */ + zone_info->max_zone_append_size = + min_t(u64, (u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT, + (u64)bdev_max_segments(bdev) << PAGE_SHIFT); if (!IS_ALIGNED(nr_sectors, zone_sectors)) zone_info->nr_zones++; @@ -640,6 +650,7 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info) u64 zoned_devices = 0; u64 nr_devices = 0; u64 zone_size = 0; + u64 max_zone_append_size = 0; const bool incompat_zoned = btrfs_fs_incompat(fs_info, ZONED); int ret = 0; @@ -674,6 +685,11 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info) ret = -EINVAL; goto out; } + if (!max_zone_append_size || + (zone_info->max_zone_append_size && + zone_info->max_zone_append_size < max_zone_append_size)) + max_zone_append_size = + zone_info->max_zone_append_size; } nr_devices++; } @@ -723,6 +739,7 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info) } fs_info->zone_size = zone_size; + fs_info->max_zone_append_size = max_zone_append_size; fs_info->fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_ZONED; /* diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 6b2eec99162b..9caeab07fd38 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -19,6 +19,7 @@ struct btrfs_zoned_device_info { */ u64 zone_size; u8 zone_size_shift; + u64 max_zone_append_size; u32 nr_zones; unsigned int max_active_zones; atomic_t active_zones_left; -- 2.35.1