From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9EA0C433F5 for ; Wed, 11 May 2022 15:09:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F7496B0074; Wed, 11 May 2022 11:09:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A78F6B0075; Wed, 11 May 2022 11:09:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06F896B0078; Wed, 11 May 2022 11:09:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EC7156B0074 for ; Wed, 11 May 2022 11:09:02 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id C2B4680F52 for ; Wed, 11 May 2022 15:09:02 +0000 (UTC) X-FDA: 79453794924.18.3AB588D Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf16.hostedemail.com (Postfix) with ESMTP id 55ADD1800C2 for ; Wed, 11 May 2022 15:08:53 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id w19so4068640lfu.11 for ; Wed, 11 May 2022 08:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KE8F0pAboHlmVpDvIJzJeE3Yh6I2powqB0a7EA++YRI=; b=LR9gjop7+QkUAbsLbkhth1quvU+Y2S26jy9bP0TJc+WR2RfvWtvGRZvLRWY9hDAmPF FQ9i3/sWNaR1Go43p1OV24bGISMi51za4K/IPCh3I5ziNJBSpN2XGn4yhLL1K27WgXkR WfTHj84m779s6NqZ9xE3IKV2WUv5nkHnS9cdlgUiHEaw1zsv8ckS81GzkGsAdF7Huebe H/XuvxEBDFYKfCTzkHaBr3+YHf5elnNigLJReC9TQlKcwQwr197XQTaLmLjm3eBABedz EzF78hiImxo3fe9im1TKS85Y44ntcvp+ngpXj1fix9+/ThCExVzTph9PA22O+TSwdXNV FmQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KE8F0pAboHlmVpDvIJzJeE3Yh6I2powqB0a7EA++YRI=; b=IhFKC+mnsU7RU8bPnyDQD2vr4wFuIb2n9Jah97wEOP3TBLIu0BGWYwmDvT9VNi6PA9 sCuG0DoTmJq9697QtM9CXxf6znX2VscFTjJ0yNWy4OV3h5BHLkQMtqDMsmq4UcXOHMlO JRHENETPZvacM5XKjMBlHm90Q235c5EzeqqvSxuyqPLvbr4N69GgWjFnRTT9lUtA6XYL OhPh0nJmj8sDNOfL87QO34fnDRln4O6u6I6n5obFSiffnTwEhen9wxZSo+h2sUx32uqI BhMEftCDLZVCGTLx7jedDGpOZYFULbX2QstK7SbxHAgFPNRZtHE0ck5hmX2ElTOiMWhY lH/g== X-Gm-Message-State: AOAM530sJx9GF+vnOvlnNJyQVciD1P3qJns+DLyVoZZu//DMDCaOwe75 0+3JmclNIGwJxoiRo19Z1xrFUfIuHRnzJlMMXu+cld6ue/c= X-Google-Smtp-Source: ABdhPJy64G0q+ERl9Hvtunxneij8b0z+R7rktknovQpURcpN78u8b6tRsGXULKT3LZ6wyg8U6Q/OCcPYELZI9gidFh4= X-Received: by 2002:a17:907:980e:b0:6f5:222a:334e with SMTP id ji14-20020a170907980e00b006f5222a334emr23452161ejc.643.1652281361550; Wed, 11 May 2022 08:02:41 -0700 (PDT) MIME-Version: 1.0 References: <20220511081207.132034-1-vvghjk1234@gmail.com> <20220511142303.GN20579@suse.de> In-Reply-To: <20220511142303.GN20579@suse.de> From: Wonhyuk Yang Date: Thu, 12 May 2022 00:02:30 +0900 Message-ID: Subject: Re: [PATCH] mm/page_alloc: Fix tracepoint mm_page_alloc_zone_locked() To: Mel Gorman Cc: Steven Rostedt , Ingo Molnar , Andrew Morton , Baik Song An , Hong Yeon Kim , Taeung Song , linuxgeek@linuxgeek.io, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 55ADD1800C2 X-Stat-Signature: fga7ts3hiih83tyy7mhcjkm3ew4x1dks Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LR9gjop7; spf=pass (imf16.hostedemail.com: domain of vvghjk1234@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=vvghjk1234@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1652281733-266865 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, May 11, 2022 at 11:23 PM Mel Gorman wrote: > > On Wed, May 11, 2022 at 05:12:07PM +0900, Wonhyuk Yang wrote: > > Currently, trace point mm_page_alloc_zone_locked() doesn't show > > correct information. > > > > First, when alloc_flag has ALLOC_HARDER/ALLOC_CMA, page can > > be allocated from MIGRATE_HIGHATOMIC/MIGRATE_CMA. Nevertheless, > > tracepoint use requested migration type not MIGRATE_HIGHATOMIC and > > MIGRATE_CMA. > > > > Second, after Commit 44042b4498728 ("mm/page_alloc: allow high-order > > pages to be stored on the per-cpu lists") percpu-list can store > > high order pages. But trace point determine whether it is a refiil > > of percpu-list by comparing requested order and 0. > > > > To handle these problems, use cached migration type by > > get_pcppage_migratetype() instead of requested migration type. > > Then, make mm_page_alloc_zone_locked() be called only two contexts > > (rmqueue_bulk, rmqueue). With a new argument called percpu_refill, > > it can show whether it is a refill of percpu-list correctly. > > > > You're definitely right that the current tracepoint is broken. > > I got momentarily confused because HIGHATOMIC and CMA are not stored on > PCP lists even though they are a pageblock migrate type. Superficially > calling get_pcppage_migratetype on a page that cannot be a PCP page > seems silly but in the context of this patch, it happens to work because > it was isolated with __rmqueue_smallest which sets the PCP type even if > the page is not going to a PCP list. Yes, I agree that calling get_pcppage_migratetype look quite confusing. > The original intent of that tracepoint was to trace when pages were > removed from the buddy list. That would suggest this untested patch on > top of yours as a simplication; > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 0351808322ba..66a70b898130 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2476,6 +2476,8 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, > del_page_from_free_list(page, zone, current_order); > expand(zone, page, order, current_order, migratetype); > set_pcppage_migratetype(page, migratetype); > + trace_mm_page_alloc_zone_locked(page, order, migratetype, > + pcp_allowed_order(order) && migratetype < MIGRATE_PCPTYPES); > return page; > } Interestingly, my first approach was quite similar your suggestion. But I noticed that there can be a request whose migration type is MOVABLE and alloc_flags doen't have ALLOC_CMA. In that case, page are marked as percpu-refill even though it was allocated from buddy-list directly. Is there no problem if we just ignore this case? > @@ -3025,7 +3027,6 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, > int migratetype, unsigned int alloc_flags) > { > int i, allocated = 0; > - int mt; > > /* > * local_lock_irq held so equivalent to spin_lock_irqsave for > @@ -3053,9 +3054,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, > */ > list_add_tail(&page->lru, list); > allocated++; > - mt = get_pcppage_migratetype(page); > - trace_mm_page_alloc_zone_locked(page, order, mt, true); > - if (is_migrate_cma(mt)) > + if (is_migrate_cma(get_pcppage_migratetype(page))) > __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, > -(1 << order)); > } > @@ -3704,7 +3703,6 @@ struct page *rmqueue(struct zone *preferred_zone, > { > unsigned long flags; > struct page *page; > - int mt; > > if (likely(pcp_allowed_order(order))) { > /* > @@ -3734,17 +3732,15 @@ struct page *rmqueue(struct zone *preferred_zone, > * reserved for high-order atomic allocation, so order-0 > * request should skip it. > */ > - if (order > 0 && alloc_flags & ALLOC_HARDER) { > + if (order > 0 && alloc_flags & ALLOC_HARDER) > page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); > - } > if (!page) { > page = __rmqueue(zone, order, migratetype, alloc_flags); > if (!page) > goto failed; > } > - mt = get_pcppage_migratetype(page); > - trace_mm_page_alloc_zone_locked(page, order, mt, false); > - __mod_zone_freepage_state(zone, -(1 << order), mt); > + __mod_zone_freepage_state(zone, -(1 << order), > + get_pcppage_migratetype(page)); > spin_unlock_irqrestore(&zone->lock, flags); > } while (check_new_pages(page, order)); >