From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABED61E991C for ; Tue, 21 Jan 2025 09:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737453323; cv=none; b=KH2qjJwFcABBMNbBTT9w7HYl1mkaSYUmSskJjR4p4aNAfEP39UWdcM1xQNrXmyasSMsZfYoN9Q/JkFceqoqROvs9r+Wsf4DihGl20xqG+mocbMRrtKNxazJXR9Vu4bAmXD8hgsUjLjJHYsVQt+5YNn+id568B+r9JFwXiz3s364= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737453323; c=relaxed/simple; bh=4qDYmd2jJvYBkr6TiQ5nkIB5aARRrm9bZ8mDIspMN2s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k8CUSdWUKtY0amtfDLZBzb9sBI52mx07lsS+yEo682UN2Yk4fT9PZZGSqYP+UNXXmvIS5ItbGv2ewZefIK9rYHzeIqcXoF32RNS4nldZ9yl3K6FLWXAH5Qin5ClSij8Rmf7fuIoqYs6BmgxHfx/1pDrZZMmliaBr1geOzhZ6P44= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bvCZxrDX; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bvCZxrDX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=r9TbVSfipg2t06a90ZFihQOp8RMB/deZCx1oiNaX8vU=; b=bvCZxrDXlASI90n//xC3JUbhqe AFeiy1S80Nqy9AOvQDfWbkueXDqZnePqSnY4VXKOkpXQ6JQgr6T4nNVUQ0fdILiS17/q/vMkxZIvx se2rV3yfyWZbBtlC5E2TgsazlG0SMeZqrvGaSoqIR1WKWygfyz/wR4v6OHl3KeyW1ZpVY+2ToBydP tiOm1v1wUzKMS5BDLzKCsFriPeejXLzRZqgVRKAumqtpLk6vJashuDe5p/WmZcaH4mmDwUomTcTOW 3aeLtoGIbt97RF+V7ZwBLfSJ4EW6PSjLdumtiy913XMDpkvaepxUYSRyU1jU4eQYtVqSQqi2Bctfa m3kgHdbQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1taAyR-00000006G30-44o1; Tue, 21 Jan 2025 09:55:08 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8E426300619; Tue, 21 Jan 2025 10:55:07 +0100 (CET) Date: Tue, 21 Jan 2025 10:55:07 +0100 From: Peter Zijlstra To: Rik van Riel Cc: x86@kernel.org, linux-kernel@vger.kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, zhengqi.arch@bytedance.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com Subject: Re: [PATCH v6 09/12] x86/mm: enable broadcast TLB invalidation for multi-threaded processes Message-ID: <20250121095507.GB5388@noisy.programming.kicks-ass.net> References: <20250120024104.1924753-1-riel@surriel.com> <20250120024104.1924753-10-riel@surriel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250120024104.1924753-10-riel@surriel.com> On Sun, Jan 19, 2025 at 09:40:17PM -0500, Rik van Riel wrote: > +/* > + * Figure out whether to assign a global ASID to a process. > + * We vary the threshold by how empty or full global ASID space is. > + * 1/4 full: >= 4 active threads > + * 1/2 full: >= 8 active threads > + * 3/4 full: >= 16 active threads > + * 7/8 full: >= 32 active threads > + * etc > + * > + * This way we should never exhaust the global ASID space, even on very > + * large systems, and the processes with the largest number of active > + * threads should be able to use broadcast TLB invalidation. > + */ > +#define HALFFULL_THRESHOLD 8 > +static bool meets_global_asid_threshold(struct mm_struct *mm) > +{ > + int avail = global_asid_available; > + int threshold = HALFFULL_THRESHOLD; > + > + if (!avail) > + return false; > + > + if (avail > MAX_ASID_AVAILABLE * 3 / 4) { > + threshold = HALFFULL_THRESHOLD / 4; > + } else if (avail > MAX_ASID_AVAILABLE / 2) { > + threshold = HALFFULL_THRESHOLD / 2; > + } else if (avail < MAX_ASID_AVAILABLE / 3) { > + do { > + avail *= 2; > + threshold *= 2; > + } while ((avail + threshold) < MAX_ASID_AVAILABLE / 2); > + } > + > + return mm_active_cpus_exceeds(mm, threshold); > +} I'm still very much disliking this. Why do we need this? Yes, running out of ASID space is a pain, but this increasing threshold also makes things behave weird. Suppose our most used processes starts slow, and ends up not getting an ASID because too much irrelevant crap gets started before it spawns enough threads and then no longer qualifies. Can't we just start with a very simple constant test and poke at things if/when its found to not work?