Re: [PATCH 4/7] x86,tlb: make lazy TLB mode lazier

From: Dave Hansen
Date: Fri Jun 29 2018 - 13:05:22 EST


On 06/29/2018 07:29 AM, Rik van Riel wrote:
> + /*
> + * If the CPU is not in lazy TLB mode, we are just switching
> + * from one thread in a process to another thread in the same
> + * process. No TLB flush required.
> + */
> + if (!was_lazy)
> + return;
> +
> + /*
> + * Read the tlb_gen to check whether a flush is needed.
> + * If the TLB is up to date, just use it.
> + * The barrier synchronizes with the tlb_gen increment in
> + * the TLB shootdown code.
> + */
> + smp_mb();
> + next_tlb_gen = atomic64_read(&next->context.tlb_gen);
> + if (this_cpu_read(cpu_tlbstate.ctxs[prev_asid].tlb_gen) ==
> + next_tlb_gen)
> + return;

Nit: it might be nice to have this hunk in a helper like
cpu_tlbstate_needs_flush(next) to keep this nice and readable.