Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1054661iob; Wed, 4 May 2022 13:39:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVVMEvAl5aaNXvNP4gN6xWzZ1BHpEu7MnVAMPWPVKyAX4iC/PcfcyodBrud/21ymERqnwT X-Received: by 2002:aa7:db48:0:b0:425:f93a:de5b with SMTP id n8-20020aa7db48000000b00425f93ade5bmr25392153edt.169.1651696768577; Wed, 04 May 2022 13:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651696768; cv=none; d=google.com; s=arc-20160816; b=s92t80ai+8n3dADkGHmMm9OU34h7ZLgo1Zn9G9a3edGQkYDO+oW95cesAluWQ6UKwn EOnEqPBoXnXy3ndZ4HJQPFT2iGQuNqNzcxL/J+rMDHJ5w6z6ZqPfq01I2b+o6v14gDS4 QAX1ezZG+Gfhku+S+elqzyNzDMvpHsYQGhGJUT3xkBIrHS6ipi1YG3tnhgMqfaLBExaw 9sbtbTKIAR89V/TaLex+TfUt2/uobwHvdbhav742TddlHwgClx4sueDUBd7Jjf4zTPcV 9DYSeKTPDrYtZceGx7KBECtOczbRBeB40c+gCKA3uasaKfrIam7tB6In3yzvB+LpIinM MBVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Zo3O6tVQd44QV+x14eWm1UztwGioRdt6e/ffaJNkFVk=; b=BvpeeaWlNNU5mYjh5jL0O6CaM3sE0gSs1ug2VeT3LiUhLMsHWhTbeUQVXL1HW984hc ERfVQ3IbL5cBQyjeNGujBWo8nCh5xKYTuHxtcvqlnLhkxsH20mVWrTtDTcLAzip7gGEm I/9Mgxn9+VvPm+QYxDviaiBIclCIThDUttACH2eL5Ayor+3c+mf1c6INSbse2x2RGoTx ptCT1Bx+n/wJlBjzloVV/wOvlvaeDlPHc0z9bjC6vB1YT9Q65wMOWMfbpK3YXax/JVV0 wpAA0NnW8gdmFYqWQOitXnDatUj5Ire6gvZCuGR+66Yc1j4aqLqkz/NFyso8HtFbOQNU 5lLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=liDHjBfL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc35-20020a1709078a2300b006e8a06f6f01si19898906ejc.9.2022.05.04.13.39.05; Wed, 04 May 2022 13:39:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=liDHjBfL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353083AbiEDQ1u (ORCPT + 99 others); Wed, 4 May 2022 12:27:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353447AbiEDQ1s (ORCPT ); Wed, 4 May 2022 12:27:48 -0400 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A07D46B30 for ; Wed, 4 May 2022 09:24:04 -0700 (PDT) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-e5e433d66dso1676245fac.5 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=dGu4AZy0ImFdyKVq1UUIxpz2YhhilTfDDeFQdDqq1o/ZtLzQBdgRmxrwlCMqfmMmtM a/1096qB6S0qlxE8j22Zv7kYwHfe+zRGJMa5iy4W6yrvuABKhVYDpGRdkA6LkE+bV+id /1mjsp8NTNeod1xoT0Er6q00IXzvlY1r+g3vR1zv6FBfs3XzA/KP52NExuN3AuC5hPDA z6WXGF0JajuS+9npGbOpGMYKDPMWHOQBDV6QncM0HYWi32zjQts4HmLvd0O6u/C+0ocA L97gjnVXzfL5oBtShJxo/Z1jjqR1bM8CYQZXotOEpGv4rq9qCmljLZl5EK+mKBMcFI5H /quA== X-Gm-Message-State: AOAM5319n/Z/sCzI1rGMcgF+CTnPJTK+YDtV+l+cGPitzWlCXTZD3laz UUHKNKOSujKBDSuNMaTz+YYYRQ== 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.