From patchwork Fri Sep 22 19:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13396355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D580BCD4854 for ; Fri, 22 Sep 2023 19:17:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233427AbjIVTRG (ORCPT ); Fri, 22 Sep 2023 15:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbjIVTRG (ORCPT ); Fri, 22 Sep 2023 15:17:06 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46C50A3 for ; Fri, 22 Sep 2023 12:17:00 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D763F21878; Fri, 22 Sep 2023 19:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695410218; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ryUa50DxN/TbWvWFs/y5mjXbkOJKwbmKSdhz3KC1qlE=; b=pdzjcyW5Sc4cQv7w5MLk/kWYF1ZczFa+v0ymOpemlSKwd1Npb9hehwtVE+SJVI7MGJstdi FE1UyO7RNANPEbK45Zbl7tz3Xn0yDtIP4ITWqGOpi4qqt0uGrQAP44D3FhkCWpEWiZEC2J bGIzHuJADlGM1njOfSuLyichpBLN6fo= Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id BB6622C142; Fri, 22 Sep 2023 19:16:58 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id B9CD2DA832; Fri, 22 Sep 2023 21:10:24 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 1/5] btrfs: use on-stack variable for block reserve in btrfs_evict_inode Date: Fri, 22 Sep 2023 21:10:24 +0200 Message-ID: <207744286f55daefc0a55f383224632d3e8b57fc.1695408280.git.dsterba@suse.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can avoid potential memory allocation failure in btrfs_evict_inode as the block reserve lifetime is limited to the scope of the function. This requires +48 bytes on stack. Signed-off-by: David Sterba --- fs/btrfs/inode.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 52576deda654..e1cb7583016d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5202,7 +5202,7 @@ void btrfs_evict_inode(struct inode *inode) struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_trans_handle *trans; struct btrfs_root *root = BTRFS_I(inode)->root; - struct btrfs_block_rsv *rsv = NULL; + struct btrfs_block_rsv rsv; int ret; trace_btrfs_inode_evict(inode); @@ -5249,11 +5249,9 @@ void btrfs_evict_inode(struct inode *inode) */ btrfs_kill_delayed_inode_items(BTRFS_I(inode)); - rsv = btrfs_alloc_block_rsv(fs_info, BTRFS_BLOCK_RSV_TEMP); - if (!rsv) - goto out; - rsv->size = btrfs_calc_metadata_size(fs_info, 1); - rsv->failfast = true; + btrfs_init_metadata_block_rsv(fs_info, &rsv, BTRFS_BLOCK_RSV_TEMP); + rsv.size = btrfs_calc_metadata_size(fs_info, 1); + rsv.failfast = true; btrfs_i_size_write(BTRFS_I(inode), 0); @@ -5265,11 +5263,11 @@ void btrfs_evict_inode(struct inode *inode) .min_type = 0, }; - trans = evict_refill_and_join(root, rsv); + trans = evict_refill_and_join(root, &rsv); if (IS_ERR(trans)) - goto out; + goto out_release; - trans->block_rsv = rsv; + trans->block_rsv = &rsv; ret = btrfs_truncate_inode_items(trans, root, &control); trans->block_rsv = &fs_info->trans_block_rsv; @@ -5281,7 +5279,7 @@ void btrfs_evict_inode(struct inode *inode) */ btrfs_btree_balance_dirty_nodelay(fs_info); if (ret && ret != -ENOSPC && ret != -EAGAIN) - goto out; + goto out_release; else if (!ret) break; } @@ -5295,16 +5293,17 @@ void btrfs_evict_inode(struct inode *inode) * If it turns out that we are dropping too many of these, we might want * to add a mechanism for retrying these after a commit. */ - trans = evict_refill_and_join(root, rsv); + trans = evict_refill_and_join(root, &rsv); if (!IS_ERR(trans)) { - trans->block_rsv = rsv; + trans->block_rsv = &rsv; btrfs_orphan_del(trans, BTRFS_I(inode)); trans->block_rsv = &fs_info->trans_block_rsv; btrfs_end_transaction(trans); } +out_release: + btrfs_block_rsv_release(fs_info, &rsv, (u64)-1, NULL); out: - btrfs_free_block_rsv(fs_info, rsv); /* * If we didn't successfully delete, the orphan item will still be in * the tree and we'll retry on the next mount. Again, we might also want From patchwork Fri Sep 22 19:10:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13396356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F00DBCD4853 for ; Fri, 22 Sep 2023 19:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233498AbjIVTRJ (ORCPT ); Fri, 22 Sep 2023 15:17:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233435AbjIVTRI (ORCPT ); Fri, 22 Sep 2023 15:17:08 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54DB3A3 for ; Fri, 22 Sep 2023 12:17:02 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0EDCE1FE32; Fri, 22 Sep 2023 19:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695410221; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CDKXQYhUFrKT4JamsqM+T05+FNHofA1GimhAld15Nts=; b=L9P0Udse+IQABlUWePB8rb9Q7Eoe+cG+POykbVOmnU60ZSSwO6gWT2S2xp9/U/NqN9KLKq +NlhC7xeEB5UtfIt6NQd7v3xwNWe/Ep4BYJXilK/dkFdaCFvOOWYQda5aN9JbzSWUgbE/a vZgS4k5feA2iWOijdRNRfTWoOW2IOAc= Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id E968B2C142; Fri, 22 Sep 2023 19:17:00 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id E02E4DA832; Fri, 22 Sep 2023 21:10:26 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 2/5] btrfs: use on-stack variable for block reserve in btrfs_truncate Date: Fri, 22 Sep 2023 21:10:26 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can avoid potential memory allocation failure in btrfs_truncate as the block reserve lifetime is limited to the scope of the function. This requires +48 bytes on stack. Signed-off-by: David Sterba --- fs/btrfs/inode.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e1cb7583016d..780537abeba7 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8246,7 +8246,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) }; struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; - struct btrfs_block_rsv *rsv; + struct btrfs_block_rsv rsv; int ret; struct btrfs_trans_handle *trans; u64 mask = fs_info->sectorsize - 1; @@ -8288,11 +8288,9 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) * 2) fs_info->trans_block_rsv - this will have 1 items worth left for * updating the inode. */ - rsv = btrfs_alloc_block_rsv(fs_info, BTRFS_BLOCK_RSV_TEMP); - if (!rsv) - return -ENOMEM; - rsv->size = min_size; - rsv->failfast = true; + btrfs_init_metadata_block_rsv(fs_info, &rsv, BTRFS_BLOCK_RSV_TEMP); + rsv.size = min_size; + rsv.failfast = true; /* * 1 for the truncate slack space @@ -8305,7 +8303,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) } /* Migrate the slack space for the truncate to our reserve */ - ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, rsv, + ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, &rsv, min_size, false); /* * We have reserved 2 metadata units when we started the transaction and @@ -8317,7 +8315,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) goto out; } - trans->block_rsv = rsv; + trans->block_rsv = &rsv; while (1) { struct extent_state *cached_state = NULL; @@ -8360,9 +8358,9 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) break; } - btrfs_block_rsv_release(fs_info, rsv, -1, NULL); + btrfs_block_rsv_release(fs_info, &rsv, -1, NULL); ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, - rsv, min_size, false); + &rsv, min_size, false); /* * We have reserved 2 metadata units when we started the * transaction and min_size matches 1 unit, so this should never @@ -8371,7 +8369,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) if (WARN_ON(ret)) break; - trans->block_rsv = rsv; + trans->block_rsv = &rsv; } /* @@ -8409,7 +8407,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) btrfs_btree_balance_dirty(fs_info); } out: - btrfs_free_block_rsv(fs_info, rsv); + btrfs_block_rsv_release(fs_info, &rsv, (u64)-1, NULL); /* * So if we truncate and then write and fsync we normally would just * write the extents that changed, which is a problem if we need to From patchwork Fri Sep 22 19:10:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13396357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 978EFCD4854 for ; Fri, 22 Sep 2023 19:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233609AbjIVTRL (ORCPT ); Fri, 22 Sep 2023 15:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232021AbjIVTRK (ORCPT ); Fri, 22 Sep 2023 15:17:10 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78700A3 for ; Fri, 22 Sep 2023 12:17:04 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 368A421845; Fri, 22 Sep 2023 19:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695410223; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PMISc5NzcM1J17puirQSiNTefPswrgCFfkWhYjgz2Zs=; b=mC5tgKPpkaCJya5d7q4DSXfDkqMdgsyOkWA/rNSYQpOF33YjHCOFrtr+8ziylmRIOdqPrR eQrl8iwJW9NMXnIoHSYKwa81VXjfMVcH9soDFIDTHdHMQgtjZw2ZWb4UkJgdv3/Nwd7sH4 VO12Pj2H/JSxLgOh3b6V5Bmvov3g7XI= Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id 1BA9F2C142; Fri, 22 Sep 2023 19:17:03 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 10B6ADA832; Fri, 22 Sep 2023 21:10:29 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 3/5] btrfs: use on-stack variable for block reserve in btrfs_replace_file_extents Date: Fri, 22 Sep 2023 21:10:28 +0200 Message-ID: <14f18cb66e7f762352fdda4df02d6d56b5b4485c.1695408280.git.dsterba@suse.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We can avoid potential memory allocation failure in btrfs_truncate as the block reserve lifetime is limited to the scope of the function. This requires +48 bytes on stack. Signed-off-by: David Sterba --- fs/btrfs/file.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 7a070f114a21..1bae9b3d50e1 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2324,7 +2324,7 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, u64 min_size = btrfs_calc_insert_metadata_size(fs_info, 1); u64 ino_size = round_up(inode->vfs_inode.i_size, fs_info->sectorsize); struct btrfs_trans_handle *trans = NULL; - struct btrfs_block_rsv *rsv; + struct btrfs_block_rsv rsv; unsigned int rsv_count; u64 cur_offset; u64 len = end - start; @@ -2333,13 +2333,9 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, if (end <= start) return -EINVAL; - rsv = btrfs_alloc_block_rsv(fs_info, BTRFS_BLOCK_RSV_TEMP); - if (!rsv) { - ret = -ENOMEM; - goto out; - } - rsv->size = btrfs_calc_insert_metadata_size(fs_info, 1); - rsv->failfast = true; + btrfs_init_metadata_block_rsv(fs_info, &rsv, BTRFS_BLOCK_RSV_TEMP); + rsv.size = btrfs_calc_insert_metadata_size(fs_info, 1); + rsv.failfast = true; /* * 1 - update the inode @@ -2356,14 +2352,14 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, if (IS_ERR(trans)) { ret = PTR_ERR(trans); trans = NULL; - goto out_free; + goto out_release; } - ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, rsv, + ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, &rsv, min_size, false); if (WARN_ON(ret)) goto out_trans; - trans->block_rsv = rsv; + trans->block_rsv = &rsv; cur_offset = start; drop_args.path = path; @@ -2478,10 +2474,10 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, } ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, - rsv, min_size, false); + &rsv, min_size, false); if (WARN_ON(ret)) break; - trans->block_rsv = rsv; + trans->block_rsv = &rsv; cur_offset = drop_args.drop_end; len = end - cur_offset; @@ -2558,16 +2554,15 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, out_trans: if (!trans) - goto out_free; + goto out_release; trans->block_rsv = &fs_info->trans_block_rsv; if (ret) btrfs_end_transaction(trans); else *trans_out = trans; -out_free: - btrfs_free_block_rsv(fs_info, rsv); -out: +out_release: + btrfs_block_rsv_release(fs_info, &rsv, (u64)-1, NULL); return ret; } From patchwork Fri Sep 22 19:10:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13396358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7229ECD4853 for ; Fri, 22 Sep 2023 19:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbjIVTRO (ORCPT ); Fri, 22 Sep 2023 15:17:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232021AbjIVTRN (ORCPT ); Fri, 22 Sep 2023 15:17:13 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A72FC1 for ; Fri, 22 Sep 2023 12:17:06 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 589F11FE32; Fri, 22 Sep 2023 19:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695410225; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ADM/ydSkfSm8Xv1cpzSwsGG0sUrJmoe1KGb0LqME8u4=; b=ICpAFZpg08PmFsHpCPEdxk0XRRoBxmB/H1BR4GPL/xrhuQz2xzVl9cwrzVLvSMLC/n7E2G yxkIlFHwDCDw2nR86vbGahI9jgLzzS5MZgrq40djrRYlI4B4MTDVmdvAGH+0e/C+7cmd7D H7cOnhNYlrl8eUzjEsPRk2djYb66Qw4= Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id 3EC2E2C142; Fri, 22 Sep 2023 19:17:05 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 42CD4DA832; Fri, 22 Sep 2023 21:10:31 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 4/5] btrfs: relocation: embed block reserve to struct reloc_control Date: Fri, 22 Sep 2023 21:10:31 +0200 Message-ID: <895699ead9c00b11c15183f0c315fcb8e8a67d3c.1695408280.git.dsterba@suse.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The size of reloc_control is over 1500 bytes, we don't need to allocate the block reserve separately with potential memory allocation failure, as this would use the space in the same 2K slab. Signed-off-by: David Sterba --- fs/btrfs/relocation.c | 46 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 903621a65244..cdadb4af58ea 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -139,7 +139,7 @@ struct reloc_control { /* inode for moving data */ struct inode *data_inode; - struct btrfs_block_rsv *block_rsv; + struct btrfs_block_rsv block_rsv; struct btrfs_backref_cache backref_cache; @@ -880,7 +880,7 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, if (!trans->reloc_reserved) { rsv = trans->block_rsv; - trans->block_rsv = rc->block_rsv; + trans->block_rsv = &rc->block_rsv; clear_rsv = 1; } reloc_root = create_reloc_root(trans, root, root->root_key.objectid); @@ -1751,7 +1751,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, memset(&next_key, 0, sizeof(next_key)); while (1) { - ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv, + ret = btrfs_block_rsv_refill(fs_info, &rc->block_rsv, min_reserved, BTRFS_RESERVE_FLUSH_LIMIT); if (ret) @@ -1774,7 +1774,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, * appropriately. */ reloc_root->last_trans = trans->transid; - trans->block_rsv = rc->block_rsv; + trans->block_rsv = &rc->block_rsv; replaced = 0; max_level = level; @@ -1871,7 +1871,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) again: if (!err) { num_bytes = rc->merging_rsv_size; - ret = btrfs_block_rsv_add(fs_info, rc->block_rsv, num_bytes, + ret = btrfs_block_rsv_add(fs_info, &rc->block_rsv, num_bytes, BTRFS_RESERVE_FLUSH_ALL); if (ret) err = ret; @@ -1880,7 +1880,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) trans = btrfs_join_transaction(rc->extent_root); if (IS_ERR(trans)) { if (!err) - btrfs_block_rsv_release(fs_info, rc->block_rsv, + btrfs_block_rsv_release(fs_info, &rc->block_rsv, num_bytes, NULL); return PTR_ERR(trans); } @@ -1888,7 +1888,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) if (!err) { if (num_bytes != rc->merging_rsv_size) { btrfs_end_transaction(trans); - btrfs_block_rsv_release(fs_info, rc->block_rsv, + btrfs_block_rsv_release(fs_info, &rc->block_rsv, num_bytes, NULL); goto again; } @@ -2360,7 +2360,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, num_bytes = calcu_metadata_size(rc, node, 1) * 2; - trans->block_rsv = rc->block_rsv; + trans->block_rsv = &rc->block_rsv; rc->reserved_bytes += num_bytes; /* @@ -2368,7 +2368,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, * If we get an enospc just kick back -EAGAIN so we know to drop the * transaction and try to refill when we can flush all the things. */ - ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv, num_bytes, + ret = btrfs_block_rsv_refill(fs_info, &rc->block_rsv, num_bytes, BTRFS_RESERVE_FLUSH_LIMIT); if (ret) { tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES; @@ -2381,8 +2381,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, * space for relocation and we will return earlier in * enospc case. */ - rc->block_rsv->size = tmp + fs_info->nodesize * - RELOCATION_RESERVED_NODES; + rc->block_rsv.size = tmp + fs_info->nodesize * RELOCATION_RESERVED_NODES; return -EAGAIN; } @@ -3631,21 +3630,18 @@ int prepare_to_relocate(struct reloc_control *rc) struct btrfs_trans_handle *trans; int ret; - rc->block_rsv = btrfs_alloc_block_rsv(rc->extent_root->fs_info, - BTRFS_BLOCK_RSV_TEMP); - if (!rc->block_rsv) - return -ENOMEM; - + btrfs_init_metadata_block_rsv(rc->extent_root->fs_info, &rc->block_rsv, + BTRFS_BLOCK_RSV_TEMP); memset(&rc->cluster, 0, sizeof(rc->cluster)); rc->search_start = rc->block_group->start; rc->extents_found = 0; rc->nodes_relocated = 0; rc->merging_rsv_size = 0; rc->reserved_bytes = 0; - rc->block_rsv->size = rc->extent_root->fs_info->nodesize * - RELOCATION_RESERVED_NODES; + rc->block_rsv.size = rc->extent_root->fs_info->nodesize * + RELOCATION_RESERVED_NODES; ret = btrfs_block_rsv_refill(rc->extent_root->fs_info, - rc->block_rsv, rc->block_rsv->size, + &rc->block_rsv, rc->block_rsv.size, BTRFS_RESERVE_FLUSH_ALL); if (ret) return ret; @@ -3697,8 +3693,8 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) while (1) { rc->reserved_bytes = 0; - ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv, - rc->block_rsv->size, + ret = btrfs_block_rsv_refill(fs_info, &rc->block_rsv, + rc->block_rsv.size, BTRFS_RESERVE_FLUSH_ALL); if (ret) { err = ret; @@ -3818,7 +3814,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) set_reloc_control(rc); btrfs_backref_release_cache(&rc->backref_cache); - btrfs_block_rsv_release(fs_info, rc->block_rsv, (u64)-1, NULL); + btrfs_block_rsv_release(fs_info, &rc->block_rsv, (u64)-1, NULL); /* * Even in the case when the relocation is cancelled, we should all go @@ -3834,7 +3830,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) rc->merge_reloc_tree = false; unset_reloc_control(rc); - btrfs_block_rsv_release(fs_info, rc->block_rsv, (u64)-1, NULL); + btrfs_block_rsv_release(fs_info, &rc->block_rsv, (u64)-1, NULL); /* get rid of pinned extents */ trans = btrfs_join_transaction(rc->extent_root); @@ -3849,7 +3845,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) ret = clean_dirty_subvols(rc); if (ret < 0 && !err) err = ret; - btrfs_free_block_rsv(fs_info, rc->block_rsv); + btrfs_block_rsv_release(fs_info, &rc->block_rsv, (u64)-1, NULL); btrfs_free_path(path); return err; } @@ -4575,7 +4571,7 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, if (rc->merge_reloc_tree) { ret = btrfs_block_rsv_migrate(&pending->block_rsv, - rc->block_rsv, + &rc->block_rsv, rc->nodes_relocated, true); if (ret) return ret; From patchwork Fri Sep 22 19:10:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13396359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B0B6CD4852 for ; Fri, 22 Sep 2023 19:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233647AbjIVTRP (ORCPT ); Fri, 22 Sep 2023 15:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233627AbjIVTRO (ORCPT ); Fri, 22 Sep 2023 15:17:14 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0926A3 for ; Fri, 22 Sep 2023 12:17:08 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9D0CE1FE33; Fri, 22 Sep 2023 19:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695410227; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YOXh5K+JZEgsMnRMob8VwviO9Zjo3VWQfo86OSJO4yE=; b=UOfopOtsbygOubabvr/IuPR8XnP/kFMYUqmYpMKTzAbtc8j8JbhBtwSKRXnZmLyiBcQGXB MTSi5UCHfXt9W+prt/T19JEPGMAS0HfE843NzmV59qwKe/0zUEKjkXPtUeiWaooioUzVcg xTSqQaijCSb9p7HKCr4CT4t9YhNZECY= Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id 82CA02C142; Fri, 22 Sep 2023 19:17:07 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 68650DA832; Fri, 22 Sep 2023 21:10:33 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 5/5] btrfs: remove unused alloc and free helpers for block group reserves Date: Fri, 22 Sep 2023 21:10:33 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There are no remaining users of btrfs_alloc_block_rsv() and btrfs_free_block_rsv() after conversions to on-stack or embedded variables, so remove them. Signed-off-by: David Sterba --- fs/btrfs/block-rsv.c | 22 ---------------------- fs/btrfs/block-rsv.h | 4 ---- 2 files changed, 26 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index ceb5f586a2d5..9cb32301e92a 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -190,28 +190,6 @@ void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info, BTRFS_BLOCK_GROUP_METADATA); } -struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info, - enum btrfs_rsv_type type) -{ - struct btrfs_block_rsv *block_rsv; - - block_rsv = kmalloc(sizeof(*block_rsv), GFP_NOFS); - if (!block_rsv) - return NULL; - - btrfs_init_metadata_block_rsv(fs_info, block_rsv, type); - return block_rsv; -} - -void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info, - struct btrfs_block_rsv *rsv) -{ - if (!rsv) - return; - btrfs_block_rsv_release(fs_info, rsv, (u64)-1, NULL); - kfree(rsv); -} - int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *block_rsv, u64 num_bytes, enum btrfs_reserve_flush_enum flush) diff --git a/fs/btrfs/block-rsv.h b/fs/btrfs/block-rsv.h index b0bd12b8652f..f1f52a21682a 100644 --- a/fs/btrfs/block-rsv.h +++ b/fs/btrfs/block-rsv.h @@ -53,13 +53,9 @@ struct btrfs_block_rsv { void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, enum btrfs_rsv_type type); void btrfs_init_root_block_rsv(struct btrfs_root *root); -struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info, - enum btrfs_rsv_type type); void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *rsv, enum btrfs_rsv_type type); -void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info, - struct btrfs_block_rsv *rsv); int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *block_rsv, u64 num_bytes, enum btrfs_reserve_flush_enum flush);