Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1050720rwr; Wed, 3 May 2023 09:31:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UHisMy4erlhI1+GFqekIlA7AknJP3ao61qcodf8oK2q/BtotLCK2Lhq6FFpgnqtdDfCtX X-Received: by 2002:a17:902:7295:b0:1aa:ee36:4095 with SMTP id d21-20020a170902729500b001aaee364095mr586799pll.43.1683131507648; Wed, 03 May 2023 09:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683131507; cv=none; d=google.com; s=arc-20160816; b=Qsz9u0oRIZo3+ylK2nX2RzJ9PiSpLjWszE2Tz7AQ3mXG8pUcxr/+PEtD6tZfPMflvF O1BXxohqjyYknttVS0hBdw4uYK/wkkH35sYFWwB5VzOivRoWusrwPbdXiLAZSxB7NoT7 vHYyf8k9h4g5mpNnVFD1y74UhoqmtZM46Emo3zffGcJgLziXlMDR9p2QfFyL5wgr7iXk lARSrfS9zPdbIT3vXkOd7c28wHiQ3yRIiQ1NMVV/xT0UtG/ECpW7r4rjVVEFi0sqtF8v On9xOm9ThCxEIJMNHICoiNJIJk1ZrFR92Uufnsw67ylTVLGc8NgQ/271PlmgtpYLRoOO 8oAA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=YGRmvkXZgWwSDmksHZZl3JTraRryAOxL8ndOPqqQNzA=; b=LelyIRTF5GFQJB4zOAU6MAVeAfJV5gCMWWrcQuJ18GSbGI2CAOl1vDNPP7TKVswyFr kg48zWLf+AKDt0NPC6Yzga4x61AanWIZPtuasDl/JNkUo49Lf5BIYwTDIORaG2ze3Wbw jLcOepJbY81NHyVayq966BOSS7PKKH0Dfp0LK4Rg3teNxJnl9V+J1cbvAuWbPiQsmjWC ePHdgwfWWYuOO2n73B1zYImOZpe+V4uLp+owhehxRGeqzm9y1/52kJrkqpMqvHe+r/ib HzPPYraEwYiOL/q37yJyB5/tEUaRZHRoGcqOz0grgbK55bsV1uek22wi2HybNnC0nE/n f03Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ift34KQ4; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u8-20020a17090341c800b001a50dcd10c2si10275119ple.247.2023.05.03.09.31.32; Wed, 03 May 2023 09:31:47 -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=@linux.dev header.s=key1 header.b=Ift34KQ4; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjECQab (ORCPT + 99 others); Wed, 3 May 2023 12:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbjECQaW (ORCPT ); Wed, 3 May 2023 12:30:22 -0400 Received: from out-37.mta0.migadu.com (out-37.mta0.migadu.com [IPv6:2001:41d0:1004:224b::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7CAE4EF9 for ; Wed, 3 May 2023 09:30:07 -0700 (PDT) Date: Wed, 3 May 2023 09:30:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683131405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YGRmvkXZgWwSDmksHZZl3JTraRryAOxL8ndOPqqQNzA=; b=Ift34KQ4ikJ+WTvGN4Y1OvAtcUpwNgFBqPVKyB/ZjJIBe4waIyJ6EEGw3c34v1edy4+gQ2 XyDIcpEZezSpg/S7ZbDKsgJESbBEkk9vVPmSflPSUnU3TeP3oYLioq9ZKVh/07Aa/hArij Va9IoVhT15FgtFN32qFN/Lvy8cybTS4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Zhaoyang Huang Cc: =?utf-8?B?6buE5pyd6ZizIChaaGFveWFuZyBIdWFuZyk=?= , Andrew Morton , Roman Gushchin , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , =?utf-8?B?546L56eRIChLZSBXYW5nKQ==?= Subject: Re: =?utf-8?B?562U5aSNOiBbUEFUQ0g=?= =?utf-8?Q?=5D?= mm: optimization on page allocation when CMA enabled Message-ID: References: <1682679641-13652-1-git-send-email-zhaoyang.huang@unisoc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Wed, May 03, 2023 at 03:58:21PM +0800, Zhaoyang Huang wrote: > On Wed, May 3, 2023 at 6:01 AM Roman Gushchin wrote: > > > > On Tue, May 02, 2023 at 12:12:28PM +0000, 黄朝阳 (Zhaoyang Huang) wrote: > > > > Hi Zhaoyang! > > > > > > > > On Fri, Apr 28, 2023 at 07:00:41PM +0800, zhaoyang.huang wrote: > > > > > From: Zhaoyang Huang > > > > > > > > > > Please be notice bellowing typical scenario that commit 168676649 > > > > > introduce, that is, 12MB free cma pages 'help' GFP_MOVABLE to keep > > > > > draining/fragmenting U&R page blocks until they shrink to 12MB without > > > > > enter slowpath which against current reclaiming policy. This commit change > > > > the criteria from hard coded '1/2' > > > > > to watermark check which leave U&R free pages stay around WMARK_LOW > > > > > when being fallback. > > > > > > > > Can you, please, explain the problem you're solving in more details? > > > I am trying to solve a OOM problem caused by slab allocation fail as all free pages are MIGRATE_CMA by applying 168676649, which could help to reduce the fault ration from 12/20 to 2/20. I noticed it introduce the phenomenon which I describe above. > > > > > > > > If I understand your code correctly, you're effectively reducing the use of cma > > > > areas for movable allocations. Why it's good? > > > Not exactly. In fact, this commit lead to the use of cma early than it is now, which could help to protect U&R be 'stolen' by GFP_MOVABLE. Imagine this scenario, 30MB total free pages composed of 10MB CMA and 20MB U&R, while zone's watermark low is 25MB. An GFP_MOVABLE allocation can keep stealing U&R pages(don't meet 1/2 criteria) without enter slowpath(zone_watermark_ok(WMARK_LOW) is true) until they shrink to 15MB. In my opinion, it makes more sense to have CMA take its duty to help movable allocation when U&R lower to certain zone's watermark instead of when their size become smaller than CMA. > > > > Also, this is a hot path, please, make sure you're not adding much overhead. > > > I would like to take more thought. > > > > Got it, thank you for the explanation! > > > > How about the following approach (completely untested)? > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 6da423ec356f..4b50f497c09d 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -2279,12 +2279,13 @@ __rmqueue(struct zone *zone, unsigned int order, int migratetype, > > if (IS_ENABLED(CONFIG_CMA)) { > > /* > > * Balance movable allocations between regular and CMA areas by > > - * allocating from CMA when over half of the zone's free memory > > - * is in the CMA area. > > + * allocating from CMA when over half of the zone's easily > > + * available free memory is in the CMA area. > > */ > > if (alloc_flags & ALLOC_CMA && > > zone_page_state(zone, NR_FREE_CMA_PAGES) > > > - zone_page_state(zone, NR_FREE_PAGES) / 2) { > > + (zone_page_state(zone, NR_FREE_PAGES) - > > + zone->_watermark[WMARK_LOW]) / 2) { > IMO, we should focus on non-cma area which trigger use of cma when > they are lower than corresponding watermark(there is still > WMARK_MIN/HIGH to deal with within slowpath) > > page = __rmqueue_cma_fallback(zone, order); > > if (page) > > return page; > > > > Basically the idea is to keep free space equally split between cma and non-cma areas. > > Will it work for you? > I don't think it makes sense to 'equally split' cma and non-cma areas > over free space while cma could occupy various proportions in a single > zone. This fixed 1/2 could lead to different situation on 20% or 50% > cma occupation. Can you then, please, explain in details what you're proposing instead and why it's better (not only in your case, but generally as well)? For the context, my original usecase was cma size under 10G and the total memory size between 32G and 128G. Looking at your original patch, I see that __if_use_cma_first() always returns false if zone_watermark_ok() returns true. It worries me. Thanks!