Received: by 10.213.65.68 with SMTP id h4csp434216imn; Tue, 20 Mar 2018 06:52:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELvoQklUqWWSMHF4kzBGxlrfUyHa4gKppDSNdTDpQQQdGZRu3+0C0u7gWLLq5WqAdg6vHPvJ X-Received: by 2002:a17:902:8481:: with SMTP id c1-v6mr6544458plo.304.1521553977423; Tue, 20 Mar 2018 06:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521553977; cv=none; d=google.com; s=arc-20160816; b=CB/C/Ia/G5jSgB/r4JSfPY/UuWMlRCPbtl/r6Q8v7OJPEqJeQ3r0yoq7dfl5i1eAL8 Vwx0wtRlQz8AW8hZJPBtoNEmrmIWcrzRPaGGbGPbEpCEm/9b++ua/fuxQCL4RsDFrfrF I3DcPVsz2zQR9HK4FVeA0jdNhSxrGcregOYdN77r77YAGF/kAy6/qqdE4gZHSqAgH0vX Lw9PMdmVjPM1eCHc8WAdftooL7xrrJ7uvqPnmpHNuDnqbpa47gfjacjK2KNigni4ll2S riTZ+9NA++yeODJKJibCuRmvxevgNj3XsDX2ZPaY+pzgXiW9WGXD76DsI+rkkb6cnAzF gOZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=rU1yCqsKDTk98+pwsOip66rik26exKaZ/MUpNiJxjMU=; b=M6RuZJkIxayuZS8E1+/g8+nVl6qdRS1b4KpvFWou9MmwWVSsHnEEwzrH/+/gqUxi/w 0/1iOjhSXoJUhPoaE+V4Bq5Lz2lA6xM5crnG+fT0ql5xE4MrWnGKwdd8T5g0Uy+5omh5 +XsXgcoHInxhpJbCf0Fiy7+n0eFbVjIlUfHkVRpNEbyVzqRsinPA3wWQkOvSPNck+AEM IGA2nPlyn4QdQOPDMbdb3c03RaM9h6xD8cY5k4QiquA5Zr7E1qBAsvjPY4UzNVuyBHNL SPQJ3lskOwfUnUV5fgMQ74PUzKg+nY33V3qlR0GLyKUeoqeeAhgcNs2wQS0iBFHg07mh hRBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si1190778pgo.753.2018.03.20.06.52.42; Tue, 20 Mar 2018 06:52:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753498AbeCTNu0 (ORCPT + 99 others); Tue, 20 Mar 2018 09:50:26 -0400 Received: from mga02.intel.com ([134.134.136.20]:42662 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753227AbeCTNuZ (ORCPT ); Tue, 20 Mar 2018 09:50:25 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2018 06:50:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,335,1517904000"; d="scan'208";a="26042033" Received: from yangrich-mobl1.amr.corp.intel.com (HELO intel.com) ([10.254.209.181]) by fmsmga008.fm.intel.com with ESMTP; 20 Mar 2018 06:50:21 -0700 Date: Tue, 20 Mar 2018 21:50:20 +0800 From: Aaron Lu To: Vlastimil Babka Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Huang Ying , Dave Hansen , Kemi Wang , Tim Chen , Andi Kleen , Michal Hocko , Mel Gorman , Matthew Wilcox , Daniel Jordan Subject: Re: [RFC PATCH v2 1/4] mm/page_alloc: use helper functions to add/remove a page to/from buddy Message-ID: <20180320135019.GA2033@intel.com> References: <20180320085452.24641-1-aaron.lu@intel.com> <20180320085452.24641-2-aaron.lu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 20, 2018 at 12:35:46PM +0100, Vlastimil Babka wrote: > On 03/20/2018 09:54 AM, Aaron Lu wrote: > > There are multiple places that add/remove a page into/from buddy, > > introduce helper functions for them. > > > > This also makes it easier to add code when a page is added/removed > > to/from buddy. > > > > Signed-off-by: Aaron Lu > > --- > > mm/page_alloc.c | 65 ++++++++++++++++++++++++++++++++++----------------------- > > 1 file changed, 39 insertions(+), 26 deletions(-) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 3db9cfb2265b..3cdf1e10d412 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -736,12 +736,41 @@ static inline void set_page_order(struct page *page, unsigned int order) > > __SetPageBuddy(page); > > } > > > > +static inline void add_to_buddy_common(struct page *page, struct zone *zone, > > + unsigned int order, int mt) > > +{ > > + set_page_order(page, order); > > + zone->free_area[order].nr_free++; > > The 'mt' parameter seems unused here. Otherwise An right, forgot to remove it... > > Acked-by: Vlastimil Babka Thanks! > > > +} > > + > > +static inline void add_to_buddy_head(struct page *page, struct zone *zone, > > + unsigned int order, int mt) > > +{ > > + add_to_buddy_common(page, zone, order, mt); > > + list_add(&page->lru, &zone->free_area[order].free_list[mt]); > > +} > > + > > +static inline void add_to_buddy_tail(struct page *page, struct zone *zone, > > + unsigned int order, int mt) > > +{ > > + add_to_buddy_common(page, zone, order, mt); > > + list_add_tail(&page->lru, &zone->free_area[order].free_list[mt]); > > +} > > + > > static inline void rmv_page_order(struct page *page) > > { > > __ClearPageBuddy(page); > > set_page_private(page, 0); > > } > > > > +static inline void remove_from_buddy(struct page *page, struct zone *zone, > > + unsigned int order) > > +{ > > + list_del(&page->lru); > > + zone->free_area[order].nr_free--; > > + rmv_page_order(page); > > +} > > + > > /* > > * This function checks whether a page is free && is the buddy > > * we can do coalesce a page and its buddy if > > @@ -845,13 +874,10 @@ static inline void __free_one_page(struct page *page, > > * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, > > * merge with it and move up one order. > > */ > > - if (page_is_guard(buddy)) { > > + if (page_is_guard(buddy)) > > clear_page_guard(zone, buddy, order, migratetype); > > - } else { > > - list_del(&buddy->lru); > > - zone->free_area[order].nr_free--; > > - rmv_page_order(buddy); > > - } > > + else > > + remove_from_buddy(buddy, zone, order); > > combined_pfn = buddy_pfn & pfn; > > page = page + (combined_pfn - pfn); > > pfn = combined_pfn; > > @@ -883,8 +909,6 @@ static inline void __free_one_page(struct page *page, > > } > > > > done_merging: > > - set_page_order(page, order); > > - > > /* > > * If this is not the largest possible page, check if the buddy > > * of the next-highest order is free. If it is, it's possible > > @@ -901,15 +925,12 @@ static inline void __free_one_page(struct page *page, > > higher_buddy = higher_page + (buddy_pfn - combined_pfn); > > if (pfn_valid_within(buddy_pfn) && > > page_is_buddy(higher_page, higher_buddy, order + 1)) { > > - list_add_tail(&page->lru, > > - &zone->free_area[order].free_list[migratetype]); > > - goto out; > > + add_to_buddy_tail(page, zone, order, migratetype); > > + return; > > } > > } > > > > - list_add(&page->lru, &zone->free_area[order].free_list[migratetype]); > > -out: > > - zone->free_area[order].nr_free++; > > + add_to_buddy_head(page, zone, order, migratetype); > > } > > > > /* > > @@ -1731,9 +1752,7 @@ static inline void expand(struct zone *zone, struct page *page, > > if (set_page_guard(zone, &page[size], high, migratetype)) > > continue; > > > > - list_add(&page[size].lru, &area->free_list[migratetype]); > > - area->nr_free++; > > - set_page_order(&page[size], high); > > + add_to_buddy_head(&page[size], zone, high, migratetype); > > } > > } > > > > @@ -1877,9 +1896,7 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, > > struct page, lru); > > if (!page) > > continue; > > - list_del(&page->lru); > > - rmv_page_order(page); > > - area->nr_free--; > > + remove_from_buddy(page, zone, current_order); > > expand(zone, page, order, current_order, area, migratetype); > > set_pcppage_migratetype(page, migratetype); > > return page; > > @@ -2795,9 +2812,7 @@ int __isolate_free_page(struct page *page, unsigned int order) > > } > > > > /* Remove page from free list */ > > - list_del(&page->lru); > > - zone->free_area[order].nr_free--; > > - rmv_page_order(page); > > + remove_from_buddy(page, zone, order); > > > > /* > > * Set the pageblock if the isolated page is at least half of a > > @@ -7886,9 +7901,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) > > pr_info("remove from free list %lx %d %lx\n", > > pfn, 1 << order, end_pfn); > > #endif > > - list_del(&page->lru); > > - rmv_page_order(page); > > - zone->free_area[order].nr_free--; > > + remove_from_buddy(page, zone, order); > > for (i = 0; i < (1 << order); i++) > > SetPageReserved((page+i)); > > pfn += (1 << order); > > >