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>
Subject: [PATCH 2/2] mm/page_alloc: use a single function to free page
Date: Mon,  5 Nov 2018 16:58:20 +0800	[thread overview]
Message-ID: <20181105085820.6341-2-aaron.lu@intel.com> (raw)
In-Reply-To: <20181105085820.6341-1-aaron.lu@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 and left in another.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 mm/page_alloc.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 91a9a6af41a2..2b330296e92a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4425,9 +4425,17 @@ unsigned long get_zeroed_page(gfp_t gfp_mask)
 }
 EXPORT_SYMBOL(get_zeroed_page);
 
-void __free_pages(struct page *page, unsigned int order)
+/*
+ * Free a page by reducing its ref count by @nr.
+ * If its refcount reaches 0, then according to its order:
+ * order0: send to PCP;
+ * high order: directly send to Buddy.
+ */
+static inline void free_the_page(struct page *page, unsigned int order, int nr)
 {
-	if (put_page_testzero(page)) {
+	VM_BUG_ON_PAGE(page_ref_count(page) == 0, page);
+
+	if (page_ref_sub_and_test(page, nr)) {
 		if (order == 0)
 			free_unref_page(page);
 		else
@@ -4435,6 +4443,11 @@ void __free_pages(struct page *page, unsigned int order)
 	}
 }
 
+void __free_pages(struct page *page, unsigned int order)
+{
+	free_the_page(page, order, 1);
+}
+
 EXPORT_SYMBOL(__free_pages);
 
 void free_pages(unsigned long addr, unsigned int order)
@@ -4481,16 +4494,7 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc,
 
 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);
-	}
+	free_the_page(page, compound_order(page), count);
 }
 EXPORT_SYMBOL(__page_frag_cache_drain);
 
@@ -4555,14 +4559,7 @@ 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);
-	}
+	free_the_page(page, compound_order(page), 1);
 }
 EXPORT_SYMBOL(page_frag_free);
 
-- 
2.17.2


  reply	other threads:[~2018-11-05  8:58 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 ` Aaron Lu [this message]
2018-11-05 16:39   ` [PATCH 2/2] mm/page_alloc: use a single function to free page 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     ` [PATCH v3 " Aaron Lu
2018-11-06 12:06       ` 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=20181105085820.6341-2-aaron.lu@intel.com \
    --to=aaron.lu@intel.com \
    --cc=akpm@linux-foundation.org \
    --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.