Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3727963pxb; Mon, 24 Jan 2022 16:30:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKOevUw+1X5XFB3d+hL2PjtmdU8kFDHIt7yxYeC2BMH9bsalrRc1yMIeHf3IMFAQEon8aJ X-Received: by 2002:a17:902:ab05:b0:14b:e74:d7bd with SMTP id ik5-20020a170902ab0500b0014b0e74d7bdmr16537449plb.126.1643070603940; Mon, 24 Jan 2022 16:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643070603; cv=none; d=google.com; s=arc-20160816; b=EWyDe95q5Kn4shcYNdsTA1hx8DC1qxzon1hDNXF2D4OVzA9tN6t08cmjdvYszNNuMh 2rA8aIUzn8UC8ODqlxo1Q+5iFjFRi/mUKWdMv1lBugcnzyCKDk4PQCM/zL/Kb0lQLQg2 gBcvyMG0YPz53L6RHtLebjbTWScbsGBAykwIOmH7i1sceio5hArnuBMbjf8lj6IumijP MP5NjXdpG3TkgF0u2K0Fs8NGxLdNPshFvQimZU/d1ZzO+NvnR9ZflM+A0Gx7OVDwOl3t HoS7fs1KVZziCLRtGm51V9xIXKYzC/HFgvWJ2Ukud5TO9Dj0KYQZO4DdGMYZbTG0wv8V FjlQ== 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=YRprOnIgR2cUDhPi1wOc79TK+CromG5I5MqKL1bFc4g=; b=QggQwYgsInBdYrD6ZQTz45fVKQ/x5Z7cbseU6NA2pn6rrpZmdSovjQty6OwKyomXqL WRPUOF35vSUwy90ODdDtkoQajskpJuPE+iG68ycNx3GoX6uIikN5YI29h98USWvKzn80 NB+P/XtSnJ1ClpFyoKfosAkGSm8gBpArdDGrmZfMnZN/okRbiXF8L4nLYqtuB63ybNpa T8UgXsQeOhbHS3DPzp70L8OqZIJRonhT7v/2vZTcGNEaoV47XNvfr5pnHzw3e3cFVriN tv9DE5vDUSDoTzUeudTp418PV4+TRM9nle+AqavL+0l08sbunXPD/V9btZHfLm1n7jJv S/fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G0elHKSM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r7si16104682pgl.380.2022.01.24.16.29.51; Mon, 24 Jan 2022 16:30:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G0elHKSM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2375587AbiAYAUj (ORCPT + 99 others); Mon, 24 Jan 2022 19:20:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2360267AbiAXXgV (ORCPT ); Mon, 24 Jan 2022 18:36:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE788C0ADFD2; Mon, 24 Jan 2022 13:37:21 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 5EE2761509; Mon, 24 Jan 2022 21:37:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F026C340E5; Mon, 24 Jan 2022 21:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060240; bh=iVBtmMFos7khpdpnzC8VC+3aCQSp2wxi7CJFJLIM1oE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G0elHKSM3KGtYDGBNFjTP1hsEGItoaPsHpGm8gRikaa+JdbB/L3FwWSHsrBGMPgEE wqQx4lxRhdWSNWJE8/M1oFuqrzcyETFuQJsR5/wnkw4IVW/Pcm0/qxohTt2tkfYNQf a3CnXEtYG8j5IuRg28t1AtFdFC5HgDXabPiC9R4E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Naohiro Aota , David Sterba Subject: [PATCH 5.16 0885/1039] btrfs: add extent allocator hook to decide to allocate chunk or not Date: Mon, 24 Jan 2022 19:44:34 +0100 Message-Id: <20220124184155.038183447@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naohiro Aota commit 50475cd57706359d6cc652be88369dace7a4c2eb upstream. Introduce a new hook for an extent allocator policy. With the new hook, a policy can decide to allocate a new block group or not. If not, it will return -ENOSPC, so btrfs_reserve_extent() will cut the allocation size in half and retry the allocation if min_alloc_size is large enough. The hook has a place holder and will be replaced with the real implementation in the next patch. CC: stable@vger.kernel.org # 5.16 Signed-off-by: Naohiro Aota Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3947,6 +3947,19 @@ static void found_extent(struct find_fre } } +static bool can_allocate_chunk(struct btrfs_fs_info *fs_info, + struct find_free_extent_ctl *ffe_ctl) +{ + switch (ffe_ctl->policy) { + case BTRFS_EXTENT_ALLOC_CLUSTERED: + return true; + case BTRFS_EXTENT_ALLOC_ZONED: + return true; + default: + BUG(); + } +} + static int chunk_allocation_failed(struct find_free_extent_ctl *ffe_ctl) { switch (ffe_ctl->policy) { @@ -4034,6 +4047,10 @@ static int find_free_extent_update_loop( struct btrfs_trans_handle *trans; int exist = 0; + /*Check if allocation policy allows to create a new chunk */ + if (!can_allocate_chunk(fs_info, ffe_ctl)) + return -ENOSPC; + trans = current->journal_info; if (trans) exist = 1;