From: Mel Gorman <mgorman@suse.de>
To: Linux-MM <linux-mm@kvack.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>, Dave Hansen <dave@sr71.net>,
Christoph Lameter <cl@linux.com>,
LKML <linux-kernel@vger.kernel.org>, Mel Gorman <mgorman@suse.de>
Subject: [PATCH 20/22] mm: page allocator: Hold magazine lock for a batch of pages
Date: Wed, 8 May 2013 17:03:05 +0100 [thread overview]
Message-ID: <1368028987-8369-21-git-send-email-mgorman@suse.de> (raw)
In-Reply-To: <1368028987-8369-1-git-send-email-mgorman@suse.de>
free_base_page_list() frees a list of pages. This patch will batch
the magazine lock for the list of pages if possible.
Signed-off-by: Mel Gorman <mgorman@suse.de>
---
mm/page_alloc.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 61 insertions(+), 14 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 727c8d3..cf31191 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1236,15 +1236,13 @@ static void magazine_drain(struct zone *zone, struct free_magazine *mag,
spin_unlock_irqrestore(&zone->lock, flags);
}
-/* Free a 0-order page */
-void free_base_page(struct page *page)
+/* Prepare a page for freeing and return its migratetype */
+static inline int free_base_page_prep(struct page *page)
{
- struct zone *zone = page_zone(page);
- struct free_magazine *mag;
int migratetype;
if (!free_pages_prepare(page, 0))
- return;
+ return -1;
migratetype = get_pageblock_migratetype(page);
@@ -1256,24 +1254,46 @@ void free_base_page(struct page *page)
* excessively into the page allocator
*/
if (migratetype >= MIGRATE_PCPTYPES) {
- if (unlikely(is_migrate_isolate(migratetype))) {
- free_one_page(zone, page, 0, migratetype);
- return;
- }
- migratetype = MIGRATE_MOVABLE;
+ if (likely(!is_migrate_isolate(migratetype)))
+ migratetype = MIGRATE_MOVABLE;
}
+
+ set_freepage_migratetype(page, migratetype);
+
+ return migratetype;
+}
+
+/* Put the free page on the magazine list with magazine lock held */
+static inline void __free_base_page(struct zone *zone,
+ struct free_area_magazine *area,
+ struct page *page, int migratetype)
+{
+ list_add(&page->lru, &area->free_list[migratetype]);
+ area->nr_free++;
+}
+
+/* Free a 0-order page */
+void free_base_page(struct page *page)
+{
+ struct zone *zone = page_zone(page);
+ struct free_magazine *mag;
+ int migratetype;
+
+ migratetype = free_base_page_prep(page);
+ if (migratetype == -1)
+ return;
set_freepage_migratetype(page, migratetype);
/* magazine_lock is not safe against IRQs */
- if (in_interrupt() || irqs_disabled()) {
+ if (migratetype >= MIGRATE_PCPTYPES || in_interrupt() ||
+ irqs_disabled()) {
free_one_page(zone, page, 0, migratetype);
return;
}
/* Put the free page on the magazine list */
mag = lock_magazine(zone);
- list_add(&page->lru, &mag->area.free_list[migratetype]);
- mag->area.nr_free++;
+ __free_base_page(zone, &mag->area, page, migratetype);
/* Drain the magazine if necessary, releases the magazine lock */
magazine_drain(zone, mag, migratetype);
@@ -1283,11 +1303,38 @@ void free_base_page(struct page *page)
void free_base_page_list(struct list_head *list)
{
struct page *page, *next;
+ struct zone *locked_zone = NULL;
+ struct free_magazine *mag = NULL;
+ bool use_magazine = (!in_interrupt() && !irqs_disabled());
+ int migratetype = MIGRATE_UNMOVABLE;
+ /* Similar to free_hot_cold_page except magazine lock is batched */
list_for_each_entry_safe(page, next, list, lru) {
+ struct zone *zone = page_zone(page);
+ int migratetype;
+
trace_mm_page_free_batched(page);
- free_base_page(page);
+ migratetype = free_base_page_prep(page);
+ if (migratetype == -1)
+ continue;
+
+ if (!use_magazine || migratetype >= MIGRATE_PCPTYPES) {
+ free_one_page(zone, page, 0, migratetype);
+ continue;
+ }
+
+ if (zone != locked_zone) {
+ /* Drain unlocks magazine lock */
+ if (locked_zone)
+ magazine_drain(locked_zone, mag, migratetype);
+ mag = lock_magazine(zone);
+ locked_zone = zone;
+ }
+ __free_base_page(zone, &mag->area, page, migratetype);
}
+
+ if (locked_zone)
+ magazine_drain(locked_zone, mag, migratetype);
}
/*
--
1.8.1.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-05-08 16:03 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-08 16:02 [RFC PATCH 00/22] Per-cpu page allocator replacement prototype Mel Gorman
2013-05-08 16:02 ` [PATCH 01/22] mm: page allocator: Lookup pageblock migratetype with IRQs enabled during free Mel Gorman
2013-05-08 16:02 ` [PATCH 02/22] mm: page allocator: Push down where IRQs are disabled during page free Mel Gorman
2013-05-08 16:02 ` [PATCH 03/22] mm: page allocator: Use unsigned int for order in more places Mel Gorman
2013-05-08 16:02 ` [PATCH 04/22] mm: page allocator: Only check migratetype of pages being drained while CMA active Mel Gorman
2013-05-08 16:02 ` [PATCH 05/22] oom: Use number of online nodes when deciding whether to suppress messages Mel Gorman
2013-05-08 16:02 ` [PATCH 06/22] mm: page allocator: Convert hot/cold parameter and immediate callers to bool Mel Gorman
2013-05-08 16:02 ` [PATCH 07/22] mm: page allocator: Do not lookup the pageblock migratetype during allocation Mel Gorman
2013-05-08 16:02 ` [PATCH 08/22] mm: page allocator: Remove the per-cpu page allocator Mel Gorman
2013-05-08 16:02 ` [PATCH 09/22] mm: page allocator: Allocate/free order-0 pages from a per-zone magazine Mel Gorman
2013-05-08 18:41 ` Christoph Lameter
2013-05-09 15:23 ` Mel Gorman
2013-05-09 16:21 ` Christoph Lameter
2013-05-09 17:27 ` Mel Gorman
2013-05-09 18:08 ` Christoph Lameter
2013-05-08 16:02 ` [PATCH 10/22] mm: page allocator: Allocate and free pages from magazine in batches Mel Gorman
2013-05-08 16:02 ` [PATCH 11/22] mm: page allocator: Shrink the magazine to the migratetypes in use Mel Gorman
2013-05-08 16:02 ` [PATCH 12/22] mm: page allocator: Remove knowledge of hot/cold from page allocator Mel Gorman
2013-05-08 16:02 ` [PATCH 13/22] mm: page allocator: Use list_splice to refill the magazine Mel Gorman
2013-05-08 16:02 ` [PATCH 14/22] mm: page allocator: Do not disable IRQs just to update stats Mel Gorman
2013-05-08 16:03 ` [PATCH 15/22] mm: page allocator: Check if interrupts are enabled only once per allocation attempt Mel Gorman
2013-05-08 16:03 ` [PATCH 16/22] mm: page allocator: Remove coalescing improvement heuristic during page free Mel Gorman
2013-05-08 16:03 ` [PATCH 17/22] mm: page allocator: Move magazine access behind accessors Mel Gorman
2013-05-08 16:03 ` [PATCH 18/22] mm: page allocator: Split magazine lock in two to reduce contention Mel Gorman
2013-05-09 15:21 ` Dave Hansen
2013-05-15 19:44 ` Andi Kleen
2013-05-08 16:03 ` [PATCH 19/22] mm: page allocator: Watch for magazine and zone lock contention Mel Gorman
2013-05-08 16:03 ` Mel Gorman [this message]
2013-05-08 16:03 ` [PATCH 21/22] mm: compaction: Release free page list under a batched magazine lock Mel Gorman
2013-05-08 16:03 ` [PATCH 22/22] mm: page allocator: Drain magazines for direct compact failures Mel Gorman
2013-05-09 15:41 ` [RFC PATCH 00/22] Per-cpu page allocator replacement prototype Dave Hansen
2013-05-09 16:25 ` Christoph Lameter
2013-05-09 17:33 ` Mel Gorman
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=1368028987-8369-21-git-send-email-mgorman@suse.de \
--to=mgorman@suse.de \
--cc=cl@linux.com \
--cc=dave@sr71.net \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).