Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751099AbdFRG04 (ORCPT ); Sun, 18 Jun 2017 02:26:56 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36234 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbdFRG0x (ORCPT ); Sun, 18 Jun 2017 02:26:53 -0400 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH v2 10/10] x86/mm: Try to preserve old TLB entries using PCID From: Nadav Amit In-Reply-To: <35264bd304c93f6d3cfff2329e3e01b084598ea1.1497415951.git.luto@kernel.org> Date: Sat, 17 Jun 2017 23:26:48 -0700 Cc: X86 ML , linux-kernel@vger.kernel.org, Borislav Petkov , Linus Torvalds , Andrew Morton , Mel Gorman , "linux-mm@kvack.org" , Rik van Riel , Dave Hansen , Arjan van de Ven , Peter Zijlstra Content-Transfer-Encoding: 7bit Message-Id: <740B1D51-B801-48C9-A4C9-F31B34A09AEF@gmail.com> References: <35264bd304c93f6d3cfff2329e3e01b084598ea1.1497415951.git.luto@kernel.org> To: Andy Lutomirski X-Mailer: Apple Mail (2.3273) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1697 Lines: 46 > On Jun 13, 2017, at 9:56 PM, Andy Lutomirski wrote: > > PCID is a "process context ID" -- it's what other architectures call > an address space ID. Every non-global TLB entry is tagged with a > PCID, only TLB entries that match the currently selected PCID are > used, and we can switch PGDs without flushing the TLB. x86's > PCID is 12 bits. > > This is an unorthodox approach to using PCID. x86's PCID is far too > short to uniquely identify a process, and we can't even really > uniquely identify a running process because there are monster > systems with over 4096 CPUs. To make matters worse, past attempts > to use all 12 PCID bits have resulted in slowdowns instead of > speedups. > > This patch uses PCID differently. We use a PCID to identify a > recently-used mm on a per-cpu basis. An mm has no fixed PCID > binding at all; instead, we give it a fresh PCID each time it's > loaded except in cases where we want to preserve the TLB, in which > case we reuse a recent value. > > In particular, we use PCIDs 1-3 for recently-used mms and we reserve > PCID 0 for swapper_pg_dir and for PCID-unaware CR3 users (e.g. EFI). > Nothing ever switches to PCID 0 without flushing PCID 0 non-global > pages, so PCID 0 conflicts won't cause problems. Is this commit message outdated? NR_DYNAMIC_ASIDS is set to 6. More importantly, I do not see PCID 0 as reserved: > +static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, > + u16 *new_asid, bool *need_flush) > +{ > [snip] > + if (*new_asid >= NR_DYNAMIC_ASIDS) { > + *new_asid = 0; > + this_cpu_write(cpu_tlbstate.next_asid, 1); > + } > + *need_flush = true; > +} Am I missing something?