From patchwork Tue Dec 10 19:06:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roger L. Beckermeyer III" X-Patchwork-Id: 13901934 Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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 D92F3194080 for ; Tue, 10 Dec 2024 19:07:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857635; cv=none; b=rnwM61/zvVi1gRRl7I/+G6A021E1Wv7RoHJuWEIqiRli4VzJRMeJh6tB/NRquz33/P52hr/OHUif8Qqgm0EPUFrgmzb557fMy+MzMJzu7pC9TWJZgIjJAmMWFB9htdJEWIEhQWALATqLZ21ozvjCs5DYrsO77zgaJJCIeNlvH4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857635; c=relaxed/simple; bh=By8mpbQ7VBmZbkBzf3n0bpLF3tVeR2hfOpb9yBxOGXM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jn1In3C6ImIer4xB3KvTOtlXKRPcoL8kcVk5uhRxMaPdNvFn9qDy9lJRjv+0FvYQ5pg2Y9Y7LwjeZ8gE4g0ACztoxzTHCXk1EfSxChS19v47K+pFurid8fWz32s8xUrW8gXTZfYTglMOfN1mHKWXGVjtO+P/xhRcalykrHN7Cxk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N6l07+1+; arc=none smtp.client-ip=209.85.166.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N6l07+1+" Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-8418a2f596fso184967539f.1 for ; Tue, 10 Dec 2024 11:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733857633; x=1734462433; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tJpi7HTzmASriu0LWxSoUvvkiz2lc3vNSEY919+be6k=; b=N6l07+1+MWJbSxUuB+BT/4JJzFEcltagSHCcwKYCp9sjLu4GrtmnYwl/oM9fceF5as mrD+0iH1bTMDVypZwF4pFaC5KwpTKs+pCRfrxdrkh+aF+IFSE6CdK/M4vODwz0+cpa9D uXS/C8cCvblFvxS56/D4zItKlgbIRDi4gVr073YES59PY/ptd1BY3Mc2+KTY/tOMCeyE fC0wZNXy2pjSpNxm5rcfQYnKIdEHWe8San/So1wKkgpp4zsZGtTwBENXLZXBMFxAkYUk xv/U6gw3J+3sKSSFFU6R9RJ68r2vT9OnEfMg37uU+fsP7LSeOGIJe+pXT3RpM2ef05vV JQYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733857633; x=1734462433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tJpi7HTzmASriu0LWxSoUvvkiz2lc3vNSEY919+be6k=; b=Wt/e1tLfYWOxv9acZQrd5E/W1sMDxysyeoKbz1pYHGj/9N/FnQIfYFYYvzp7B/VZQj JpLOCsJ3ags88zLmpWRotQRfoFGnv0z0VStgxGWyX4D5obJ7hQhJuSxfUWlYNueSKA2W yURCstdIwP5qbhOiWb1TJ0vxr42T/MyVbZNy07ooyh+qw8CjTd47ygwCRTEu7pGVJCT4 KBo/3vNohgAVPTX393w1puO/crcTlUSSbOZGDWL7MFSVAGW+I1YExeiD3yzVli4p6cBc /wwoHxyLvdWD5DMWlFWT98kuPlWKn/xX9v6rFhf8MqxwSFEXyxq1/ATbnxzYXNcDsi8V cU1Q== X-Gm-Message-State: AOJu0YwHIKN6qJ7YmLrDQVr8jNsdB/L2i3p0KKnyF7n0EAoQ/BIxegF0 Y6xAxyCZgNTVJeI8AjRbLpJr12QcRSJ1DeLbEawvIEqzurEwzv5I4M/Rdnl/ X-Gm-Gg: ASbGncvR5iE9+anMOTXekpUXueWJUu6cJbfuzZRGRPPoEONgnMZXr3sASuiOJPiWgd0 U3VhW9cZ8NrRvtwNYx347a8Fm2OJ/C4LFYeB7Ln9X4Of2SnjNWCJtjfyE1SxfaBNevwH+DQL936 w88TQH63Amm3AVcmdxaev+QWl/MINNeDbTgo9ntFZClKonwN7Tm+vJrkj2UrVlKP9ZBf0m469ne D20b9W9xVsc/kTDn81PbDmV3JPbaClElAW6dvfQ0Yu0s74/5Cv7gvzMVGxvhIk= X-Google-Smtp-Source: AGHT+IHvrrak7pj0ExjTUBiv1KclUcPXD8vLwe/cXM/CvxL5Gm83lXVmjRHY9BGdIUNuS72g8cZTQA== X-Received: by 2002:a05:6602:2ccf:b0:843:ec8d:be00 with SMTP id ca18e2360f4ac-844cb691d42mr54584839f.13.1733857632600; Tue, 10 Dec 2024 11:07:12 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844cb2611b5sm7044839f.38.2024.12.10.11.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 11:07:10 -0800 (PST) From: "Roger L. Beckermeyer III" To: linux-btrfs@vger.kernel.org Cc: "Roger L. Beckermeyer III" , kernel test robot , Josef Bacik Subject: [PATCH 1/6] rbtree: add rb_find_add_cached() to rbtree.h Date: Tue, 10 Dec 2024 13:06:07 -0600 Message-ID: <4768e17a808c754748ac9264b5de9e8f00f22380.1733850317.git.beckerlee3@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds rb_find_add_cached() as a helper function for use with red-black trees. Used in btrfs to reduce boilerplate code. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202412092033.josUXvY4-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412091004.4vQ7P5Kl-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090944.g3jpT1Cz-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090919.RdI1OMQg-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090922.LHCgRc17-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412091036.JGaCqbvL-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090921.E0n0Ioce-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090958.CtUdYRwP-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090922.Cg7LuOhS-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202412090910.F5gin2Tv-lkp@intel.com/ Suggested-by: Josef Bacik Signed-off-by: Roger L. Beckermeyer III --- include/linux/rbtree.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h index 7c173aa64e1e..0d4444c0cfb3 100644 --- a/include/linux/rbtree.h +++ b/include/linux/rbtree.h @@ -210,6 +210,43 @@ rb_add(struct rb_node *node, struct rb_root *tree, rb_insert_color(node, tree); } +/** + * rb_find_add_cached() - find equivalent @node in @tree, or add @node + * @node: node to look-for / insert + * @tree: tree to search / modify + * @cmp: operator defining the node order + * + * Returns the rb_node matching @node, or NULL when no match is found and @node + * is inserted. + */ +static __always_inline struct rb_node * +rb_find_add_cached(struct rb_node *node, struct rb_root_cached *tree, + int (*cmp)(struct rb_node *, const struct rb_node *)) +{ + bool leftmost = true; + struct rb_node **link = &tree->rb_root.rb_node; + struct rb_node *parent = NULL; + int c; + + while (*link) { + parent = *link; + c = cmp(node, parent); + + if (c < 0) { + link = &parent->rb_left; + } else if (c > 0) { + link = &parent->rb_right; + leftmost = false; + } else { + return parent; + } + } + + rb_link_node(node, parent, link); + rb_insert_color_cached(node, tree, leftmost); + return NULL; +} + /** * rb_find_add() - find equivalent @node in @tree, or add @node * @node: node to look-for / insert From patchwork Tue Dec 10 19:06:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roger L. Beckermeyer III" X-Patchwork-Id: 13901935 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (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 3C3182046AE for ; Tue, 10 Dec 2024 19:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857636; cv=none; b=t4e8whTP5bnBOI9fWiJN1YrliK6J/6v+ePyO6bl+Fr92BBtZ4uQ8HoDpH/JN6IMXyQCs4r7Cir6xuuaKWixLiWRLQYn5vBonCEH2gJwqqFxttxrUvjMg/3gSp9msNoxjnuMVKL8bEYIijfB1PGkNEPpHu1IUDYS4YQg8YwkMLG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857636; c=relaxed/simple; bh=0USXxJsPG17IwkGkOz+XYdZWoS8GQB32P/NpsIN6bwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V9ZmO31dJtuDJYC7e/5dgA2ClKUxQkhPP6BHxFVjuSrxZUkOu5AnIP9y/XrGf1X39GjT5khLeP/P1S7NPj7946ziS02HXTvSg6Oao9TzPM9rRDyRVq8Z+PsLOWXY+45mhX16o6i0biL0MD21GePZ0aKDCcpsRZRxfbJZr9r4dwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=efkht6Ax; arc=none smtp.client-ip=209.85.166.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="efkht6Ax" Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-844c0547717so60732939f.3 for ; Tue, 10 Dec 2024 11:07:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733857633; x=1734462433; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=coDBx/pjraEIem/UXRQljsqpBGD/05jQgXXpDtPUOio=; b=efkht6AxYpZaObUzouwKcHvwkr6q3fNmV2BQ4d4sShU0SJoQkEWiJdMFQcDsm3cYED toP7uwPbYThxSak3n9JXnlgOfn9flSRHjizlccT5Jb8r8fq9PPItKaQ3wHpDSRH4fdD/ GA8mfYnD59b+2Jnjn1HOmwY42Dhh4BP9g3NF2RZvRv5H26CLtsoflrLpwVAzBOTlLOU8 IJX3qkGrzX6bDsSJh6p4YVXvECNtflnYza4A1pTPJEKcph4b8dUnfpLrvIE/Xoo8cHF5 cRKHkdnQbgpcgGaa+tKoYpU1nokNboEWj3UR336+Yxg3G5PquEjtAbi5R8BqyiS0TXy8 BVdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733857633; x=1734462433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=coDBx/pjraEIem/UXRQljsqpBGD/05jQgXXpDtPUOio=; b=ox0odEHBMtF7us8RTy8abLVVxvMH2X6FNmzG3PVwT/ZG6p7tm8QI+Q+WuogjqRX/7E adMW4pWppeEsRLkGmifHkwhWWmiB/U9PvTFCbdf+NI2IGSpjK2q54IIimduvea9w4qV5 /7B10fSCMeFidgKOWHGLKxZjbdWyhEokqnLuF0bIu/4Hpy2c9RdHgoqJS2CaVwtj9URm EFti9PiZK3Mknz6r2Y4toWJvpxmETD5SU12i1A8Ka6MjmVVfP2Sh7tXSNhmmH2yg01P3 KSRtspCSThmN6D60RosNhY6OcgrPJ9Jhk7v5VOK0MC4A/5/3jc3oIdSJWGahjbU5K1/N mb7g== X-Gm-Message-State: AOJu0YxMfo1m8q52W3vpTiYHdnpgwUtSKGVoj6AfBJr1Sl5JKALFBCsk pxq/TutX/lKJV6XK9ArpHMZNdYUSUgbLL4urr1fHnF5nUBxliDZH2b5sHm0h X-Gm-Gg: ASbGnctchONroVqibnwrwTLuZe0HPbqgtdsNlVFDqnOCh+ZFJhzmyYgtHlQDLmEJeas cVfROvWDovW95zUNZ+8kb4k4+5CbrBvMJVJWIhhw6masNVZ6HGhaj36cMImaCD5hOyQrhs9i3cc e3n2V6wjdS0I38ZvkwXOsiwJLRByWHgpLRosc9PRBkE4gBO0CvHGaeyyadav3Kzl0Q+s7EIE8ww PBaDhvD4NtM1GoUpB0EqgLieREktTqmIhI8wgm26JQzws9OAeRlbNiEARfrjPU= X-Google-Smtp-Source: AGHT+IH5BghPn5k/nDa0URkP8U4o8SrT5C+LUM+b/82jUWB6gpkkz2o73tj8/EH6GyJdXOSt7u/zxg== X-Received: by 2002:a05:6602:27c6:b0:843:ec8f:c84a with SMTP id ca18e2360f4ac-844cb5c7f7dmr68179739f.6.1733857633606; Tue, 10 Dec 2024 11:07:13 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844cb2611b5sm7044839f.38.2024.12.10.11.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 11:07:13 -0800 (PST) From: "Roger L. Beckermeyer III" To: linux-btrfs@vger.kernel.org Cc: "Roger L. Beckermeyer III" , Josef Bacik Subject: [PATCH 2/6] btrfs: edit btrfs_add_block_group_cache() to use rb helper Date: Tue, 10 Dec 2024 13:06:08 -0600 Message-ID: <2c3972c084ab074fd1b6a2e03ada8c20dde6d060.1733850317.git.beckerlee3@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Edits fs/btrfs/block-group.c to use rb_find_add_cached(), also adds a comparison function, btrfs_add_block_blkgrp_cmp(), for use with rb_find_add_cached(). Suggested-by: Josef Bacik Reviewed-by: Roger L. Beckermeyer III Signed-off-by: Roger L. Beckermeyer III --- fs/btrfs/block-group.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 5be029734cfa..ccff051de43a 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -173,40 +173,34 @@ void btrfs_put_block_group(struct btrfs_block_group *cache) } } +static int btrfs_add_blkgrp_cmp(struct rb_node *new, const struct rb_node *exist) +{ + struct btrfs_block_group *cmp1 = rb_entry(new, struct btrfs_block_group, cache_node); + struct btrfs_block_group *cmp2 = rb_entry(exist, struct btrfs_block_group, cache_node); + + if (cmp1->start < cmp2->start) + return -1; + if (cmp1->start > cmp2->start) + return 1; + return 0; +} + /* * This adds the block group to the fs_info rb tree for the block group cache */ static int btrfs_add_block_group_cache(struct btrfs_fs_info *info, struct btrfs_block_group *block_group) { - struct rb_node **p; - struct rb_node *parent = NULL; - struct btrfs_block_group *cache; - bool leftmost = true; + struct rb_node *exist; ASSERT(block_group->length != 0); write_lock(&info->block_group_cache_lock); - p = &info->block_group_cache_tree.rb_root.rb_node; - - while (*p) { - parent = *p; - cache = rb_entry(parent, struct btrfs_block_group, cache_node); - if (block_group->start < cache->start) { - p = &(*p)->rb_left; - } else if (block_group->start > cache->start) { - p = &(*p)->rb_right; - leftmost = false; - } else { - write_unlock(&info->block_group_cache_lock); - return -EEXIST; - } - } - - rb_link_node(&block_group->cache_node, parent, p); - rb_insert_color_cached(&block_group->cache_node, - &info->block_group_cache_tree, leftmost); + exist = rb_find_add_cached(&block_group->cache_node, + &info->block_group_cache_tree, btrfs_add_blkgrp_cmp); + if (exist != NULL) + return -EEXIST; write_unlock(&info->block_group_cache_lock); return 0; From patchwork Tue Dec 10 19:06:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roger L. Beckermeyer III" X-Patchwork-Id: 13901936 Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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 592AB214213 for ; Tue, 10 Dec 2024 19:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857638; cv=none; b=f2ug3cLcMEhO2roLiyGmJE4xxRZ1d72MqJvdjL6qFmJ5XTl5+0YbjcURXi39Qcbz1dG9URb5oPbMyZfsBql6xTsq+yZJfLqGnzDYHfRjvqBnJzu/SFLMCKKVwzN3ctGSXPeygBOVp7dEcrr0thC2gfton3lfg0yye/wWE+tISVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857638; c=relaxed/simple; bh=u9SEzsD1bJdvCYbsjeBjErmtk/VKVnl1hVIWJa9mayc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kP5960W785rOOEtRaOgr5Lvgv+9BTg9rWj1SKKeIQtnCZ+PhJBs1e+PjS++KFYqv/oPCGf1PP2wLsA4EHtNnAnKsXPU/2/hqv1I4dDzy1WwkcTwU8NaNsr11q8WV/IArzuVDAgSEa4FLgvbyn+drXEofQ6vPF0lIheUx1ywLAzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=atPy+8JC; arc=none smtp.client-ip=209.85.166.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="atPy+8JC" Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-843d7f16827so220849039f.0 for ; Tue, 10 Dec 2024 11:07:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733857635; x=1734462435; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YIWsXL+UkpVmQB5Hmm8YTXoe3HdC01zMWfLyVamraQ0=; b=atPy+8JCHg4UnsFiG32+yJm8xR7DN5MRfMMtdTTS7ok7S4sUfpl53FFPqwaNTQP+k+ /bTYV1HU4N0U3qSzuuJChL+R2l8O/RoMtg745gIN/wFWB6wALG6fk1fTWNr3q8n8XatI B6544uGU0QqlLtBr9VvWiD64MOstzdZO3KDUEVsxomZslpo/KntZCk127L5sW37o2tAM 8fY5FLMflJJs83h4su5HQJq5epToAQdz2L00ZLL8mQc+DEn8Jj2nA0GDvImS7A4wz3qT b2rLebYyLYwRNSQ19PGSL+MdHhK9x5pEZH70+vMGevBYXBchp6WnrdUFjDxlRA1uI5Xa 1AbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733857635; x=1734462435; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YIWsXL+UkpVmQB5Hmm8YTXoe3HdC01zMWfLyVamraQ0=; b=WkJb/PDM1wusN5sucshDUgRNIu+N3LFjCV7iNDfBtNmRT9OTnygA4L+SNjLCNnM9oc osYroH/n+rOXG3YtI8uYANzX5TQnO76XZkynFdTuc9gSlF+czt+nduAkHiiDX6AlIKvi sWVDQxdMGu5xei+vudGdD+nz992CNF0E0GfSTNVoNSH5LL8we2yYzDoBKKOpuMw9xUBE 089+YArVYwL7nAT6qOpMUd9+I/SV1SEwJSEkZy8P8XVfFNr1ryB4M2Cd22oBuQP82ub1 hzg16cVSrU8MAeKhNhNHQ4xLcglD4y7D3ixKVo6fFLEM9S6vYYtuaOtW0VHdGR7qBwsb Bl4Q== X-Gm-Message-State: AOJu0YyDt+Ccs8vyQLgIOhx9AAdZwOnznsuEuIMja1OXn/2/9u1xD9D1 07j5ZpbL44OgLW9uYwiOI0zXAg/6lESM0sZvj8DBD/nGtr2DaMrhW5K/hA== X-Gm-Gg: ASbGncu5A9zI6W/LldmbyzsfSAoEwFjrM1PT0/i+iZXZQGGPk9csh4P5/pE2232fKO7 ZQDI9K128qMw9Mi/DxiIXcWzUOijJCsIXHUIU8AUHDx8FP2Mz4DngDPO+CVRs80d54ATsmUuB75 ZN/dtLvXARqnjfDlp0NtfnFza9WajMnNXktG3JS/3oDwOIbGO2ExPle+4arcLqWdaUpQE3K5S0K Pf0btoXX1oly3pOmGHTJP1bCPVhCNelRdIY/vchwAkttMgj+KeJz4B1A6ZQ+1U= X-Google-Smtp-Source: AGHT+IFsyINSKnNX/YJZhJVLttdU59Qwni+tzyDt2jgXpqDxnA+zcaDpNNycrMkWMqR2dsgH/XznyA== X-Received: by 2002:a05:6602:280a:b0:844:cbd0:66cb with SMTP id ca18e2360f4ac-844cbd0689emr31615439f.2.1733857634875; Tue, 10 Dec 2024 11:07:14 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844cb2611b5sm7044839f.38.2024.12.10.11.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 11:07:13 -0800 (PST) From: "Roger L. Beckermeyer III" To: linux-btrfs@vger.kernel.org Cc: "Roger L. Beckermeyer III" Subject: [PATCH 3/6] btrfs: edit prelim_ref_insert() to use rb helpers Date: Tue, 10 Dec 2024 13:06:09 -0600 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit edits prelim_ref_insert() in fs/btrfs/backref.c to use rb_find_add_cached(). It also adds a comparison function for use with rb_find_add_cached(). Signed-off-by: Roger L. Beckermeyer III --- fs/btrfs/backref.c | 71 +++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 6d9f39c1d89c..fcbcfce0f93a 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -250,6 +250,17 @@ static int prelim_ref_compare(const struct prelim_ref *ref1, return 0; } +static int prelim_ref_cmp(struct rb_node *node, const struct rb_node *exist) +{ + int result; + struct prelim_ref *ref1 = rb_entry(node, struct prelim_ref, rbnode); + struct prelim_ref *ref2 = rb_entry(exist, struct prelim_ref, rbnode); + + result = prelim_ref_compare(ref1, ref2); + + return result; +} + static void update_share_count(struct share_check *sc, int oldcount, int newcount, const struct prelim_ref *newref) { @@ -281,52 +292,42 @@ static void prelim_ref_insert(const struct btrfs_fs_info *fs_info, struct rb_node **p; struct rb_node *parent = NULL; struct prelim_ref *ref; - int result; - bool leftmost = true; + struct rb_node *exist; root = &preftree->root; p = &root->rb_root.rb_node; + parent = *p; + ref = rb_entry(parent, struct prelim_ref, rbnode); - while (*p) { - parent = *p; - ref = rb_entry(parent, struct prelim_ref, rbnode); - result = prelim_ref_compare(ref, newref); - if (result < 0) { - p = &(*p)->rb_left; - } else if (result > 0) { - p = &(*p)->rb_right; - leftmost = false; - } else { - /* Identical refs, merge them and free @newref */ - struct extent_inode_elem *eie = ref->inode_list; + exist = rb_find_add_cached(&newref->rbnode, root, prelim_ref_cmp); + if (exist != NULL) { + /* Identical refs, merge them and free @newref */ + struct extent_inode_elem *eie = ref->inode_list; - while (eie && eie->next) - eie = eie->next; + while (eie && eie->next) + eie = eie->next; - if (!eie) - ref->inode_list = newref->inode_list; - else - eie->next = newref->inode_list; - trace_btrfs_prelim_ref_merge(fs_info, ref, newref, - preftree->count); - /* - * A delayed ref can have newref->count < 0. - * The ref->count is updated to follow any - * BTRFS_[ADD|DROP]_DELAYED_REF actions. - */ - update_share_count(sc, ref->count, - ref->count + newref->count, newref); - ref->count += newref->count; - free_pref(newref); - return; - } + if (!eie) + ref->inode_list = newref->inode_list; + else + eie->next = newref->inode_list; + trace_btrfs_prelim_ref_merge(fs_info, ref, newref, + preftree->count); + /* + * A delayed ref can have newref->count < 0. + * The ref->count is updated to follow any + * BTRFS_[ADD|DROP]_DELAYED_REF actions. + */ + update_share_count(sc, ref->count, + ref->count + newref->count, newref); + ref->count += newref->count; + free_pref(newref); + return; } update_share_count(sc, 0, newref->count, newref); preftree->count++; trace_btrfs_prelim_ref_insert(fs_info, newref, NULL, preftree->count); - rb_link_node(&newref->rbnode, parent, p); - rb_insert_color_cached(&newref->rbnode, root, leftmost); } /* From patchwork Tue Dec 10 19:06:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roger L. Beckermeyer III" X-Patchwork-Id: 13901937 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 A8C9C2046AE for ; Tue, 10 Dec 2024 19:07:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857640; cv=none; b=c9C5duJoOLNVu+60rvRo5G4Ol+n7oIplv2rAjsS/FNPg/pPCG7L9oAhHV9VdIEGPdC7cOqEiVwr6c6JD2o8qZ8t1owOxQdY/S2ycIack6RLWuL0oKWmIjZAJqsdqHB5bx/IiXDBonYipqK/owuUBqNhoQ5Wx7jycTVa8HXFSq6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857640; c=relaxed/simple; bh=g2u5ICgSwJ+jY8DpCTuuvJwLuK1LmosHHuopMy5AU3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t2nGc8ds/arNPe5Knv4xGB/wcYj34fB1BuSwT2XwQbF0pnszxwnfEihK/LrFdcZNabNq3vQfaZO0kT/0gBUxeWXUmAtVnAvyWD1SU7Z1ZzQgZrpYK7L7JRt///FtanXlmh4nsyA1MYCZqbNIyQ8TTkA1MDB6UTtO1+S23xWSHEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UvnBlLfR; arc=none smtp.client-ip=209.85.166.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UvnBlLfR" Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-843e9db3e65so213589739f.1 for ; Tue, 10 Dec 2024 11:07:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733857637; x=1734462437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ci4fxMwTROvKHzo/u+oWA7qVLhZcwhboGlFW8NsFTnE=; b=UvnBlLfR0rz72jT/UFJzinWtwryTPoRL5ubDYpmU2hp/qoDZOukXnQEIcxptnNhd5T rirfVjqgJwh+VPLivoY5QTGxt8JNTcsLpY6OI2JyNhT2mmyA9qmNSmP8n5MHPyGyc27A VAiPNfuiK5khss59hTXvXBlxrlAttB3UQuBMqZNHFGVpUGFIB6aV7Fu4SSIcdWgADlSu saseRYMkQ9PBw/jao2Qv29Iq1YQea6nct6XObpiZJ4OhXjW3rBqJ3sACWvkyqQbw77Xr 8JJkE728YJtC1LaRkj5Nv8hogPiEdjX55tDgZWRO994LfjD0ChUj0OuoInTSlCLGefBr huKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733857637; x=1734462437; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ci4fxMwTROvKHzo/u+oWA7qVLhZcwhboGlFW8NsFTnE=; b=JeZ8T2DUai/X9EfeWvGJC001OwfMFnTUsPt7ULnV2QLfy2+ZNX+cSR1BaGN9dZuNd0 c/tldRqvtILu4aW9PT8rXaHQqewHVf8OFCnRHkBcppXW/8JbR7EUJh4nICiPNlpacQwg 2z3/1rD/dgFrxfTdS1h7t7neMihKyRxSrXdF1BdhDjGKipsnllgqgRFRWRm/IMPx0LV9 5F1JaOuDYVqfNgKpzwPPjqUEtWV0rAUMY8Lzay8vjUoi1MLKDLoQRI7vk80V+Jn4AGi4 76Do6Le/uCyRsu8R8/hYjXh/qchzuwPXbu+GtKBXk7OR2Kx8a2m/1EBPCGsEOVlBu48Y KmNA== X-Gm-Message-State: AOJu0Yx8aPC27dqwbRIuyPiUPRgL4kT9xmiIdEPFNry6vrDlMkEVX7y9 UJJtcHPVINg3PVRuvLIpF2TTGHOPFeFD+jpZLsbDBhIQLOU2dmXdNQjOBg== X-Gm-Gg: ASbGncv90oCdlRca6oET1TkcOWfZ9ZSvFUKTfdLpRe6GYd68X2EoZtRIE1kSQCNf/8p 6VsACt2i5WuOY+tozQv7uJB9LjqsFOz53QDcrcgknAq5buRvmZCLL0GztryUNxj2nY+k5G1DOgB GAjUIUNew/7jpLgQCph4u29LWmZJ06mQBrkWpj78CJdgco5eaa7oTOxMY9yJ9cN/jObz5q3+x8N GOAuLB2hVG0ZGsc2lhWejPyQ3Fs8Lgx/fuPNWh0i2e92gm3B6xBHGrSQaasp+w= X-Google-Smtp-Source: AGHT+IGVKoxrQ/Vf3WE7Zzj1LHGUGRy6aklgE6IBR5QVgeoGRJqaZbK+C8TdQi1AloKh1Ee+MTWHbw== X-Received: by 2002:a05:6602:6019:b0:844:7896:8cb4 with SMTP id ca18e2360f4ac-844b8804d31mr505804639f.1.1733857637016; Tue, 10 Dec 2024 11:07:17 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844cb2611b5sm7044839f.38.2024.12.10.11.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 11:07:16 -0800 (PST) From: "Roger L. Beckermeyer III" To: linux-btrfs@vger.kernel.org Cc: "Roger L. Beckermeyer III" Subject: [PATCH 4/6] btrfs: edit __btrfs_add_delayed_item() to use rb helper Date: Tue, 10 Dec 2024 13:06:10 -0600 Message-ID: <76d94f40a9c6333e8685375aa998199320b54101.1733850317.git.beckerlee3@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit edits __btrfs_add_delayed_item() to use rb_find_add_cached(). It also adds a helper function to use with rb_find_add_cached(). Signed-off-by: Roger L. Beckermeyer III --- fs/btrfs/delayed-inode.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 508bdbae29a0..7d62224bc49c 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -366,40 +366,32 @@ static struct btrfs_delayed_item *__btrfs_lookup_delayed_item( return NULL; } +static int btrfs_add_delayed_item_cmp(struct rb_node *rb_node, const struct rb_node *exist_node) +{ + struct btrfs_delayed_item *item = rb_entry(rb_node, struct btrfs_delayed_item, rb_node); + struct btrfs_delayed_item *exist = rb_entry(exist_node, struct btrfs_delayed_item, rb_node); + + if (item->index < exist->index) + return -1; + if (item->index > exist->index) + return 1; + return 0; +} + static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node, struct btrfs_delayed_item *ins) { - struct rb_node **p, *node; - struct rb_node *parent_node = NULL; struct rb_root_cached *root; - struct btrfs_delayed_item *item; - bool leftmost = true; + struct rb_node *exist; if (ins->type == BTRFS_DELAYED_INSERTION_ITEM) root = &delayed_node->ins_root; else root = &delayed_node->del_root; - p = &root->rb_root.rb_node; - node = &ins->rb_node; - - while (*p) { - parent_node = *p; - item = rb_entry(parent_node, struct btrfs_delayed_item, - rb_node); - - if (item->index < ins->index) { - p = &(*p)->rb_right; - leftmost = false; - } else if (item->index > ins->index) { - p = &(*p)->rb_left; - } else { - return -EEXIST; - } - } - - rb_link_node(node, parent_node, p); - rb_insert_color_cached(node, root, leftmost); + exist = rb_find_add_cached(&ins->rb_node, root, btrfs_add_delayed_item_cmp); + if (exist != NULL) + return -EEXIST; if (ins->type == BTRFS_DELAYED_INSERTION_ITEM && ins->index >= delayed_node->index_cnt) From patchwork Tue Dec 10 19:06:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roger L. Beckermeyer III" X-Patchwork-Id: 13901938 Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) (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 84A4A214225 for ; Tue, 10 Dec 2024 19:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857641; cv=none; b=f+1Lhh8LfzKJG+4aLT3YhUjFVuMe69FDn9HBphGZEdVsSN1O/QU5prsD5E5zsYZUUOZz7XYaZjyfh6HbbZ73r0oTHLBMJVnYHBU0Hq4AEOkdYpqpBw22BWQr65cPtxZacPs4vkWn9OV+YM9aKYII8ptOLYXUMLCNTA9dSjWfp2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857641; c=relaxed/simple; bh=f8zqfLDbVbo6pVP8+8i1UClt68Hb+1fTkJKIoUaUkvE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ScGskLpzsXApi/wbWM33L8xuw16OilFXux+YRQP8fey666dueB2v11ykqwDlyyCXjC7ZYsVo8yVnBN+HGphN6bspxoTkBPZTJSI3E+2g6ucGzksWCQKtJ5x4mzNUBNKAKiY9exQByfHccSGRTSDkKZqAfWOKdXHjHjfQFculzho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PZRq16Bt; arc=none smtp.client-ip=209.85.166.42 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PZRq16Bt" Received: by mail-io1-f42.google.com with SMTP id ca18e2360f4ac-841a565f871so292337939f.1 for ; Tue, 10 Dec 2024 11:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733857638; x=1734462438; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gyF61UPlwTPl6abI/g9ou4p5GQJQbBZfjdnOgGeqJFY=; b=PZRq16Btljqmzug7FGu8ZrFxRd7K59B5HUUPuICBp7cCf0a8VvLwhhkmrZtzksUU8l I6Cf94lo+WtiSK0UkPXIGkMvEJMBHFrjWUefS/9UYDXq3s9/9QFqExiXXZ9QDoVzrb0V 0PrY8b/ubT/jkYOLdbwtTO1T6zL9Rt7FhVVJkZi2qpWPYfG3ayBZkwHultVXImdNtqTR 7yq+WMs7AStf7Onp/ePDHTHXOfMw+cCzeaHyM4oeml5x+gkF5FKz+hz+8caPU3yeuETN Tpy0zRyaqtkFdrGtfVpp13M3+l3uj7p0R9V8AO6abLKQJ2JBVJIAbyQni76RSd5DLkcg bgdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733857638; x=1734462438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gyF61UPlwTPl6abI/g9ou4p5GQJQbBZfjdnOgGeqJFY=; b=gZ5NRS2jJo4sxemTXE6VgXyiVcIzwbdCuRVwbs/GB6chQk0et9g/Obd139vh0bqtU3 riGPi2Jq9k6vW87hzPoBNJ43lhfr4LCGcWaVs7gUxk1wjYjzmTLw1g1a09ThkrkSKbfE xvrCyk9XDt2Fz3qVp397gFoK9t3bReYytBjbHvJdS7HrhK1Oxv6npqvYyaLFbJuBGQDM OL8Ri6jSb/1BifyLGHguglpz5csSDPyZRkfmzbCGOTEYI5WnIHsgwIHyAkgQ+auGRjDL mqAF8PX80gynZk9qxtiCz2FHE2RPx8HMeb8fiaXxgr42RahcEepnU0bQMikJijhdN8pS 5cWg== X-Gm-Message-State: AOJu0YyczrKEp99gpKUYemw65mAqr0LOfLv+QCxPzWmO38ON95gJQC6k 0o8auNg7S0Yvg7IwyAGWyZ5zjGKTB0j3ymEAo6wipNJIq0WCwf+6eH5QWg== X-Gm-Gg: ASbGncvwcr6TtTa4QOFLCeZ7rIPEfdXCaWhWKhXlsMTqwk1H9VHiokuixdti2PCoM+1 NEPtZEGhukb2R3Isu7F90RAgnT10jauY3oErUaBooBF50F3lp3vgRjsZHZ5wpBHq2ys02pCFKTy oHvTtesH0sIYZiYyGf/mWyV1t+i0Fvx1aKne0q9FBnxv/np/IciLEnyoiU/NnreMadm9PCmFKLm tDTAi3F+oQ3oh1/YKs72Bga8F6+plWJqdvdAhC+L4iKRc1RvN2jo6yoG1EPJJ0= X-Google-Smtp-Source: AGHT+IE9ezKhUgqWL2Je4ErOKNjh+Ya+8bVJT2btugSNMKPPPChgRYFIWU2sikUWCdnDjGwQqPq7oQ== X-Received: by 2002:a05:6602:26c7:b0:83b:a47c:dbfd with SMTP id ca18e2360f4ac-844cb5f57ccmr66924239f.6.1733857638325; Tue, 10 Dec 2024 11:07:18 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844cb2611b5sm7044839f.38.2024.12.10.11.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 11:07:17 -0800 (PST) From: "Roger L. Beckermeyer III" To: linux-btrfs@vger.kernel.org Cc: "Roger L. Beckermeyer III" Subject: [PATCH 5/6] btrfs: edit btrfs_add_chunk_map() to use rb helpers Date: Tue, 10 Dec 2024 13:06:11 -0600 Message-ID: <536cfab6a2c1189bfe4e00282a54289fca6afc36.1733850317.git.beckerlee3@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Edits btrfs_add_chunk_map() to use rb_find_add_cached(). Also adds a comparison function to use with rb_find_add_cached(). Signed-off-by: Roger L. Beckermeyer III --- fs/btrfs/volumes.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1cccaf9c2b0d..4837761a56c9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5513,33 +5513,30 @@ void btrfs_remove_chunk_map(struct btrfs_fs_info *fs_info, struct btrfs_chunk_ma btrfs_free_chunk_map(map); } +static int btrfs_chunk_map_cmp(struct rb_node *rb_node, const struct rb_node *exist_node) +{ + struct btrfs_chunk_map *map = rb_entry(rb_node, struct btrfs_chunk_map, rb_node); + struct btrfs_chunk_map *exist = rb_entry(exist_node, struct btrfs_chunk_map, rb_node); + + if (map->start == exist->start) + return 0; + if (map->start < exist->start) + return -1; + return 1; +} + EXPORT_FOR_TESTS int btrfs_add_chunk_map(struct btrfs_fs_info *fs_info, struct btrfs_chunk_map *map) { - struct rb_node **p; - struct rb_node *parent = NULL; - bool leftmost = true; + struct rb_node *exist; write_lock(&fs_info->mapping_tree_lock); - p = &fs_info->mapping_tree.rb_root.rb_node; - while (*p) { - struct btrfs_chunk_map *entry; - - parent = *p; - entry = rb_entry(parent, struct btrfs_chunk_map, rb_node); - - if (map->start < entry->start) { - p = &(*p)->rb_left; - } else if (map->start > entry->start) { - p = &(*p)->rb_right; - leftmost = false; - } else { - write_unlock(&fs_info->mapping_tree_lock); - return -EEXIST; - } + exist = rb_find_add_cached(&map->rb_node, &fs_info->mapping_tree, btrfs_chunk_map_cmp); + + if (exist != NULL) { + write_unlock(&fs_info->mapping_tree_lock); + return -EEXIST; } - rb_link_node(&map->rb_node, parent, p); - rb_insert_color_cached(&map->rb_node, &fs_info->mapping_tree, leftmost); chunk_map_device_set_bits(map, CHUNK_ALLOCATED); chunk_map_device_clear_bits(map, CHUNK_TRIMMED); write_unlock(&fs_info->mapping_tree_lock); From patchwork Tue Dec 10 19:06:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roger L. Beckermeyer III" X-Patchwork-Id: 13901939 Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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 D46F621422D for ; Tue, 10 Dec 2024 19:07:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857642; cv=none; b=HUO0zXEf1EYbJj7NSa2D7MbKRiIN8W31RUoSAzL2LpLTH8ek95iwLWAimvxtIjX57WQxzAxgypG2qMXrVkYOz4hxQIXF55Cj7bP0oWX0skYrayrnAvzeFjwfonGoIe0ZXcRv7j3uqjlIUBcEf2WJ6gInzxRwozqz+IlC4QrmLxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733857642; c=relaxed/simple; bh=QP2Jlvpr1efkA1p8JzqH8bk0pqKU4GIwRrPo7qsvGAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=upwbI7GwnMKcZfDDu2dxbFjb82ZOnkLhfiE9q9AK6ehWxAK8439XvnwIpztHV3uhMTyfyKTl1YjTq3np1ti5Qxoi1SFaun5rkpoPwgsvA+Ip4NOvgX9qSrvj1JE9TsVwV0PgvVsNTTwrcuwUy3PMS4/bl4AMdYyqWXiJBbNOV9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WyjdE/FC; arc=none smtp.client-ip=209.85.166.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WyjdE/FC" Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-84197c469cfso185269839f.3 for ; Tue, 10 Dec 2024 11:07:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733857639; x=1734462439; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tulxANZghOKV09/bXuoCBRca3VDxQt6iE0t/bv0DEWc=; b=WyjdE/FCIlaT2PYiouNIe4SfGVAmiBfLXNJOKCxCjNahyLhLOFKbrWtj/ZP3ERHRVA P2z0ZNF+RMqn6tV2nmooCqsGM+WLgOiYrtBt8eEHh2IXPvUpCpImnz1TXuKBbEWXPIOe 14OjfrRYC/2HdZNTxBXMSkQM/UXF0OIUrVVrOpe6gEk/TAy6TmVA710Hkp4TEgpSvg1i 5Rkrc524hnBlqJhWUMJyBgjIB+5z8q38CBVC245u75azCyKyeNSDZSyq/47LDss1+2gW gvmm9fjJj3DwQUqccUpqdVORCNlUfpMimPQvlgsjSCS7VAtZ92nE+uopoXtoR0fbggnZ fJFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733857639; x=1734462439; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tulxANZghOKV09/bXuoCBRca3VDxQt6iE0t/bv0DEWc=; b=emMFEjsYsCtZEkY9eoaakbD5b53sdsWmrNDyYrFrkRduC/7vbqrLRkFRLHM36kD0+1 Yk0n/NUnHBIUina/wEMULTQ3+A7Zr6WIq9W7oV8MhYTUjlsIMqQESkx89mSbrLqG3QnX EFCiwtNd4eYsKsMpNGK9iNQsG8oLzggOIAy1DxmIUjDCFfIYL2KxX642Gfd2w0MOvJ1b QNMzjVv3TaJPB6kVfMW4PKNt3Grli/I1BLPmj5Ez4iW/9XrrfJvC3xMbCy+AW9Ylg3Kr 5igodF4mbbar5FrPLz5vwEkUAxTBULbOMT+GPc72F5Pe5adS0vt9o0G25pGX31axWA1e M7KQ== X-Gm-Message-State: AOJu0YxfocXWNWxxwQ8xikuuXgdi8Qfvx4ggidFyu1x2kfD3UIk4useh Yh+NYj/p4RRN2FZBPCUhi+rmCqGBIHnSPyPP5kNwpIPqV2kX9wD73+G2xQ== X-Gm-Gg: ASbGnct2yDHqZGAB2/D5eOQp1b6MGQag+8AI5/84BeiYYyH76Zhr2RfBYTA5+SdqvNU kXB4mmDzMoqaivYcV/BPZQUcaf5vRlZneevJgcOiqpeHkpEo0PU+SPS9qBs24WnMDV1wreZlHWy kMuFTOK4iD541OSLPM7XYQtWMZVWBGz8De7gtqAwDCsrUxQVCXaA5O/TkUJaJh4D8AB0mvNJzRM cJ0Ws/iEEbNNL2OPAQZyYNiUP4crAdZiAQr9i580gkJZ/wM/nCnKQu5WdwQaGI= X-Google-Smtp-Source: AGHT+IE1zFU8JqHlMZbV3LITzS5v8HrUs+X7SN9qPo27p4kYFSANrlEwg82YAQEyerBH6mY+p0yLzw== X-Received: by 2002:a6b:f202:0:b0:844:cb6b:56b2 with SMTP id ca18e2360f4ac-844cb6b571bmr46544139f.6.1733857639161; Tue, 10 Dec 2024 11:07:19 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844cb2611b5sm7044839f.38.2024.12.10.11.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 11:07:18 -0800 (PST) From: "Roger L. Beckermeyer III" To: linux-btrfs@vger.kernel.org Cc: "Roger L. Beckermeyer III" Subject: [PATCH 6/6] btrfs: edit tree_insert() to use rb helpers Date: Tue, 10 Dec 2024 13:06:12 -0600 Message-ID: <29decaada3411dbc4c4516141a3ec7391a91e961.1733850317.git.beckerlee3@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Edits tree_insert() to use rb_find_add_cached(). Also adds a comparison function for use in rb_find_add_cached() to compare. V2: incorporated changes from Filipe Manana Signed-off-by: Roger L. Beckermeyer III --- fs/btrfs/delayed-ref.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 30f7079fa28e..e288058f5c3c 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -317,34 +317,27 @@ static int comp_refs(struct btrfs_delayed_ref_node *ref1, return 0; } +static int comp_refs_node(struct rb_node *node, const struct rb_node *node2) +{ + struct btrfs_delayed_ref_node *ref1; + struct btrfs_delayed_ref_node *ref2; + bool check_seq = true; + + ref1 = rb_entry(node, struct btrfs_delayed_ref_node, ref_node); + ref2 = rb_entry(node2, struct btrfs_delayed_ref_node, ref_node); + + return comp_refs(ref1, ref2, check_seq); +} + static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root, struct btrfs_delayed_ref_node *ins) { - struct rb_node **p = &root->rb_root.rb_node; struct rb_node *node = &ins->ref_node; - struct rb_node *parent_node = NULL; - struct btrfs_delayed_ref_node *entry; - bool leftmost = true; - - while (*p) { - int comp; - - parent_node = *p; - entry = rb_entry(parent_node, struct btrfs_delayed_ref_node, - ref_node); - comp = comp_refs(ins, entry, true); - if (comp < 0) { - p = &(*p)->rb_left; - } else if (comp > 0) { - p = &(*p)->rb_right; - leftmost = false; - } else { - return entry; - } - } + struct rb_node *exist; - rb_link_node(node, parent_node, p); - rb_insert_color_cached(node, root, leftmost); + exist = rb_find_add_cached(node, root, comp_refs_node); + if (exist != NULL) + return rb_entry(exist, struct btrfs_delayed_ref_node, ref_node); return NULL; }