Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9621566rwl; Wed, 11 Jan 2023 07:59:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXuHqpRz+4oi361VYgd1ph1qX7s7C4vHbu+mDKpmw0TGItn0EX399qUqAx7dW0OlmD3TZgYI X-Received: by 2002:a62:1981:0:b0:578:8864:b25c with SMTP id 123-20020a621981000000b005788864b25cmr60534723pfz.25.1673452743984; Wed, 11 Jan 2023 07:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673452743; cv=none; d=google.com; s=arc-20160816; b=A5mpZf20gB+jkQl3zb1ifXfYSepHJu2x5diXqYfElXnNqXN4ei2xSICy9HVL9zBl+l HR7wqx/Dxs0LJNsLKSJM2BDeFt4G6LDDBiiQngiI9cXn84Adgki74Z3D6txXigrdZ3/F LLHCwRbvO3vK/vjqV+xbQ+E03BBSXtfm0Sd8eqBBUE/Egalk0/sgnDdgaahD2datQktb D2YFGn5YB+DxQJdYRHtAw6Rv64Q2COq+b4ltgbtrHZemGOOY8TpCgk0tMRf4Wti1yKPa fXWdKUVsB4WFafr0viaNBkUKl+R8zSDmebbIAByJFsvgtqLc7pmOqfXLi+O2bcIAYvkI Ojdg== 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=H5PrZhGxAXPih4jW/nQocRH5mJY9ZxQOPuFJC4UKqxc=; b=MZD/00ePZGvqtCmI0PWpXMgeNfxGhl+w7U06oFpY7uVOaZU2Rhj6hnl0gWXqk4a5NW saGjmddtkaOpr2r09HndiY6wM5zvCBiW6g7kYkwmy/ARMkf9I0krhtYPL0Zf2vWWNIMr OU/vSvTn6OmzMLLdEtWPS8WAc0WD7b2tfiTCN3xblhIbny+cshQ2WxWzfkAaupzZYjZZ FVx0oOHkP10qUIEv4IQqEWzOJhbqOe31Z9K0PcCBYga9Ih3Wx1brbjQ99WC6f9BO9Hgu EzwVAaT76vZy6pDz2mGTPYQghUUau5nMww1niaQ35qd1HeB5ekX5zg4m/5YyPHAUOg47 wpPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ANOeU6im; 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 h19-20020a056a001a5300b005749d29f159si15620876pfv.194.2023.01.11.07.58.57; Wed, 11 Jan 2023 07:59:03 -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=ANOeU6im; 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 S233480AbjAKPiE (ORCPT + 51 others); Wed, 11 Jan 2023 10:38:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239124AbjAKPhs (ORCPT ); Wed, 11 Jan 2023 10:37:48 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FDF81E3FC for ; Wed, 11 Jan 2023 07:37:35 -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 AAE3A8B896; Wed, 11 Jan 2023 15:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673451453; 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=H5PrZhGxAXPih4jW/nQocRH5mJY9ZxQOPuFJC4UKqxc=; b=ANOeU6imNYB3YhDQhQexlYgh0cL0lzk3Nt32U9yhMFbLO42nW6eeTkOWED21iFXAgb/SVp TK2apZMAjfWHNRtFCzX2s3xRfaZFQK11gncGb5+MDWyQLpvBoBruZ+n8NKqxqNAybU+m6V /Ykdr6nnso/PjaSV9/uABIpvWi1Q/Nk= 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 8EDD61358A; Wed, 11 Jan 2023 15:37:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HgAAIL3XvmM6OAAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:37:33 +0000 Date: Wed, 11 Jan 2023 16:37:32 +0100 From: Michal Hocko To: Mel Gorman Cc: Linux-MM , Andrew Morton , NeilBrown , Thierry Reding , Matthew Wilcox , Vlastimil Babka , LKML Subject: Re: [PATCH 4/7] mm/page_alloc: Explicitly define what alloc flags deplete min reserves Message-ID: References: <20230109151631.24923-1-mgorman@techsingularity.net> <20230109151631.24923-5-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230109151631.24923-5-mgorman@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 Mon 09-01-23 15:16:28, Mel Gorman wrote: > As there are more ALLOC_ flags that affect reserves, define what flags > affect reserves and clarify the effect of each flag. I like this! It makes the code much easier to follow. > Signed-off-by: Mel Gorman Acked-by: Michal Hocko Thanks! > --- > mm/internal.h | 3 +++ > mm/page_alloc.c | 34 ++++++++++++++++++++++------------ > 2 files changed, 25 insertions(+), 12 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index 178484d9fd94..8706d46863df 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -749,6 +749,9 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, > #define ALLOC_HIGHATOMIC 0x200 /* Allows access to MIGRATE_HIGHATOMIC */ > #define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ > > +/* Flags that allow allocations below the min watermark. */ > +#define ALLOC_RESERVES (ALLOC_HARDER|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM) > + > enum ttu_flags; > struct tlbflush_unmap_batch; > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 0ef4f3236a5a..6f41b84a97ac 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3949,15 +3949,14 @@ ALLOW_ERROR_INJECTION(should_fail_alloc_page, TRUE); > static inline long __zone_watermark_unusable_free(struct zone *z, > unsigned int order, unsigned int alloc_flags) > { > - const bool alloc_harder = (alloc_flags & (ALLOC_HARDER|ALLOC_OOM)); > long unusable_free = (1 << order) - 1; > > /* > - * If the caller does not have rights to ALLOC_HARDER then subtract > - * the high-atomic reserves. This will over-estimate the size of the > - * atomic reserve but it avoids a search. > + * If the caller does not have rights to reserves below the min > + * watermark then subtract the high-atomic reserves. This will > + * over-estimate the size of the atomic reserve but it avoids a search. > */ > - if (likely(!alloc_harder)) > + if (likely(!(alloc_flags & ALLOC_RESERVES))) > unusable_free += z->nr_reserved_highatomic; > > #ifdef CONFIG_CMA > @@ -3981,25 +3980,36 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, > { > long min = mark; > int o; > - const bool alloc_harder = (alloc_flags & (ALLOC_HARDER|ALLOC_OOM)); > > /* free_pages may go negative - that's OK */ > free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); > > - if (alloc_flags & ALLOC_MIN_RESERVE) > - min -= min / 2; > + if (unlikely(alloc_flags & ALLOC_RESERVES)) { > + /* > + * __GFP_HIGH allows access to 50% of the min reserve as well > + * as OOM. > + */ > + if (alloc_flags & ALLOC_MIN_RESERVE) > + min -= min / 2; > > - if (unlikely(alloc_harder)) { > /* > - * OOM victims can try even harder than normal ALLOC_HARDER > + * Non-blocking allocations can access some of the reserve > + * with more access if also __GFP_HIGH. The reasoning is that > + * a non-blocking caller may incur a more severe penalty > + * if it cannot get memory quickly, particularly if it's > + * also __GFP_HIGH. > + */ > + if (alloc_flags & ALLOC_HARDER) > + min -= min / 4; > + > + /* > + * OOM victims can try even harder than the normal reserve > * users on the grounds that it's definitely going to be in > * the exit path shortly and free memory. Any allocation it > * makes during the free path will be small and short-lived. > */ > if (alloc_flags & ALLOC_OOM) > min -= min / 2; > - else > - min -= min / 4; > } > > /* > -- > 2.35.3 -- Michal Hocko SUSE Labs