Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10784475rwl; Thu, 12 Jan 2023 02:29:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBwJ8UV+s3EiaYwAZ+uZmaagibyZxFDVIVTR7njgnqtOYOqZL2PM61NOsmYmUsWOqLsQHp X-Received: by 2002:a17:906:33d0:b0:854:6e3:2388 with SMTP id w16-20020a17090633d000b0085406e32388mr9379349eja.12.1673519367312; Thu, 12 Jan 2023 02:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673519367; cv=none; d=google.com; s=arc-20160816; b=HnW8b/5M++v0vbmdZvBCtP0V+xuyWqSciCdgBkvEW1lrn2qGmeBh/zDNxueeiERiJ4 PwbYOrs689TOHKnSs0D2IBuhxzRA+djMY6S9M3H2m4uHoW4Qb26N3VUXSfcFI5w411gI s2hCciZdQbLB8S94b5x0vpgsFXcU7AmDfgWE2m4rxXR28DKLl/THzoJ3xbLdPezBj4/s guZJLHWzsGFXiEG5mxiqecHt6rrTUbHwkeMIU8ZUgAsyyMUYHY715GuCaRv3/S+iYMtc cLXxSffSUohF5K2xXXRHnpU7gWFRhqPIV05w+fF9o+LbKz/OCI79WsGGIDEKKdhytJcy EgwQ== 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=KNiMMQNVa5sMzIVJxz1JeBcyurPbf7owbHpmHsMMjls=; b=R3S2ffyCF4aIIbgvDJYb3au2+y0wzqsjHaF3uTOpFM4Y0KpjPIjLP3S9RAz7L3MY30 /O6QEEuIoD3709aVm6KP3XNiyC5ACkwzuEhsA/drEYso8pB4zrHGGo8S6rLIGcfhAPw0 KSEE1E891KQabpgrisiaBzcQPDSydy0V/5f0c9/ss6Fke9ucfZopGewx021MR+TEvV7n Gywl6FCSGEfJbgOtxU57t/A4SAuvbcp/6r4Bp0Qmbpa2NGZi3aLHYCr+g/UOoGFT7eAo AAAK6Xk/Xixl7JDrErLz5VViC5Xd8M5mN4ZFW0QiHaNtMUkQouFUmT7xn9TowAv+5zxM RcJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="M/ll2Jxb"; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb12-20020a170907960c00b007c1633cea0csi19011472ejc.513.2023.01.12.02.29.15; Thu, 12 Jan 2023 02:29:27 -0800 (PST) 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=@suse.com header.s=susede1 header.b="M/ll2Jxb"; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234582AbjALJtv (ORCPT + 50 others); Thu, 12 Jan 2023 04:49:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240070AbjALJtO (ORCPT ); Thu, 12 Jan 2023 04:49:14 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D911BD45 for ; Thu, 12 Jan 2023 01:45:11 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 619273ED65; Thu, 12 Jan 2023 09:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673516710; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KNiMMQNVa5sMzIVJxz1JeBcyurPbf7owbHpmHsMMjls=; b=M/ll2JxbXKarOND/NWDMQnnEv4wMiNFhx+H1RxnuakOBXNgAZXW67kEbJuMOZPUwqg850S bkyJR/TXsfKRzS3dLAqzrsft5vi7oY2acCNtbR599ljSeoEC0oZiCemGMA7B16OZRfQaO+ qQPxgWpvKe1Q5+fnR6DtkjLk9TVkCVo= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F0CD013585; Thu, 12 Jan 2023 09:45:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id W2ZzK6XWv2NDHAAAMHmgww (envelope-from ); Thu, 12 Jan 2023 09:45:09 +0000 Date: Thu, 12 Jan 2023 10:45:07 +0100 From: Michal Hocko To: Mel Gorman Cc: Linux-MM , Andrew Morton , NeilBrown , Thierry Reding , Matthew Wilcox , Vlastimil Babka , LKML Subject: Re: [PATCH 6/7] mm/page_alloc: Give GFP_ATOMIC and non-blocking allocations access to reserves Message-ID: References: <20230109151631.24923-1-mgorman@techsingularity.net> <20230109151631.24923-7-mgorman@techsingularity.net> <20230111170552.5b7z5hetc2lcdwmb@techsingularity.net> <20230112092452.rtvo6tkp4rpmxm7v@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230112092452.rtvo6tkp4rpmxm7v@techsingularity.net> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 Thu 12-01-23 09:24:52, Mel Gorman wrote: > On Thu, Jan 12, 2023 at 09:11:06AM +0100, Michal Hocko wrote: > > On Wed 11-01-23 17:05:52, Mel Gorman wrote: > > > On Wed, Jan 11, 2023 at 04:58:02PM +0100, Michal Hocko wrote: > > > > On Mon 09-01-23 15:16:30, Mel Gorman wrote: > > > > > Explicit GFP_ATOMIC allocations get flagged ALLOC_HARDER which is a bit > > > > > vague. In preparation for removing __GFP_ATOMIC, give GFP_ATOMIC and > > > > > other non-blocking allocation requests equal access to reserve. Rename > > > > > ALLOC_HARDER to ALLOC_NON_BLOCK to make it more clear what the flag > > > > > means. > > > > > > > > GFP_NOWAIT can be also used for opportunistic allocations which can and > > > > should fail quickly if the memory is tight and more elaborate path > > > > should be taken (e.g. try higher order allocation first but fall back to > > > > smaller request if the memory is fragmented). Do we really want to give > > > > those access to memory reserves as well? > > > > > > Good question. Without __GFP_ATOMIC, GFP_NOWAIT only differs from GFP_ATOMIC > > > by __GFP_HIGH but that is not enough to distinguish between a caller that > > > cannot sleep versus one that is speculatively attempting an allocation but > > > has other options. That changelog is misleading, it's not equal access > > > as GFP_NOWAIT ends up with 25% of the reserves which is less than what > > > GFP_ATOMIC gets. > > > > > > Because it becomes impossible to distinguish between non-blocking and > > > atomic without __GFP_ATOMIC, there is some justification for allowing > > > access to reserves for GFP_NOWAIT. bio for example attempts an allocation > > > (clears __GFP_DIRECT_RECLAIM) before falling back to mempool but delays > > > in IO can also lead to further allocation pressure. mmu gather failing > > > GFP_WAIT slows the rate memory can be freed. NFS failing GFP_NOWAIT will > > > have to retry IOs multiple times. The examples were picked at random but > > > the point is that there are cases where failing GFP_NOWAIT can degrade > > > the system, particularly delay the cleaning of pages before reclaim. > > > > Fair points. > > > > > A lot of the truly speculative users appear to use GFP_NOWAIT | __GFP_NOWARN > > > so one compromise would be to avoid using reserves if __GFP_NOWARN is > > > also specified. > > > > > > Something like this as a separate patch? > > > > I cannot say I would be happy about adding more side effects to > > __GFP_NOWARN. You are right that it should be used for those optimistic > > allocation requests but historically all many of these subtle side effects > > have kicked back at some point. > > True. > > > Wouldn't it make sense to explicitly > > mark those places which really benefit from reserves instead? > > That would be __GFP_HIGH and would require context from every caller on > whether they need reserves or not and to determine what the consequences > are if there is a stall. Is there immediate local fallout or wider fallout > such as a variable delay before pages can be cleaned? Yes, and I will not hide I do not mind putting the burden on caller to justify adding requirement and eat from otherwise shared pool which memory reserves are. > > This is > > more work but it should pay off long term. Your examples above would use > > GFP_ATOMIC instead of GFP_NOWAIT. > > > > Yes, although it would confuse the meaning of GFP_ATOMIC as a result. > It's described as "%GFP_ATOMIC users can not sleep and need the allocation to > succeed" and something like the bio callsite does not *need* the allocation > to succeed. It can fallback to the mempool and performance simply degrades > temporarily. No doubt there are a few abuses of GFP_ATOMIC just to get > non-blocking behaviour already. I am afraid GFP_ATOMIC will eventually require a closer look. Many users are simply confused by the name and use it from the spin lock context. Others use it from IRQ context because that is the right thing to do (TM). > > The semantic would be easier to explain as well. GFP_ATOMIC - non > > sleeping allocations which are important so they have access to memory > > reserves. GFP_NOWAIT - non sleeping allocations. > > > > People's definition of "important" will vary wildly. The following would > avoid reserve access for GFP_NOWAIT for now. It would need to be folded > into this patch and a new changelog OK, so that effectively means that __GFP_HIGH modifier will give more reserves to non-sleepable allocations than sleepable. That is a better semantic than other special casing because when the two allocations are competing then the priority non-sleepable should win because it simply cannot reclaim. That hierarchy makes sense to me. Thanks for bearing with me here. Changing gfp flags semantic is a PITA. I wish would could design the whole thing from scratch (and screw it in yet another way). I will ack the patch once you post the full version of it. -- Michal Hocko SUSE Labs