From patchwork Tue Sep 11 05:36:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 10595069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22F0D921 for ; Tue, 11 Sep 2018 05:36:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 128382902E for ; Tue, 11 Sep 2018 05:36:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04E76292AD; Tue, 11 Sep 2018 05:36:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6553E2902E for ; Tue, 11 Sep 2018 05:36:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35C388E0008; Tue, 11 Sep 2018 01:36:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2E3ED8E0001; Tue, 11 Sep 2018 01:36:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15EDD8E0008; Tue, 11 Sep 2018 01:36:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id BDC3A8E0001 for ; Tue, 11 Sep 2018 01:36:35 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id j15-v6so12358643pfi.10 for ; Mon, 10 Sep 2018 22:36:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=MPZK49hQvw81fghu4GWNsKHbGZXfgYk2uY7Qgh648So=; b=KVL5PSoqwNpFO4NgavkR2klvVT9Gs4NqdI5njQVWfmYsF3X5mzzRSYy7vjb0lS89Ux VXhntUb+m+tHTbScvNn6LO+qNZ9PXhZO4z/HDdXgorIQBLQbhSC62eCg50YFSBvjD7Ne 4B023VR+sraobLD/5FalNN0wDdJreXv4auYiolD0yT2XUD7FHC8ooiMSm7pzTmpUEumv HnYeOcAAXwrxzlAprpWxp2pdWMe/30QtsltyCc7JaALS5J7Kvejr3ckZMx6mZbP7uXCk wDEyASdHYWX7lxvUKuaAs6jBY+btEAIcyvLzxqjBzD4sT0hVgQ1rI6GSLk/DK8OQjij5 TY2w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APzg51C9yRy0M+zHgrwhJSxSx3QohQN6QVH1Qqh9Fb6H6Tn9wj6kqDaB Zj/YkA9nifJ+YNpIuDtn83JfPBTSnWkaVoIxcZW36d8hRqA8NQYHNb5uMeRmhaF0ww2DJKccCqE ka1/uqwIcPZ+87TWLuahwl8OzgkgiZI+dDsBUI1rhg++jSoQIhWqXe0U4kKSVkzUv2g== X-Received: by 2002:a63:77ce:: with SMTP id s197-v6mr26709000pgc.172.1536644195428; Mon, 10 Sep 2018 22:36:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaLkM7hklUGnlZxX2+SwSW3xMJIJ7NV8a+CWPMrHYEIWBi6AeDUE6faNnDdIbNBPI5uWQxo X-Received: by 2002:a63:77ce:: with SMTP id s197-v6mr26708950pgc.172.1536644194663; Mon, 10 Sep 2018 22:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536644194; cv=none; d=google.com; s=arc-20160816; b=R6eZiZhmxI/Dg36IlTqLQdlVf1AURuUtBesbclNCp2HoEqcHeUing3iJ0fDGLYdO0d nxN2/r6Rm3ne9/1OnubPuqQBo3vmF81SwWqPAqlcQOYXift6rbQ5aS9VVF80q+aPPRzP OtgnQAIUMqyUcjM4cW6E/Gy9gM0Od91utfttTTHrPnTU8SohNGyvu7eFRXAH4fynPKqk dhHb7aXi37oy8kG4d1U+uqUK9W+g1rLOaplzrPCwhoTYyBFC8c/7BNXYGCTG7SOcfGQC tQFHdEdYvWpXGKYmpHfjmCabsc+S4g2AUCeGo+SbFVqaYuB5rlGIEnrMNIOHfCHWewZf C77A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=MPZK49hQvw81fghu4GWNsKHbGZXfgYk2uY7Qgh648So=; b=QelaVM0lqm6J387hCPZ9uUkz0qbnBq9ffuMYETeZRYhDFKbGwk7Mi2w27HIEgaaOr9 mDoSs9bAPZGmaBUx3CkQ/Q7nHA1GhpcwjTmhSwD/Be99iGLIGiiCxQBSZ3eXwur9zgQI T21nbg5XOyYVyZaWHtNVjl9fGkYCmzNMkkJwly1/oCbFW+/tKKvvdcqCvHZyCWiGzdHE S3cOjZpuRgJzSLKWy1duGlTiqFl+5xXCcMNMFZUn2JMjhN5eT7aiAvZmN4nwlyTGQ6SU D8UswnWd+2FuaPzAnuPHv0Vaze3l0+WLtSlEdKfozkEvtTG4bmOB5CvwlxZjNoQ6uRdZ 42/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id c19-v6si20646945pfc.18.2018.09.10.22.36.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 22:36:34 -0700 (PDT) Received-SPF: pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 22:36:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,359,1531810800"; d="scan'208";a="262426333" Received: from aaronlu.sh.intel.com ([10.239.159.44]) by fmsmga006.fm.intel.com with ESMTP; 10 Sep 2018 22:36:31 -0700 From: Aaron Lu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Dave Hansen , Michal Hocko , Vlastimil Babka , Mel Gorman , Matthew Wilcox , Daniel Jordan , Tariq Toukan , Yosef Lev , Jesper Dangaard Brouer Subject: [RFC PATCH 5/9] mm/page_alloc: use helper functions to add/remove a page to/from buddy Date: Tue, 11 Sep 2018 13:36:12 +0800 Message-Id: <20180911053616.6894-6-aaron.lu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180911053616.6894-1-aaron.lu@intel.com> References: <20180911053616.6894-1-aaron.lu@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP 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. No functionality change. 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 38e39ccdd6d9..d0b954783f1d 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 coalesce a page and its buddy if @@ -803,13 +832,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; @@ -841,8 +867,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 @@ -859,15 +883,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); } /* @@ -1805,9 +1826,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); } } @@ -1951,9 +1970,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; @@ -2871,9 +2888,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 @@ -8066,9 +8081,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);