From patchwork Wed Oct 17 06:33:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 10644627 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 007A4112B for ; Wed, 17 Oct 2018 06:33:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4134289D0 for ; Wed, 17 Oct 2018 06:33:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8206289E1; Wed, 17 Oct 2018 06:33:43 +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 56A52289D0 for ; Wed, 17 Oct 2018 06:33:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B7386B0005; Wed, 17 Oct 2018 02:33:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 78C8E6B0006; Wed, 17 Oct 2018 02:33:39 -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 67C466B0007; Wed, 17 Oct 2018 02:33:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 2BC916B0005 for ; Wed, 17 Oct 2018 02:33:39 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id s15-v6so19299013pgv.9 for ; Tue, 16 Oct 2018 23:33:39 -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=qGxadi8yG+CAoBsPLQsJm3DFIcMzGgKrjqFOcxfOzZY=; b=fcH0yCNYBy8swpczHp/nDAhPcUiWzI7dgvGK3TgAr3G6SVv9U9zeXXhhuF4mYNpNKn +6oAPBEDIdPDfBmTeSFrct3hGyWx2W78FYVdOjCaI4fmdRyEk9POVGmV/TND8alyJ9ne rVF1JPDIfppeLnEZidJJMUllwZmv6INof9YZ1nqWSdClIRTCftDCpQTVbB37ohi3Qpk/ mOiSbSymPAr/dJV4V77hx3LFqXoFSlO2vHbx2RyQLZvI0kFFR+WSCGmJTUyGFBjj9u8W 4L/NAHGoxiRgc3JXJhow688x7RbYLrjdooKyIj75WIsZA01XLdOXLkmEHRljPutxVaF7 1/Aw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.20 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: ABuFfoiklODxlWtX7liDG0NW58ETCp08hDW1y1GzIapXTR47Hv61W0aI l/MM3GC73h94HanHvtbI/twBi1mV/m3vAR/g5BA+6pTieRk6kb5vqTouKxQCIK4sncv2u1kL0RD 7UJbRNphHFf3S2oWF2MUO6L0BlkRuXKxY7+I5q0ceJCvppLiy6AC0BBmBvIKNvHPbuA== X-Received: by 2002:a63:9c3:: with SMTP id 186-v6mr23431560pgj.249.1539758018850; Tue, 16 Oct 2018 23:33:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV62MWMwhFp8vrHGTUea4X5lcoAvS3YFhh8/V5Dp2PI1nkfQHeldL3o6/jnxr+HaNwQk1EFqH X-Received: by 2002:a63:9c3:: with SMTP id 186-v6mr23431518pgj.249.1539758017792; Tue, 16 Oct 2018 23:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539758017; cv=none; d=google.com; s=arc-20160816; b=H2VG8TSyoShBB+ah1HDEnkkC6nDEcecYKkg3gN0wgXgnTm6LevAz7rrJszYruXvZLg gMOLVzY9HPdqnm8/R8CBAutNaopBD8ENiuCWcgqBzMN6XfvRKfD3YYRfdYYLpVcLjRgg VGURCmOAf88YDz/bN6sgOlRe0EweLjJKpYK3MWFdB7lqjOxOuRPOCaxUP7b/bNg7O6rl wVBPipYvrgEMe9HO3jdpchjs7CRHiLrBznDbuVyc7tYCGOYziphWIcAxiiwlOr8Ik5VX kRD4tTQPdmW+ZyIHb2yQOBixQFBiCSu75cC6HuyyBm7oSCycHaJDFrA3b08gvu4S+KAW hkUw== 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=qGxadi8yG+CAoBsPLQsJm3DFIcMzGgKrjqFOcxfOzZY=; b=SpjslZQHLMkjnLKWbZnLQpEdCpv81s5l/YpJWa12vDLZVhP5XzUUn1hQOqYwAxkomK 5UwcJWpnA1A3fSELk2IOnDBcqeRlgYv5n1ixwX3f+QCvMlBiYmjVbix829h0QwHxjz6x Fq/LKMyBmHZCHtZ6t7FliOQD4aWgQHExAeOGor3qK+StvLIOrtqIHwDq9w7xvLt/IG9g G9/5j36MpMB2PYfuCqK/IESrdvHP5iEsT9papI3vHKFmMSYZB+bWxa2Vc376LjkNePsw nnpL5O8DC59UWNDkh4OiHZatJzA5TAIfPMcWV+gRyT1k4zLJiZ92pggiyKBc/7DPq1FA zooQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTPS id f2-v6si16427856pgf.423.2018.10.16.23.33.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Oct 2018 23:33:37 -0700 (PDT) Received-SPF: pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.20 as permitted sender) client-ip=134.134.136.20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.20 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 orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 23:33:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,391,1534834800"; d="scan'208";a="273090072" Received: from aaronlu.sh.intel.com ([10.239.159.44]) by fmsmga006.fm.intel.com with ESMTP; 16 Oct 2018 23:33:34 -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 , Jesper Dangaard Brouer Subject: [RFC v4 PATCH 1/5] mm/page_alloc: use helper functions to add/remove a page to/from buddy Date: Wed, 17 Oct 2018 14:33:26 +0800 Message-Id: <20181017063330.15384-2-aaron.lu@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181017063330.15384-1-aaron.lu@intel.com> References: <20181017063330.15384-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 Acked-by: Mel Gorman --- 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 89d2a2ab3fe6..14c20bb3a3da 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 @@ -8070,9 +8085,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);