[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4F173A6B-B09B-40D0-B118-94B08B9ACC32@gmail.com>
Date: Thu, 26 Dec 2024 01:22:10 +0200
From: Nadav Amit <nadav.amit@...il.com>
To: Rik van Riel <riel@...riel.com>
Cc: the arch/x86 maintainers <x86@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
kernel-team@...a.com,
Dave Hansen <dave.hansen@...ux.intel.com>,
luto@...nel.org,
peterz@...radead.org,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"open list:MEMORY MANAGEMENT" <linux-mm@...ck.org>
Subject: Re: [PATCH 08/11] x86/mm: enable broadcast TLB invalidation for
multi-threaded processes
On 23 Dec 2024, at 4:55, Rik van Riel <riel@...riel.com> wrote:
> +static int mm_active_cpus(struct mm_struct *mm)
> +{
> + int count = 0;
> + int cpu;
> +
> + for_each_cpu(cpu, mm_cpumask(mm)) {
> + /* Skip the CPUs that aren't really running this process. */
> + if (per_cpu(cpu_tlbstate.loaded_mm, cpu) != mm)
> + continue;
> +
> + if (per_cpu(cpu_tlbstate_shared.is_lazy, cpu))
> + continue;
> +
> + count++;
> + }
> + return count;
> +}
Since you are only interested in checking whether the number of “mm active
CPUs" is greater than a certain threshold, don’t you want to add some
checks for early termination? This can allow to avoid cachelines of
cpu_tlbstate traversing back and forth.
For instance, by running cpumask_weight() first, if the weight is lower than
the threshold, no need to loop. Similarly, if inside the loop the threshold
has already been crossed, no need for more iterations.
Powered by blists - more mailing lists