linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Mateusz Guzik <mjguzik@gmail.com>,
	Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	Martin Liu <liumartin@google.com>,
	David Rientjes <rientjes@google.com>,
	Jani Nikula <jani.nikula@intel.com>,
	Sweet Tea Dorminy <sweettea@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Christian Brauner <brauner@kernel.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Suren Baghdasaryan <surenb@google.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Wei Yang <richard.weiyang@gmail.com>,
	David Hildenbrand <david@redhat.com>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, Yu Zhao <yuzhao@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Greg Thelen <gthelen@google.com>
Subject: Re: [PATCH] mm: use per-numa-node atomics instead of percpu_counters
Date: Thu, 27 Mar 2025 16:35:35 -0400	[thread overview]
Message-ID: <a89cb4d9-088e-4ed6-afde-f1b097de8db9@efficios.com> (raw)
In-Reply-To: <evqxyt5dkkervut7q4ea4dnykcz75lxx2wvqyg2lq7m3ptam3c@53ao37tlhytk>

On 2025-03-26 19:36, Mateusz Guzik wrote:
[...]
> 
> Hell, it may be your patch as is can be easily repurposed to
> decentralize the main percpu counter? I mean perhaps there is no need
> for any fancy hierarchical structure.

Here is an initial attempt at a design document for the hierarchical
percpu counters. Feedback welcome!

Split Counters With Binary Tree Approximation Propagation
=========================================================

Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
March 27, 2025

* Propagation diagram when reaching batch size thresholds (± batch size):

Example diagram for 8 CPUs:

log2(8) = 3 levels

At each level, each pair propagates its values to the next level when
reaching the batch size thresholds.

Counters at levels 0, 1, 2 can be kept on a single byte (±128 range).
Counter at level 3 can be kept on a 32/64-bit counter.

Level 0:  0    1    2    3    4    5    6    7
           |   /     |   /     |   /     |   /
           |  /      |  /      |  /      |  /
           | /       | /       | /       | /
Level 1:  0         1         2         3
           |       /           |       /
           |    /              |    /
           | /                 | /
Level 2:  0                   1
           |               /
           |         /
           |   /
Level 3:  0


* Inaccuracy:

BATCH(level N): Level N batch size.

Example for BATCH(level 0) = 4

BATCH(level 0) =  4
BATCH(level 1) =  8
BATCH(level 2) = 16
BATCH(level N) = BATCH(level 0) * 2^N

           per-counter     global
           inaccuracy      inaccuracy
Level 0:    ±  3          ± 24  (8 * 3)
Level 1:    ±  7          ± 28  (4 * 7)
Level 2:    ± 15          ± 30  (2 * 15)
Total:      ------        ± 82  (log2(nr_cpus) * BATCH(level 0) * nr_cpus - Sum[0 .. log2(nr_cpus) - 1](nr_cpus / 2^n)

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com


  reply	other threads:[~2025-03-27 20:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25 22:15 Sweet Tea Dorminy
2025-03-26 19:56 ` Mathieu Desnoyers
2025-03-26 21:54   ` Mateusz Guzik
2025-03-26 23:36 ` Mateusz Guzik
2025-03-27 20:35   ` Mathieu Desnoyers [this message]
2025-03-31 12:32 ` Lorenzo Stoakes

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=a89cb4d9-088e-4ed6-afde-f1b097de8db9@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=cl@linux.com \
    --cc=david@redhat.com \
    --cc=dennis@kernel.org \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=jani.nikula@intel.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=liumartin@google.com \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhiramat@kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=richard.weiyang@gmail.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=surenb@google.com \
    --cc=sweettea-kernel@dorminy.me \
    --cc=sweettea@google.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yuzhao@google.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