Received: by 10.192.165.148 with SMTP id m20csp5255001imm; Wed, 9 May 2018 01:54:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwTV+66x0UdwR6sNzb/x1R+GZGVurp7wokbiBa/5xrQzwqdgQs7Pu4LBlewmZtwjPcwyX3 X-Received: by 2002:a17:902:7283:: with SMTP id d3-v6mr21839012pll.192.1525856061951; Wed, 09 May 2018 01:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525856061; cv=none; d=google.com; s=arc-20160816; b=DZ3wuGu27UK20hNc+tfC1XIVSYz8gQu5/dd+8I1MMcRuhWql59SGnihKBSmyWPsYPI PyGFjBLo8JBY4ECFmc4Bb4fIwVJ1v3BG3a6Btk4LPWjz+yZaaXdtIpoUJta37bYv/Ipd Sh/Zq4qFnaicztOMllSZl97cI0v4UPaeAcwfg6QL7Su357eTt7McMOAGlS7bAv4TGvY4 LjfW4AM58lWn6IkOtVuPkuS8A6ZtnjeUUZM+TLQ4yIYIiAd4kByY4toVOcydIu6qt4tD K8uNSIV/CEnD3h1L5egi3uzsYW3EpAOqoJGwAJ7M/ONojQKJSiBPSqmaoAsXLcfcqbR/ wIYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=XtyS1IEb8ucVQU9d/Uaufdo5nrXE0RdqxjuPxKPeVRg=; b=yf/QLXNq6BesJOy3o4whn+KVfbbD886+KsBfyu91kIuNIRe9KKlsQ5yDd0nhhr/Lry WkUwwDwWSiSLWysMRsWawNhfWxLtPywVxDZRQmTIZoPpuhQbjJfFSh9AUFeG0dXtfH6M kvboaKKCAi82KAkytSYC7tdxUCwAvoOnlmK2wJtU6MXHv8qGtGbY50eaQZJDqw0k2Z+c 85AI82WQhqqJcHxYcl4u+x6YeLHWD41BvYsGKrJ4FWyayQz/0jJE/ZuXCstUh203wrsE WIlkX0rIa0EB+AHrCEgIPjW/Ls7AU3Ukr3waqigiA2KVfjHdZZ1B/1cgSJmMDN69oOaQ W4Wg== 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 k3-v6si26205729pld.9.2018.05.09.01.54.07; Wed, 09 May 2018 01:54:21 -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 S934254AbeEIIxj (ORCPT + 99 others); Wed, 9 May 2018 04:53:39 -0400 Received: from mga03.intel.com ([134.134.136.65]:31336 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934079AbeEIIx3 (ORCPT ); Wed, 9 May 2018 04:53:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 01:53:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,381,1520924400"; d="scan'208";a="227055148" Received: from aaronlu.sh.intel.com ([10.239.159.135]) by fmsmga006.fm.intel.com with ESMTP; 09 May 2018 01:53:26 -0700 From: Aaron Lu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Huang Ying , Dave Hansen , Kemi Wang , Tim Chen , Andi Kleen , Michal Hocko , Vlastimil Babka , Mel Gorman , Matthew Wilcox , Daniel Jordan , Tariq Toukan Subject: [RFC v3 PATCH 1/5] mm/page_alloc: use helper functions to add/remove a page to/from buddy Date: Wed, 9 May 2018 16:54:46 +0800 Message-Id: <20180509085450.3524-2-aaron.lu@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180509085450.3524-1-aaron.lu@intel.com> References: <20180509085450.3524-1-aaron.lu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Acked-by: Vlastimil Babka 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 905db9d7962f..a92afa362e1f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -697,12 +697,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) +{ + set_page_order(page, order); + zone->free_area[order].nr_free++; +} + +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); + 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); + 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 @@ -806,13 +835,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; @@ -844,8 +870,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 @@ -862,15 +886,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); } /* @@ -1830,9 +1851,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); } } @@ -1976,9 +1995,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; @@ -2896,9 +2913,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 @@ -8032,9 +8047,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); -- 2.14.3