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 20F95C433F5 for ; Wed, 4 May 2022 16:24:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A0376B0071; Wed, 4 May 2022 12:24:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94C896B0073; Wed, 4 May 2022 12:24:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8150D6B0074; Wed, 4 May 2022 12:24:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 742F26B0071 for ; Wed, 4 May 2022 12:24:05 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5095A2B725 for ; Wed, 4 May 2022 16:24:05 +0000 (UTC) X-FDA: 79428582450.29.2188503 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) by imf25.hostedemail.com (Postfix) with ESMTP id 9A640A0081 for ; Wed, 4 May 2022 16:23:51 +0000 (UTC) Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-e9027efe6aso1662610fac.10 for ; Wed, 04 May 2022 09:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Zo3O6tVQd44QV+x14eWm1UztwGioRdt6e/ffaJNkFVk=; b=liDHjBfLPT03qcEt5udttgxkBTlhkRj9QEnRjXqeDsGrQRYS1FSPoazeSWJPZLAMyU a2MeQW559qQu9bBU+g4rBc/O0nKIqVUQN5/Ui9Hen7gD/IO8KpywTphZ5lsDcONdNwkI zYhhfKc+0TUPOH7cURTrnodrtzKw/QPWLStxtEsHd7oXucjnz1GF+sbU5Hwl4q3kqLAf xmtAu6IGgFQH2e+fVzpCcTSyT/ldQjVs2SQJ6CX0NhnyRoE46sKAw2GcQPPXz6AZl0mj vQbi3DLL+yebcIQV/Offd+ZatlVFtrMtzhDuonkUXXfcprfyRjjGJnYyL0Yf1glmjGZK NMBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Zo3O6tVQd44QV+x14eWm1UztwGioRdt6e/ffaJNkFVk=; b=56OsHJn0dDDtQluwnEoxs2XK8u6m8oQKLU9Zv3JtG/nKqCwiXBQgqSUsQWCcuaLb6P JVvG7Ufgxo349TYZShmjAYfz12RBz3o1lVny4RIRnxWCLJQXLQZeBVK9l8h+LBZra1/i HHkpbrt9BXUbPlklre748awwI7imk8rennEA0CjVlWbQgJCIETUdSrzu1j3W4CPR6ZSj OLthslH/+zzcue/MxKCafAL4vU/XuSM5rUMte5N59G7d2zIeYYLWvV8f7kZSU86FbEBs dvWAihWbD6HYMrYjswl7cfILlR9Neg4Qr99FP5uKhjfl4fPeoTgSuz7LQP64U4OoB4bf f5lQ== X-Gm-Message-State: AOAM533n3bRN4378cKFfZS5txZIqYem1nX/xGIJ3YkxmzHroxu6dqM8I 2XyFCxWHJA9NsA1UOrdH6BY7hg== X-Google-Smtp-Source: ABdhPJxvTbJfQYVVkk06vmzUGhiMMpd6Af2yf8dg0IE6RS4vB2z6lPNUei0kcgWWXLi3e5slxqg8vg== X-Received: by 2002:a05:6870:5708:b0:db:2ef8:f220 with SMTP id k8-20020a056870570800b000db2ef8f220mr131572oap.198.1651681443863; Wed, 04 May 2022 09:24:03 -0700 (PDT) Received: from localhost ([8.34.116.185]) by smtp.gmail.com with ESMTPSA id b21-20020a056870b25500b000eba4901e57sm5699113oam.17.2022.05.04.09.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 09:24:03 -0700 (PDT) Date: Wed, 4 May 2022 09:23:14 -0700 From: Johannes Weiner To: Suren Baghdasaryan Cc: Matthew Wilcox , "Paul E. McKenney" , Michal Hocko , "Liam R. Howlett" , Michel Lespinasse , linux-mm , LKML , David Hildenbrand , Davidlohr Bueso 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: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9A640A0081 X-Stat-Signature: enz9b87qnqdunei8hypme3tjighe8x4m X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=liDHjBfL; spf=pass (imf25.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.49 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-HE-Tag: 1651681431-621065 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 04:15:46PM -0700, Suren Baghdasaryan wrote: > On Tue, May 3, 2022 at 11:28 AM Matthew Wilcox wrote: > > > > 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: Right, GFP_NOWAIT can starve out other allocations. It can clear out the freelists without the burden of having to do reclaim like everybody else wanting memory during a shortage. Including GFP_KERNEL. In smaller doses and/or for privileged purposes (e.g. single-argument kfree_rcu ;)), those allocations are fine. But because the context is page tables specifically, it would mean that userspace could trigger a large number of those and DOS other applications and the kernel. > > 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: > > I think the discussion was about the above approach and Johannes > suggested to fallback to the normal pagefault handling with mmap_lock > locked if PMD does not exist. Please correct me if I misunderstood > here. Yeah. Either way works, as long as the task is held accountable.