All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lu <aaron.lu@intel.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Paweł Staszewski" <pstaszewski@itcare.pl>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Eric Dumazet" <eric.dumazet@gmail.com>,
	"Tariq Toukan" <tariqt@mellanox.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Yoel Caspersen" <yoel@kviknet.dk>,
	"Mel Gorman" <mgorman@techsingularity.net>,
	"Saeed Mahameed" <saeedm@mellanox.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Alexander Duyck" <alexander.h.duyck@linux.intel.com>
Subject: [PATCH v3 2/2] mm/page_alloc: use a single function to free page
Date: Tue, 6 Nov 2018 19:31:49 +0800	[thread overview]
Message-ID: <20181106113149.GC24198@intel.com> (raw)
In-Reply-To: <20181106053037.GD6203@intel.com>

We have multiple places of freeing a page, most of them doing similar
things and a common function can be used to reduce code duplicate.

It also avoids bug fixed in one function but left in another.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
v3: Vlastimil mentioned the possible performance loss by using
    page_ref_sub_and_test(page, 1) for put_page_testzero(page), since
    we aren't sure so be safe by keeping page ref decreasing code as
    is, only move freeing page part to a common function.

 mm/page_alloc.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 91a9a6af41a2..431a03aa96f8 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4425,16 +4425,19 @@ unsigned long get_zeroed_page(gfp_t gfp_mask)
 }
 EXPORT_SYMBOL(get_zeroed_page);
 
-void __free_pages(struct page *page, unsigned int order)
+static inline void free_the_page(struct page *page, unsigned int order)
 {
-	if (put_page_testzero(page)) {
-		if (order == 0)
-			free_unref_page(page);
-		else
-			__free_pages_ok(page, order);
-	}
+	if (order == 0)
+		free_unref_page(page);
+	else
+		__free_pages_ok(page, order);
 }
 
+void __free_pages(struct page *page, unsigned int order)
+{
+	if (put_page_testzero(page))
+		free_the_page(page, order);
+}
 EXPORT_SYMBOL(__free_pages);
 
 void free_pages(unsigned long addr, unsigned int order)
@@ -4483,14 +4486,8 @@ void __page_frag_cache_drain(struct page *page, unsigned int count)
 {
 	VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);
 
-	if (page_ref_sub_and_test(page, count)) {
-		unsigned int order = compound_order(page);
-
-		if (order == 0)
-			free_unref_page(page);
-		else
-			__free_pages_ok(page, order);
-	}
+	if (page_ref_sub_and_test(page, count))
+		free_the_page(page, compound_order(page));
 }
 EXPORT_SYMBOL(__page_frag_cache_drain);
 
@@ -4555,14 +4552,8 @@ void page_frag_free(void *addr)
 {
 	struct page *page = virt_to_head_page(addr);
 
-	if (unlikely(put_page_testzero(page))) {
-		unsigned int order = compound_order(page);
-
-		if (order == 0)
-			free_unref_page(page);
-		else
-			__free_pages_ok(page, order);
-	}
+	if (unlikely(put_page_testzero(page)))
+		free_the_page(page, compound_order(page));
 }
 EXPORT_SYMBOL(page_frag_free);
 
-- 
2.17.2


  parent reply	other threads:[~2018-11-06 11:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-05  8:58 [PATCH 1/2] mm/page_alloc: free order-0 pages through PCP in page_frag_free() Aaron Lu
2018-11-05  8:58 ` Aaron Lu
2018-11-05  8:58 ` [PATCH 2/2] mm/page_alloc: use a single function to free page Aaron Lu
2018-11-05 16:39   ` Dave Hansen
2018-11-06  5:30   ` [PATCH v2 " Aaron Lu
2018-11-06  8:16     ` Vlastimil Babka
2018-11-06  8:47       ` Aaron Lu
2018-11-06  9:32         ` Vlastimil Babka
2018-11-06 11:20           ` Aaron Lu
2018-11-06 11:31     ` Aaron Lu [this message]
2018-11-06 12:06       ` [PATCH v3 " Vlastimil Babka
2018-11-05  9:26 ` [PATCH 1/2] mm/page_alloc: free order-0 pages through PCP in page_frag_free() Vlastimil Babka
2018-11-05  9:26   ` Vlastimil Babka
2018-11-05  9:26 ` Mel Gorman
2018-11-05  9:26   ` Mel Gorman
2018-11-05  9:55 ` Jesper Dangaard Brouer
2018-11-05 10:46 ` Ilias Apalodimas
2018-11-05 10:46   ` Ilias Apalodimas
2018-11-05 15:44 ` Alexander Duyck
2018-11-10 23:54   ` Paweł Staszewski
2018-11-10 23:54     ` Paweł Staszewski
2018-11-11 23:05     ` Alexander Duyck
2018-11-12  0:39       ` Paweł Staszewski
2018-11-12  0:39         ` Paweł Staszewski
2018-11-12 15:30         ` Alexander Duyck
2018-11-12 15:44           ` Eric Dumazet
2018-11-12 17:06             ` Paweł Staszewski
2018-11-12 17:06               ` Paweł Staszewski
2018-11-12 17:01           ` Paweł Staszewski
2018-11-12 17:01             ` Paweł Staszewski
2018-11-05 16:37 ` Dave Hansen
2018-11-06  5:28 ` [PATCH v2 " Aaron Lu
2018-11-06  5:28   ` Aaron Lu
2018-11-07  9:59   ` Tariq Toukan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181106113149.GC24198@intel.com \
    --to=aaron.lu@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.h.duyck@linux.intel.com \
    --cc=brouer@redhat.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=eric.dumazet@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=netdev@vger.kernel.org \
    --cc=pstaszewski@itcare.pl \
    --cc=saeedm@mellanox.com \
    --cc=tariqt@mellanox.com \
    --cc=vbabka@suse.cz \
    --cc=yoel@kviknet.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.