Skip to contentSkip to conversation

percpu_counter: increase batch count

PATCH In review Jens Axboe 3 participants 6 messages Feb 18, 2021 – Feb 22, 2021

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author
#0 lore raw

PATCH 1/1 percpu_counter: increase batch count

Currently we cap the batch count at max(32, 2*nr_online_cpus), which these days is kind of silly as systems have gotten much bigger than in 2009 when this heuristic was introduced.

Bump it to capping it at 256 instead. This has a noticeable improvement for certain io_uring workloads, as io_uring tracks per-task inflight count using percpu counters.

---

lib/percpu_counter.c +1 -1
index 00f666d94486..c3a9af5462ba 100644
@@ -188,7 +188,7 @@ static int compute_batch_value(unsigned int cpu)
 {
 	int nr = num_online_cpus();
 
-	percpu_counter_batch = max(32, nr*2);
+	percpu_counter_batch = max(256, nr*2);
 	return 0;
 }
 
Signature · 1 line
Jens Axboe
maintainer
#1 lore raw
Quoted 8 lines · On Thu, 18 Feb 2021 14:36:31 -0700 Jens Axboe <[email protected]> wrote:

Currently we cap the batch count at max(32, 2*nr_online_cpus), which these days is kind of silly as systems have gotten much bigger than in 2009 when this heuristic was introduced.

Bump it to capping it at 256 instead. This has a noticeable improvement for certain io_uring workloads, as io_uring tracks per-task inflight count using percpu counters.

It will also make percpu_counter_read() and percpu_counter_read_positive() more inaccurate than at present. Any effects from this will take a while to discover.

But yes, worth trying - I'll add it to the post-rc1 pile.

author
#2 lore raw
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Thu, 18 Feb 2021 14:36:31 -0700 Jens Axboe <[email protected]> wrote:

Currently we cap the batch count at max(32, 2*nr_online_cpus), which these days is kind of silly as systems have gotten much bigger than in 2009 when this heuristic was introduced.

Quoted 8 lines
Quoted 4 lines

Bump it to capping it at 256 instead. This has a noticeable improvement for certain io_uring workloads, as io_uring tracks per-task inflight count using percpu counters.

It will also make percpu_counter_read() and percpu_counter_read_positive() more inaccurate than at present. Any effects from this will take a while to discover.

It will, but the value of 32 is very low, especially when you are potentially doing millions of these per second. So I do think it should track the times a bit.

Quoted 1 line

But yes, worth trying - I'll add it to the post-rc1 pile.

Thanks!

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 10 lines · Jens Axboe
Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Thu, 18 Feb 2021 14:36:31 -0700 Jens Axboe <[email protected]> wrote:

Currently we cap the batch count at max(32, 2*nr_online_cpus), which these days is kind of silly as systems have gotten much bigger than in 2009 when this heuristic was introduced.

Bump it to capping it at 256 instead. This has a noticeable improvement for certain io_uring workloads, as io_uring tracks per-task inflight count using percpu counters.

I want to quibble with the word "capping" here, it's misleading - but I'm sorry I cannot think of the right word.

The macro is max() not min(): you're making an improvement for certain io_uring workloads on machines with 1 to 15 cpus, right? Does "bigger than in 2009" apply to those?

Though, io_uring could as well use percpu_counter_add_batch() instead?

(Yeah, this has nothing to do with me really, but I was looking at percpu_counter_compare() just now, for tmpfs reasons, so took more interest. Not objecting to a change, but the wording leaves me wondering if the patch does what you think - or, not for the first time, I'm confused.)

Hugh

Quoted 16 lines
Quoted 5 lines
Quoted 1 line

It will also make percpu_counter_read() and percpu_counter_read_positive() more inaccurate than at present. Any effects from this will take a while to discover.

It will, but the value of 32 is very low, especially when you are potentially doing millions of these per second. So I do think it should track the times a bit.

Quoted 1 line

But yes, worth trying - I'll add it to the post-rc1 pile.

Thanks!

Signature · 1 line
Jens Axboe
author
#4 lore raw
Quoted 8 lines · Hugh Dickins
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Thu, 18 Feb 2021 14:36:31 -0700 Jens Axboe <[email protected]> wrote:

Currently we cap the batch count at max(32, 2*nr_online_cpus), which these days is kind of silly as systems have gotten much bigger than in 2009 when this heuristic was introduced.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Bump it to capping it at 256 instead. This has a noticeable improvement for certain io_uring workloads, as io_uring tracks per-task inflight count using percpu counters.

I want to quibble with the word "capping" here, it's misleading - but I'm sorry I cannot think of the right word.

Agree, it's not the best wording. And if you can't think of a better one, then I'm at a loss too :-)

Quoted 3 lines

The macro is max() not min(): you're making an improvement for certain io_uring workloads on machines with 1 to 15 cpus, right? Does "bigger than in 2009" apply to those?

Right, that actually had me confused. The box in question has 64 threads, so my effective count was 128, or 256 with the patch.

Quoted 1 line

Though, io_uring could as well use percpu_counter_add_batch() instead?

That might be a simpler/better choice!

Quoted 5 lines

(Yeah, this has nothing to do with me really, but I was looking at percpu_counter_compare() just now, for tmpfs reasons, so took more interest. Not objecting to a change, but the wording leaves me wondering if the patch does what you think - or, not for the first time, I'm confused.)

I don't think you're confused, and honestly I think using the batch version instead would likely improve our situation without potentially changing behavior for everyone else. So it's likely the right way to go.

Thanks Hugh!

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 19 lines · Jens Axboe
Quoted 8 lines · Hugh Dickins
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Thu, 18 Feb 2021 14:36:31 -0700 Jens Axboe <[email protected]> wrote:

Currently we cap the batch count at max(32, 2*nr_online_cpus), which these days is kind of silly as systems have gotten much bigger than in 2009 when this heuristic was introduced.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Bump it to capping it at 256 instead. This has a noticeable improvement for certain io_uring workloads, as io_uring tracks per-task inflight count using percpu counters.

I want to quibble with the word "capping" here, it's misleading - but I'm sorry I cannot think of the right word.

Agree, it's not the best wording. And if you can't think of a better one, then I'm at a loss too :-)

Quoted 6 lines
Quoted 3 lines

The macro is max() not min(): you're making an improvement for certain io_uring workloads on machines with 1 to 15 cpus, right? Does "bigger than in 2009" apply to those?

Right, that actually had me confused. The box in question has 64 threads, so my effective count was 128, or 256 with the patch.

Ah, yes, so there I *was* confused in saying "1 to 15", the improvement was for "1 to 127" of course - thanks.

Quoted 11 lines
Quoted 2 lines

Though, io_uring could as well use percpu_counter_add_batch() instead?

That might be a simpler/better choice!

Quoted 5 lines

(Yeah, this has nothing to do with me really, but I was looking at percpu_counter_compare() just now, for tmpfs reasons, so took more interest. Not objecting to a change, but the wording leaves me wondering if the patch does what you think - or, not for the first time, I'm confused.)

Quoted 3 lines

I don't think you're confused, and honestly I think using the batch version instead would likely improve our situation without potentially changing behavior for everyone else. So it's likely the right way to go.

You're too polite! But yes, if percpu_counter_add_batch() suits, great.

Quoted 5 lines

Thanks Hugh!

Signature · 1 line
Jens Axboe