Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp287740ybh; Wed, 15 Jul 2020 01:52:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcio4X5tohsR41/bp0quwi/Q342hJVhZ3myl+gU92uHIWwJi4Ztwi67lSVa8dNASL5mKYD X-Received: by 2002:a05:6402:1a54:: with SMTP id bf20mr8568375edb.69.1594803161403; Wed, 15 Jul 2020 01:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594803161; cv=none; d=google.com; s=arc-20160816; b=sU5ysHQbvm5lMDND8nNu4gHFxodT7tbdE7x4fysF5RTjkHZcCfMd8+dLODci5m6mfx qb8eHfVYpsbKoKbPxS3krbJKMA6KlgFOVxPDW+jbju5CIg1cv4/vzT3FlIR4iLCUel5v F80cwhKOQrdZUQ7ZMSRK2QTH2auJBdaDMZJ6XZMjIsY0+JjDwNc3E6QjJ+IUxC8+k9a6 ilnje8rSqfk1E2Ut1/1E2HRvt2AdWOdw+bn7y3IKLSm6sQKoRMVFI0DbOoORfsjdMUz0 Seog/LPmX0sGldBk5zMS3eTJ7SyYs6+VXCQqGPbCl82mpjBsgGqznj4rgpOYsF5tyzQc eh8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ZdeH/6iE+xjZXdZUhvLf3wEtNpcPer3xXzZ1MgOShvE=; b=0LOo478M3FLdhY3U86WuMZtb4TEJnLbS5GxZfLuGuf2edp41YRiO7pHG6ZYuloGcY8 Vqi2ndA5/ulCPnJ4KwtwFy9NJgfWDI7WzEqtlmz37X3CwGlySUDZSkWRgpT2YWsq7n0X hHv2fCQfM1L0PWfIufjU9KsSA/oQ7GdarJf5+GJonnqti8mr0SgvPdoergGFcJs6j5Ap ES64Yi3GUlS0GOfNQvZrelCGiWqdK02wyEMDhUVJ+chcVjeBSLJ7RqwR+Gm4tMgDKOvK G1hlVydYDxrNgl9eKP060eob7Q7UgBgOGMGZZ6iy+2w1oEshHg88fdPW+uD8K/Hdl30E ys4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd7si834792ejb.615.2020.07.15.01.52.18; Wed, 15 Jul 2020 01:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729783AbgGOIYz (ORCPT + 99 others); Wed, 15 Jul 2020 04:24:55 -0400 Received: from [195.135.220.15] ([195.135.220.15]:52834 "EHLO mx2.suse.de" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1727086AbgGOIYz (ORCPT ); Wed, 15 Jul 2020 04:24:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6FBD6AEA6; Wed, 15 Jul 2020 08:24:56 +0000 (UTC) Subject: Re: [PATCH 1/4] mm/page_alloc: fix non cma alloc context To: js1304@gmail.com, Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Christoph Hellwig , Roman Gushchin , Mike Kravetz , Naoya Horiguchi , Michal Hocko , "Aneesh Kumar K . V" , Joonsoo Kim , stable@vger.kernel.org References: <1594789529-6206-1-git-send-email-iamjoonsoo.kim@lge.com> From: Vlastimil Babka Message-ID: <332d620b-bfe3-3b69-931b-77e3a74edbfd@suse.cz> Date: Wed, 15 Jul 2020 10:24:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <1594789529-6206-1-git-send-email-iamjoonsoo.kim@lge.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/15/20 7:05 AM, js1304@gmail.com wrote: > From: Joonsoo Kim > > Currently, preventing cma area in page allocation is implemented by using > current_gfp_context(). However, there are two problems of this > implementation. > > First, this doesn't work for allocation fastpath. In the fastpath, > original gfp_mask is used since current_gfp_context() is introduced in > order to control reclaim and it is on slowpath. > Second, clearing __GFP_MOVABLE has a side effect to exclude the memory > on the ZONE_MOVABLE for allocation target. > > To fix these problems, this patch changes the implementation to exclude > cma area in page allocation. Main point of this change is using the > alloc_flags. alloc_flags is mainly used to control allocation so it fits > for excluding cma area in allocation. Agreed, should have been done with ALLOC_CMA since the beginning. > Fixes: d7fefcc (mm/cma: add PF flag to force non cma alloc) More digits please. Fixes: d7fefcc8de91 ("mm/cma: add PF flag to force non cma alloc") > Cc: > Signed-off-by: Joonsoo Kim > --- > include/linux/sched/mm.h | 4 ---- > mm/page_alloc.c | 27 +++++++++++++++------------ > 2 files changed, 15 insertions(+), 16 deletions(-) > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index 44ad5b7..a73847a 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -191,10 +191,6 @@ static inline gfp_t current_gfp_context(gfp_t flags) > flags &= ~(__GFP_IO | __GFP_FS); > else if (pflags & PF_MEMALLOC_NOFS) > flags &= ~__GFP_FS; Above this hunk you should also remove PF_MEMALLOC_NOCMA from the test. > -#ifdef CONFIG_CMA > - if (pflags & PF_MEMALLOC_NOCMA) > - flags &= ~__GFP_MOVABLE; > -#endif > } > return flags; > } > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 6416d08..cd53894 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2791,7 +2791,7 @@ __rmqueue(struct zone *zone, unsigned int order, int migratetype, > * allocating from CMA when over half of the zone's free memory > * is in the CMA area. > */ > - if (migratetype == MIGRATE_MOVABLE && > + if (alloc_flags & ALLOC_CMA && > zone_page_state(zone, NR_FREE_CMA_PAGES) > > zone_page_state(zone, NR_FREE_PAGES) / 2) { > page = __rmqueue_cma_fallback(zone, order); > @@ -2802,7 +2802,7 @@ __rmqueue(struct zone *zone, unsigned int order, int migratetype, > retry: > page = __rmqueue_smallest(zone, order, migratetype); > if (unlikely(!page)) { > - if (migratetype == MIGRATE_MOVABLE) > + if (alloc_flags & ALLOC_CMA) > page = __rmqueue_cma_fallback(zone, order); > > if (!page && __rmqueue_fallback(zone, order, migratetype, > @@ -3502,11 +3502,9 @@ static inline long __zone_watermark_unusable_free(struct zone *z, > if (likely(!alloc_harder)) > unusable_free += z->nr_reserved_highatomic; > > -#ifdef CONFIG_CMA > /* If allocation can't use CMA areas don't use free CMA pages */ > - if (!(alloc_flags & ALLOC_CMA)) > + if (IS_ENABLED(CONFIG_CMA) && !(alloc_flags & ALLOC_CMA)) > unusable_free += zone_page_state(z, NR_FREE_CMA_PAGES); > -#endif > > return unusable_free; > } > @@ -3693,6 +3691,16 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask) > return alloc_flags; > } > > +static inline void current_alloc_flags(gfp_t gfp_mask, > + unsigned int *alloc_flags) > +{ > + unsigned int pflags = READ_ONCE(current->flags); > + > + if (!(pflags & PF_MEMALLOC_NOCMA) && > + gfp_migratetype(gfp_mask) == MIGRATE_MOVABLE) > + *alloc_flags |= ALLOC_CMA; > +} I don't like the modification through parameter, would just do what current_gfp_context() does and return the modified value. Also make it a no-op (including no READ_ONCE(current->flags)) if !CONFIG_CMA, please. > /* > * get_page_from_freelist goes through the zonelist trying to allocate > * a page. > @@ -3706,6 +3714,8 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, > struct pglist_data *last_pgdat_dirty_limit = NULL; > bool no_fallback; > > + current_alloc_flags(gfp_mask, &alloc_flags); I don't see why to move the test here? It will still be executed in the fastpath, if that's what you wanted to avoid. > + > retry: > /* > * Scan zonelist, looking for a zone with enough free. > @@ -4339,10 +4349,6 @@ gfp_to_alloc_flags(gfp_t gfp_mask) > } else if (unlikely(rt_task(current)) && !in_interrupt()) > alloc_flags |= ALLOC_HARDER; > > -#ifdef CONFIG_CMA > - if (gfp_migratetype(gfp_mask) == MIGRATE_MOVABLE) > - alloc_flags |= ALLOC_CMA; > -#endif I would just replace this here with: alloc_flags = current_alloc_flags(gfp_mask, alloc_flags); > return alloc_flags; > } > > @@ -4808,9 +4814,6 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, > if (should_fail_alloc_page(gfp_mask, order)) > return false; > > - if (IS_ENABLED(CONFIG_CMA) && ac->migratetype == MIGRATE_MOVABLE) > - *alloc_flags |= ALLOC_CMA; And same here... Ah, I see. current_alloc_flags() should probably take a migratetype parameter instead of gfp_mask then. > - > return true; > } > >