BPF List
 help / color / mirror / Atom feed
From: Barret Rhoden <brho@google.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@kernel.org, memxor@gmail.com, eddyz87@gmail.com,
	djwong@kernel.org, kernel-team@fb.com
Subject: Re: [PATCH bpf-next 1/2] bpf: Introduce range_tree data structure and use it in bpf arena
Date: Mon, 6 Jan 2025 11:12:22 -0500	[thread overview]
Message-ID: <5fe34ecf-07df-49c2-b94e-36ee6cb21f8a@google.com> (raw)
In-Reply-To: <20241108025616.17625-2-alexei.starovoitov@gmail.com>

On 11/7/24 9:56 PM, Alexei Starovoitov wrote:
> +/* Clear the range in this range tree */
> +int range_tree_clear(struct range_tree *rt, u32 start, u32 len)
> +{
> +	u32 last = start + len - 1;
> +	struct range_node *new_rn;
> +	struct range_node *rn;
> +
> +	while ((rn = range_it_iter_first(rt, start, last))) {
> +		if (rn->rn_start < start && rn->rn_last > last) {
> +			u32 old_last = rn->rn_last;
> +
> +			/* Overlaps with the entire clearing range */
> +			range_it_remove(rn, rt);
> +			rn->rn_last = start - 1;
> +			range_it_insert(rn, rt);
> +
> +			/* Add a range */
> +			new_rn = bpf_mem_alloc(&bpf_global_ma, sizeof(struct range_node));
> +			if (!new_rn)
> +				return -ENOMEM;
> +			new_rn->rn_start = last + 1;
> +			new_rn->rn_last = old_last;
> +			range_it_insert(new_rn, rt);
> +		} else if (rn->rn_start < start) {
> +			/* Overlaps with the left side of the clearing range */
> +			range_it_remove(rn, rt);
> +			rn->rn_last = start - 1;
> +			range_it_insert(rn, rt);
> +		} else if (rn->rn_last > last) {
> +			/* Overlaps with the right side of the clearing range */
> +			range_it_remove(rn, rt);
> +			rn->rn_start = last + 1;
> +			range_it_insert(rn, rt);
> +			break;
                         ^^^
did you mean to have the break here, but not in the "contains entire 
range" case?  for the arena use case, i think you never have overlapping 
intervals, so once you hit the last one, you can break.  (in both 
cases).  though TBH, i'd just never break in case you ever have 
intervals that overlap (i.e. two intervals containing 'last') - either 
for arenas or for someone who copies this code for another use of 
interval trees.

barret



> +		} else {
> +			/* in the middle of the clearing range */
> +			range_it_remove(rn, rt);
> +			bpf_mem_free(&bpf_global_ma, rn);
> +		}
> +	}
> +	return 0;
> +}


  parent reply	other threads:[~2025-01-06 16:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08  2:56 [PATCH bpf-next 0/2] bpf: range_tree for bpf arena Alexei Starovoitov
2024-11-08  2:56 ` [PATCH bpf-next 1/2] bpf: Introduce range_tree data structure and use it in " Alexei Starovoitov
2024-11-13 16:02   ` Kumar Kartikeya Dwivedi
2025-01-06 16:12   ` Barret Rhoden [this message]
2025-01-06 17:45     ` Alexei Starovoitov
2024-11-08  2:56 ` [PATCH bpf-next 2/2] selftests/bpf: Add a test for arena range tree algorithm Alexei Starovoitov
2024-11-13 16:04   ` Kumar Kartikeya Dwivedi
2024-11-15 12:20   ` Jiri Olsa
2024-11-15 16:30     ` Yonghong Song
2024-11-16 19:00       ` Alexei Starovoitov
2024-11-16 20:35         ` Jiri Olsa
2024-11-13 21:59 ` [PATCH bpf-next 0/2] bpf: range_tree for bpf arena Andrii Nakryiko
2024-11-14  0:48   ` Alexei Starovoitov
2024-11-13 22:10 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5fe34ecf-07df-49c2-b94e-36ee6cb21f8a@google.com \
    --to=brho@google.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=djwong@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox