From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC40BC433EF for ; Tue, 3 May 2022 18:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3F216B00BE; Tue, 3 May 2022 14:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEE226B00BF; Tue, 3 May 2022 14:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDE516B00C0; Tue, 3 May 2022 14:28:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id CC5E46B00BE for ; Tue, 3 May 2022 14:28:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9E0EA9B1 for ; Tue, 3 May 2022 18:28:36 +0000 (UTC) X-FDA: 79425267432.15.C2AC4C7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id 43174A007E for ; Tue, 3 May 2022 18:28:27 +0000 (UTC) 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=wjXE0SIpZd7eh/s+NoP34A161Jqj7oErQimubPGebCU=; b=ZgLPanOhTu3Nx2h0oL6bG0ARDX KQpJntnmzSTK8FBe2UY+sc8fjvU+4SLQBnLy9G3zvaUhvTW47f+p931JbiFP2ozIKbBswbDlbT6jp MbNpk5wkHPggNwOzr6oS0xHFWuhyZxxVKrJ7SW3Yd3OVV34SEB7P3+dntEEPBPcL0Fht4GrqXPQWv QoO1TBODd2vEjlCepXhgUBpYQTCR5lBO+3AtlGCqUuJb7pfoU4LPLVWTi2Dq5NkAKTjNi+uPl6xT2 QJ0+lEUO0wsN5o9ZhYmNgAHEyyTKdf0wzBo3gI9FEW+8k2yBF2i8QxW72MgMX3xhE96PY/4/ls2Wy y6qW4IWw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlxG3-00Fs21-LU; Tue, 03 May 2022 18:28:23 +0000 Date: Tue, 3 May 2022 19:28:23 +0100 From: Matthew Wilcox To: "Paul E. McKenney" Cc: Michal Hocko , liam.howlett@oracle.com, walken.cr@gmail.com, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: Memory allocation on speculative fastpaths Message-ID: References: <20220503155913.GA1187610@paulmck-ThinkPad-P17-Gen-1> <20220503163905.GM1790663@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220503163905.GM1790663@paulmck-ThinkPad-P17-Gen-1> X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 43174A007E X-Stat-Signature: ppstignd1ciyozg19oosp8iurmxe98as X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ZgLPanOh; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1651602507-448421 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, May 03, 2022 at 09:39:05AM -0700, Paul E. McKenney wrote: > On Tue, May 03, 2022 at 06:04:13PM +0200, Michal Hocko wrote: > > On Tue 03-05-22 08:59:13, Paul E. McKenney wrote: > > > Hello! > > > > > > Just following up from off-list discussions yesterday. > > > > > > The requirements to allocate on an RCU-protected speculative fastpath > > > seem to be as follows: > > > > > > 1. Never sleep. > > > 2. Never reclaim. > > > 3. Leave emergency pools alone. > > > > > > Any others? > > > > > > If those rules suffice, and if my understanding of the GFP flags is > > > correct (ha!!!), then the following GFP flags should cover this: > > > > > > __GFP_NOMEMALLOC | __GFP_NOWARN > > > > GFP_NOWAIT | __GFP_NOMEMALLOC | __GFP_NOWARN > > Ah, good point on GFP_NOWAIT, thank you! Johannes (I think it was?) made the point to me that if we have another task very slowly freeing memory, a task in this path can take advantage of that other task's hard work and never go into reclaim. So the approach we should take is: p4d_alloc(GFP_NOWAIT | __GFP_NOMEMALLOC | __GFP_NOWARN); pud_alloc(GFP_NOWAIT | __GFP_NOMEMALLOC | __GFP_NOWARN); pmd_alloc(GFP_NOWAIT | __GFP_NOMEMALLOC | __GFP_NOWARN); if (failure) { rcu_read_unlock(); do_reclaim(); return FAULT_FLAG_RETRY; } ... but all this is now moot since the approach we agreed to yesterday is: rcu_read_lock(); vma = vma_lookup(); if (down_read_trylock(&vma->sem)) { rcu_read_unlock(); } else { rcu_read_unlock(); mmap_read_lock(mm); vma = vma_lookup(); down_read(&vma->sem); } ... and we then execute the page table allocation under the protection of the vma->sem. At least, that's what I think we agreed to yesterday.