From patchwork Thu Dec 12 20:29:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Beckermeyer X-Patchwork-Id: 13905952 Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 30E261422D4 for ; Thu, 12 Dec 2024 20:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035480; cv=none; b=iM154FH+JHEpmeQROrQ2Sro4cG7y/4pod8589sbh0Bir5WWJXGjd5O5ih+HzWzqbN/CITehCCcSz62s8wIQ88MCeFDeKXqzsX05mg07sMuD7mERCxMgMmW/BBsLpjkqja61ELrtdBvZzSxWOu0/k5Hxic3VgOU3+xHKAxfdvvYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035480; c=relaxed/simple; bh=oQN9PKoo4/XxL2HTr+T3SQvrKxeZZqBZ7CGVSu871mw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b8srhZyFYYM4Q7Wxmj9b0O/XeMuNYekzdzqkE/c+lIkXqNqUgepnAAohc6zwFpmT5fNCI2PUf4aEAR8y/C03JZ0n+mNF0ym4yvTIhqx5q2DpxO7DGfembqorSdNw99z99VK9sgZZ2h4cSAGuwPCiwAm944FxJyqbNSWOun8pq3M= 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=IDci6sRK; arc=none smtp.client-ip=209.85.166.49 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="IDci6sRK" Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-844e6d1283aso13139139f.1 for ; Thu, 12 Dec 2024 12:31:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734035478; x=1734640278; 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=u81hyYymjCO6gTrB/A5NmlBtBd1FR4760ndipuiDqVo=; b=IDci6sRKopmFpOZMCY++ynvXjwVQRHJ47/JoAL9O4HWnIKrAr1mCAKuPvhmEfb6fHy MJbC6OCd3bbdSFyxXr4yMOXsnIaCGqqX1fibLXYE2UnROqDEGFD0iDZ0nVY5tzb5sZWt gT024NCDVbaJnDa85qxgJziC8R9Q7vEf8nf27czuEBNljjLEqu8rv82lxNDLgYLxhQmZ QwahEDOGHSUi0yOLHdozOXpFqDChpk1P0vGQAYVS7IXAIt3UMB+lvF5s3O92XqozHSoe RYxbDDs5YR39L66haGJHOtbZCuHpma4IotgXVYVLgO5T5WhnAUejzGAcjNWkKGCVsNHR g+rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734035478; x=1734640278; 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=u81hyYymjCO6gTrB/A5NmlBtBd1FR4760ndipuiDqVo=; b=IkbgZjfK2oicrsYNZ+1kLcqriYGkgqdLFy7dhXdhMqJj49pYuqsBVreTfjlDf0+loa wSmLyUyHf67uG3Ycfs4b0vwxDUlsNsdTPdaYL+wtpl7RJRF5hT7s3/BqQX+YWZxvlXe3 tXEWzdA5M945qVOc0wiNEJA4EKvcR8CZaVuE0zrIuaPdAhKT9baIVlIn/hl8CrCZYo0M bNVi2CvxHu/X7KodAycd/7Lbl/ze6QZiagUTdt2U6z+jodBY3oXSYoqDr5/ZT5bwBsCq wAsi+58wJzKXTFnd5XdvqAqGbXjkVdJnE2rv/s5eB1ff2fgk2Pk5LcPP/PwXWZ69t6PF xUiQ== X-Gm-Message-State: AOJu0YzO4YL0d6V9sHr0nVlpQs+ffxDLdKxfZj9e4UQW/c9qQwFRtGRq pSTA/q2GCL3HFUEBDJ8gncaXt642NkC2Znt5FaFmPQUeNHL4T+HdSXsHap/9Ka0= X-Gm-Gg: ASbGncu7X+U1RjM5gQHAvVJtDBbno//Kg7oAR7jgouZ/G7HOR/ri+vpAcRChi3K6i4Y MW8Ed+mYiidSJwfQM0UuU5wkT9F+SMnwpTvUDNHEwod1gN9i0rli7TA3mM1X2HqvJ19k1YAywpu K1iqy5YbnE45DBbnVIkEA+NLuQyxDthbYE1XouMQ8cRyq8eWbTCICEvTeEQjrgUBq8Eig6v6R7O MueCN1rvgwwSPzXsICjagFQgBPXBGkJI0RwnP4HSlLIytCFEzAGV0tQqmPaMt3s7A== X-Google-Smtp-Source: AGHT+IFEzcoDzg408ZPisPeY3d+QWX5elIh3jktehIwD5zRIuj4r7vqGcdIR4OothoXCKVjj61hrJg== X-Received: by 2002:a05:6602:6d14:b0:841:8345:5eed with SMTP id ca18e2360f4ac-844e5b6e414mr157777439f.0.1734035478311; Thu, 12 Dec 2024 12:31:18 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844e29b6103sm28642939f.29.2024.12.12.12.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 12:31:17 -0800 (PST) From: "Roger L. Beckermeyer III" To: beckerlee3@gmail.com Cc: linux-btrfs@vger.kernel.org, Josef Bacik Subject: [PATCH 2/6] btrfs: update btrfs_add_block_group_cache() to use rb helpers Date: Thu, 12 Dec 2024 14:29:40 -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 update fs/btrfs/block-group.c to use rb_find_add_cached() implement btrfs_bg_start_cmp() for use with rb_find_add_cached(). Suggested-by: Josef Bacik 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..6001b78e9ea9 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_bg_start_cmp(struct rb_node *new, const struct rb_node *exist) +{ + struct btrfs_block_group *cmp1 = rb_entry(new, struct btrfs_block_group, cache_node); + const 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_bg_start_cmp); + if (exist != NULL) + return -EEXIST; write_unlock(&info->block_group_cache_lock); return 0; From patchwork Thu Dec 12 20:29:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Beckermeyer X-Patchwork-Id: 13905953 Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (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 88AED1A4F22 for ; Thu, 12 Dec 2024 20:31:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035483; cv=none; b=alPnqQlFYG6oVfTlVN8zN0tbEZDjAIfhLaZ4IuCxGaUKJU92vdHdMpHNHzKT/+1v28zfyOSeOSTRbDG1iwfSpxNLveNC2FSwEXgA1igik6HQZ/4ZdjJD8y5G3znm831gZDdryTfFCe8x5WkCPOtcELEOdvmbvSO40A1cC7TMNxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035483; c=relaxed/simple; bh=TkliS2oHaEPuWNgijaqqLxdRvx2GTLjFdwEnagsLDSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bOtUVVOCpcmPU5z0UkjbiFdRtt4wx3fGg6Kv++xzF4kViuQd+z7Vm0+FOStyMlCVqq+RCVDl/i2FJdwzRg2ThhFXZtctJ3NlNe4asL3wLZm4Wve4IUk4If+J5FkJBQsG5iXC19atbQTqtFxTdizoYiAzNecBw1RGc8HYUuPrhJA= 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=l8MHt1m7; arc=none smtp.client-ip=209.85.166.49 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="l8MHt1m7" Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-844dac0a8f4so77099839f.2 for ; Thu, 12 Dec 2024 12:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734035480; x=1734640280; 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=JrKhWXGN+megD4dCMPT4CbRdmotjLJaXyZVNcNebOxM=; b=l8MHt1m7FBaTvqWbE5Gaxw/BM48s4c6iPczuLBDVSu14WfLlPG+g6toKI72hR039Gy nhBMz03dkNmwAaw7jUfetCx8ZZWKAdXOvCXYSCwG7J8ymZ/cjPDrbCj3FFpTssqvLCig jH7IpnuxCGYjRIDLEeXoshge4PphbLn+WEffJbkvvsBJVtN6y//mbFL/e6rqIMGY6U+w QCSfLQv2RN3+J6zJP6sXlJIfViGSsOkDoGvMJC5IcqdB11EQKe1CMwPyOsu+pKJNMsq0 ozXZIxvsBGLUJ+//GgOKbSQbbdspip1F9a3gGLz+8PdGg1qTgUuU2/BXUfNrSeAqyOG+ TwQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734035480; x=1734640280; 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=JrKhWXGN+megD4dCMPT4CbRdmotjLJaXyZVNcNebOxM=; b=KhpdWnZAvATBYendmU4b70NcG5Q+NxGhtI5Pp6OJGC5UkmsEYOM4s21IOYxNmU470w rWKI8CoSF1e++DUhq+dobupGPCtkqi17ZwZm9nCS0BpuZHZpyY37UYh2JuIORfwqn5i+ aS+sWoZNOi40EMmYMSaBQm9wJXgMtDB46rxh1mXG3A1tBh5pIiUvIf9fCdtht+Z4n3FN Rq0CBWTOw7jrgq5eMnSYCoyZGjnbemPPGr3dTDmCuvPydTg+ymAzbyFWZmgl74kPl+DS zGFJoz9p1B7MJ9LumnC6qADEGhlHi/ugHBnkBhIYWNOLc5vsmHS75DM8EGAwmymMSGw+ GCSA== X-Gm-Message-State: AOJu0YyirjMqurwKAlQGfp3+vrZrllYAw9xqmKWmW1S9fW1SUHk5nF6D h86IsiJwqmNKfDNSzMK+eCNQnFRI1fDBszt0mJqmv1mXZt9T3ZRthh04oM0sMVc= X-Gm-Gg: ASbGnct/8h2QzIAs3zrhM6W4BCvEkQ5JGAAQjOvzbhMvFjq/iu1yBa1AA/X8GEHFzoq qpvbdRuftMgTWWTpUyAkIKrwcxM2Eo4vbdjhIeQuakxSgT7VWZYxGRJJMpVjnHyKRfzXxZa7Gq3 FbskB5HRi0ZwpM6SkqH+Pr42bO2hnEeDTeC5lLVgJgmkXz+YVR2PAM8m0qnoydczqjffTpFwxas TZoatgC6AyYpbKWsPQwjxPb7cqi+unIg84fVCgC6tm6Gs9h2Pm15YHYU9s41Bhgjg== X-Google-Smtp-Source: AGHT+IE/m51xUGZKgbn0xoOshOGUZ49Munvd8q9jF1pXylVDG9zR+2h8wsw6F5mbnrvz9tIqp0C9rA== X-Received: by 2002:a05:6602:492:b0:835:3ffe:fe31 with SMTP id ca18e2360f4ac-844e88489f9mr26385539f.8.1734035480500; Thu, 12 Dec 2024 12:31:20 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844e29b6103sm28642939f.29.2024.12.12.12.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 12:31:19 -0800 (PST) From: "Roger L. Beckermeyer III" To: beckerlee3@gmail.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 3/6] btrfs: update prelim_ref_insert() to use rb helpers Date: Thu, 12 Dec 2024 14:29:41 -0600 Message-ID: <2e60a302945ddaa69abb807987fea9bcdcc36ef0.1734033142.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 update prelim_ref_insert() to use rb_find_add_cached() adds prelim_ref_cmp 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 Thu Dec 12 20:29:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Beckermeyer X-Patchwork-Id: 13905954 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (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 861E31ABEB1 for ; Thu, 12 Dec 2024 20:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035485; cv=none; b=toYWQBsDlNekh7oSnTlmYBKcfUH29r/Uq76p1Td8L6i+CVM9lEoix8iXvPXPYRkXTH1ENyADyrm0y3PHlY8YhkOzBFLCeNfKbmtcYVJpWIxplsOBMAwHrDTXQcZLkjYlisVWrB6TK1+owuDVmaIc0Pe22OHvEixoi8XPgwSyc48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035485; c=relaxed/simple; bh=0hk3y6uOdBb1TBHDqc2BPKIC/uSBk9llQOtdIUsyfx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cy08z3X+hregE2Eho0lOWOEhhrHoGdGIhRuJHYqJ23dfDlQUg7wDL03uM5/LSz21TQoe7gi7nW0sLtHJ1hE6fPLM3JWsPblWdD9uO36gehHxTCX1XekGie7cCxVXUW05Irdy/BZTCLAsC8fv+98ntRutRTqzaOH9ze2O3mKe2dA= 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=hV/nDRpx; arc=none smtp.client-ip=209.85.166.47 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="hV/nDRpx" Received: by mail-io1-f47.google.com with SMTP id ca18e2360f4ac-844dac0a8f4so77102939f.2 for ; Thu, 12 Dec 2024 12:31:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734035483; x=1734640283; 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=3QcB7uLiiK6eYxy4QV/NfOBh2UDPIWi7OhZUQTByQSw=; b=hV/nDRpxC3ToHfdeK1hkvzdf/FZOSTlWfK+i77LXJXJUev5ch6eSPgXy2hj4gLhwOe B7/r8XNuACSroxDP0XtBxcndMmoBG7h7aWTO7HD2rpOixp1E9FgJ+Fk4EAcdWohDmdkB ys6AqQ659DSJy3uNm8x1FphHfyEKxPu7i5QFmHSVMKaEWrut3fN/0Rdw8RUEPJHBfN/j EN1mMoPqn0JaxIddypTMIGBishNEkuD0hFgIm9ES46I5ww+E8IFqDH8ZSaV0MaaIziAR dhPV9y1mv7tBVP3g7W0+z54/AEJ0+b9P1ty/qHiCLK7JaUGdmaF+wvSbiJW8icSOt9+G qEyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734035483; x=1734640283; 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=3QcB7uLiiK6eYxy4QV/NfOBh2UDPIWi7OhZUQTByQSw=; b=b1j+A27UBms66zN1qWPu5yc5KmxGy9Az15KbFMtlxntsob6C32DIMisAL6IieBRGLn F97QevRMA9pgg3iXUGmVDkn1VGXHu77QFiGF1INWPcR/FDl4sbhYYOswlgKEL7jQ+rjg 8N/c+udlKq4jfLZeDMKY6EdHQwoCYJ5kBKS+xFURgmXFqPoQ6pRXpvQLx8Y6MFu5Ygij 50ys6Y9Vxt+p/8XYqsIk2Fdc6ua2TG+y+E45NRa6e9llq2xHsx55yWTGzOnfd31OHcwJ Lu64QykHKfIwHIZnIR1PElh6F5K1mG/af/5skBJi7IlmCN52r3l0+dQaVpZvZ8oCxzgA Qzkg== X-Gm-Message-State: AOJu0YxyqgtbrK5S6Dv6mvUCcivwAEqFpunXfeu40rXmmLM+wFpxW2FS 7Brb/gVgB/kAmXQQP59Ep7s6xW8vf68R1yzoR3iKI3mcS2qovTI/ZY/ZlT86f7M= X-Gm-Gg: ASbGncs8aysUPtu0QSbyGz+/1aq8rPnN2cLsQ4zjfMnwbRQhwu9H9f+FuyQB/CU0ExT 86ae2aOPyGgeI5hwIoEOhVIi2c5BNFoBV9PP4jbcK1ZxxcDU1SKJezO1S2d2hvEf42KyPep5c0G KD36MeQ1yYqPohA4ZtrqAgc/VbtWJ8W7c7H1BFYG/JWwMs2DtFtC0lR0I7s+uGmporTaPX83OV3 Dv6Yp7H4rK5Sf1KkJN3MP4W1sXBWMunKJG7Xm/ax6QMnW+vEuj7+DaMxPWFSiQ7CQ== X-Google-Smtp-Source: AGHT+IGK0oBSVmP3vY2kPXguI0O0Si0GI2mEgjlt0o7MsjsosqB+GLUYD1fmNVZZtDYV3cdizBFISg== X-Received: by 2002:a05:6602:492:b0:835:3ffe:fe31 with SMTP id ca18e2360f4ac-844e88489f9mr26395139f.8.1734035482759; Thu, 12 Dec 2024 12:31:22 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844e29b6103sm28642939f.29.2024.12.12.12.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 12:31:21 -0800 (PST) From: "Roger L. Beckermeyer III" To: beckerlee3@gmail.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 4/6] btrfs: update __btrfs_add_delayed_item() to use rb helpers Date: Thu, 12 Dec 2024 14:29:42 -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 update __btrfs_add_delayed_item() to use rb_find_add_cached() add btrfs_delayed_item_cmp() 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..d705049fb381 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_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); + const 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_delayed_item_cmp); + if (exist != NULL) + return -EEXIST; if (ins->type == BTRFS_DELAYED_INSERTION_ITEM && ins->index >= delayed_node->index_cnt) From patchwork Thu Dec 12 20:29:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Beckermeyer X-Patchwork-Id: 13905955 Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (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 13A2F1422D4 for ; Thu, 12 Dec 2024 20:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035490; cv=none; b=ZWV/CLCYM+YQdiJ12qHK4B25Kt9LH28YDSkJJzQ6L9+Kl3NigHDqzplwiLCLVqaerm0DeqXonT89ZxXPHog5ZYLRtkKBDakFN++F2rBAleJlORVcyfK8HiB2IJBlSNS4s+X6iMcL4YA/dSUNrFj2abUx3aqqUHQoYmbluMuOPkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035490; c=relaxed/simple; bh=m70gGDD9rv7gX4sEOszgR2G4jyWwJ3V+WEHM5UpVgQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JaOoUoaoustO8y0tr6JceV9vN/SVuKw50RaDxBwCHG27jVYPoF0UI3jT3slj6smU0pKcdVHtQgbt+HguZQVoZ1sXHxn6se1vxT5h4Z6HEEVbFcZYnkt1lQXooHn+mw4YXe+0P/zrEV/tG6yACS5O20IrKz8/74OhORQRtSmezhk= 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=M5Paaeyi; arc=none smtp.client-ip=209.85.166.48 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="M5Paaeyi" Received: by mail-io1-f48.google.com with SMTP id ca18e2360f4ac-844d53c62b1so81832539f.3 for ; Thu, 12 Dec 2024 12:31:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734035485; x=1734640285; 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=3pKpgct01RWYCYkwHKO61wqMtLnVKqyX6S0glBH4EZY=; b=M5PaaeyiK050Gmk/fDyl9+JdqSARrxUIyxaHFfIpQEPTiZhvqnoSHkp8h7FWuegWyc 59JyItarob0DIgO586bLfzc5GzQgHyO3WGhztjzkiNeern25JvTDMY8AfEH1J31/cyde AG6I2tDO4lJkpQD/frvWJXquB3Yk6ZfQVoByGMpITb7ZkK0tyqXbcbaDW3vNsRjrsP3e UHeh/X+sL/g2NPRYMY7BqOLeXvWm+QG5Ddw4nPSM2pndsQCMkDKa32dbIWAn0+mCmwSY BkNYQN66HiVoXImUrtgJeDipQO/nfVLihyvwqM99k0iVDuZwTVzx522CciATDVQQEJL7 s2qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734035485; x=1734640285; 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=3pKpgct01RWYCYkwHKO61wqMtLnVKqyX6S0glBH4EZY=; b=eEbiqKw+7u4D0CgWNf5k97nOb2JXH31EptH8iYO1JgclR7srRDgFV6yJl8SzpfGecb Z60AaYxQwJR1p8DtQyEDPFLUp8MmG23HGTOYZ7A68nA6Qa0fXIppFMj5wx2DDcfgFw6t JQJ1EEa5zPLPI6zf1SmnUHODNSePnNUCyBkXFaBvo9fmC6GS/jlffH4aXmar6N4JAXQy 5btBrWshDXMHNl5i7lKUNjJK/qPV4xLKgtE7CtU43GXQyWe99NXiR92hYHuedufrQuPE mx9RhbVJztEqEjoIE3adaKRp7TrpolmLNOg/tJUYmdyKoZ+nosWEFPpFKQ5fAF5LMtXb wR8A== X-Gm-Message-State: AOJu0YySm+b7KghnRjAyU/vg58cJ/q8PnMpgX0bMJtheCOTs9z6UUZ7L 9uake/fBPteeWn+gpzhkZOQQryuLSRpp5HgvZWbWnntb2neSwwbz01y8D1T2FCg= X-Gm-Gg: ASbGncsCjqeg12XZ2MvypcK6QxQntYpjMD9RUSN/2vj3dXbm7xPSwRyk3lANlkaG1Jg TLR1VQZTNjXaA7ITnoKOARu/gxgRx8eUFBoLMJpelwe+STrN28EKL2WD0ZRB0EdJCIowrnK3R/H iUR3uGnbaI4dGLuC4sPo33J7W6nmS6rL2s+gqf/HiDSHTMYNOQh57wDTWOsSKbj1nd6pW1jPJ9P YIwtElVlPcmBopHU3QAN+DUhNACcdECNUsUr+STYf9RwiRUrxTG/UyHo4KOlts6VQ== X-Google-Smtp-Source: AGHT+IGPrPw9YZGYv+VDh/iEPd7te97Ne9LmCJa0x9Q8Pp1Fhoa1fgab5njTQkfj3vhSEtOHtdqIDA== X-Received: by 2002:a05:6602:14cb:b0:83a:c296:f5b0 with SMTP id ca18e2360f4ac-844e885f35cmr26570939f.9.1734035485009; Thu, 12 Dec 2024 12:31:25 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844e29b6103sm28642939f.29.2024.12.12.12.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 12:31:23 -0800 (PST) From: "Roger L. Beckermeyer III" To: beckerlee3@gmail.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 5/6] btrfs: update btrfs_add_chunk_map() to use rb helpers Date: Thu, 12 Dec 2024 14:29:43 -0600 Message-ID: <121af810c0bb755a83cad52f3500ebf552c6a02c.1734033142.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 update btrfs_add_chunk_map() to use rb_find_add_cached(). add btrfs_chunk_map_cmp 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..b39723a95f26 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); + const 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 Thu Dec 12 20:29:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Beckermeyer X-Patchwork-Id: 13905956 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 23CCE189B91 for ; Thu, 12 Dec 2024 20:31:27 +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=1734035490; cv=none; b=C4wainySm0gIpTn6PE41eGhk9SsNt3TOmy9Qt4UInQhdscbomULy7aV+ozjykJO98fAnsRWveJJS3wBteXVDv1M0tsBSitGqhX2CBnqMTMKHqpH0p19jMz6U41zEkDL84na0Z+J0RdjoVSKCd0t/UddcxVlT0bPoJYuxKA+m96s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734035490; c=relaxed/simple; bh=MQxyUJqaalbeIkORNGIANIkOTKknWJrZfPgq3w57pbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XbtskZrIliOylVwMMYh1zfDZDYmW1oGKP2GQgjVhKD5jk1vdEq2L/G6TTkJlbeDSELAFHmIQOj/Kv268tetcsBmwCTNHpu9IZ6g10IYc1mwHqviFdAHMzQYlU1sqrgfkFB8nzM5E3GsCJN9Hm7PTTYLmSFdZGVmtMQLi6Q1rgNM= 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=QCfjXY37; 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="QCfjXY37" Received: by mail-io1-f42.google.com with SMTP id ca18e2360f4ac-83eb38883b5so36407139f.1 for ; Thu, 12 Dec 2024 12:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734035487; x=1734640287; 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=cGnxyUBnvGdimtGOgxAJCTudkumkhvBzH4UQ1On88Bs=; b=QCfjXY37xLjt9o2YmUYYvIKoRfO0YmbhvH0fk3ecykykLVmiAN1eV34KG+btYs+ilj IeKydaFBW63ijJx3pig4Oic9JQvWhjTVm//0UfN311hydAWvuVjcET7gRYA0yBl3/T+R i3YwaKQfX9zkpUzKrMyA7s7YZJImO0xh02+zzvsUyO7kB6CGGV1NrzAzBcCiIkwwkfNX FH09xk0wYq+Jtsr0vUsWtRKxR8ZOhzwU0QlWC2s7zlNlj2zeb6qg9+hWiVuOYFPmKDrH Jo09JFu3FJO22bwK9ZqqIrwDlahVHHF05aTvH/o1/7Ihtc23E3/S7/Dlx3CCidbWj0pt 407Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734035487; x=1734640287; 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=cGnxyUBnvGdimtGOgxAJCTudkumkhvBzH4UQ1On88Bs=; b=f16bJAblaZjIAC/oDwsuY423PvjUn3Vq8nJ9hwRd984qCQGqcd4n4aaI99AaePJ4wL MvHZowUzOGTS+XphOoiNZO1q0DomdPgb5FCBOR/fb06KMT2A+Q1VS67Mc1Qwe6cLfBso s/iMkgcf/a4oEwO/8CJDoSICzQO3jTygJaZyv3BJ/fvvzmkRkR0/wdEFykqwEF+SQkwt OCmrQN5eXtxfzjZyBX0umcHX0WCar9inb1aUJjS4KbHWH75+shcm4OixsQ44oyVz7n4d nBXF/PYWLUN6720W1DfEekuVgriWGefCiplF89ocusWfjHkazKoTskU2/1M/ukpvyIUC JpqA== X-Gm-Message-State: AOJu0YyxbTdmdUGWCl/KI+e2njbYcHM7Bj9lZW1VCjEtv8IzEQ4lFrjY pcaC0DUVsHKtQIaE2LiLyKm3djWSGMkaZondiMXPHpx/XfOKvTSgjsR1IIKNj74= X-Gm-Gg: ASbGnctZLHTBTJBmiK/9/XsP0VXt5uCw45VMnJUEmMmeJUUW0VRzL6a2NU6/qWPbU0d gWxH4Ojo8dYnr5T9nuBPPSUnJJBBf/x6CHGcrgRgvHQvIIf/eWa+k/gcTRKaSkyS+iZ5nu1HNmn X+wAoyVP9VVqyV0IlYw2pTvY3j5ljSX8bq064pfrcfak1RSWgIxEFYZkDv6DqLzSqgX0mPmkgT6 raGMHBxckhpG0F65/LeLtRNZlyVR0gesiMfsjZtri42o3DIWbOUkfYlBCgbRNDGfw== X-Google-Smtp-Source: AGHT+IH5A4H6/rhGA/wpCr3DMFcLgEunrKLsq9etK9KkGUpv2WdCxnc4wZvdzABBoCkBAtIGQUj+dw== X-Received: by 2002:a05:6602:485:b0:843:daae:e16d with SMTP id ca18e2360f4ac-844e8822360mr33089339f.6.1734035487252; Thu, 12 Dec 2024 12:31:27 -0800 (PST) Received: from LeeDev.lee.dev ([2600:8804:1a84:2a00:be24:11ff:fe2b:2474]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-844e29b6103sm28642939f.29.2024.12.12.12.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 12:31:26 -0800 (PST) From: "Roger L. Beckermeyer III" To: beckerlee3@gmail.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 6/6] btrfs: update tree_insert() to use rb helpers Date: Thu, 12 Dec 2024 14:29:44 -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 update tree_insert() to use rb_find_add_cached(). add cmp_refs_node in rb_find_add_cached() to compare. note: I think some of comparison functions could be further refined. 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..3cd122c899cc 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 cmp_refs_node(struct rb_node *node, const struct rb_node *node2) +{ + struct btrfs_delayed_ref_node *ref1; + const 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, cmp_refs_node); + if (exist != NULL) + return rb_entry(exist, struct btrfs_delayed_ref_node, ref_node); return NULL; }