Skip to contentSkip to conversation

mm/page_alloc : rename rmqueue_bulk to rmqueue_single

PATCH In review Huang Shijie 7 participants 41 messages Jan 11, 2010 – Jan 19, 2010

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 mm/page_alloc : rename rmqueue_bulk to rmqueue_single

There is only one place calls rmqueue_bulk to allocate the single pages. So rename it to rmqueue_single, and remove an argument order.

---
 mm/page_alloc.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
mm/page_alloc.c +8 -10
index 4e9f5cc..23df1ed 100644
@@ -930,25 +930,24 @@ retry_reserve:
 }
 
 /* 
- * Obtain a specified number of elements from the buddy allocator, all under
+ * Obtain a specified number of single page from the buddy allocator, all under
  * a single hold of the lock, for efficiency.  Add them to the supplied list.
  * Returns the number of new pages which were placed at *list.
  */
-static int rmqueue_bulk(struct zone *zone, unsigned int order, 
-			unsigned long count, struct list_head *list,
-			int migratetype, int cold)
+static int rmqueue_single(struct zone *zone, unsigned long count,
+		       struct list_head *list, int migratetype, int cold)
 {
 	int i;
 	
 	spin_lock(&zone->lock);
 	for (i = 0; i < count; ++i) {
-		struct page *page = __rmqueue(zone, order, migratetype);
+		struct page *page = __rmqueue(zone, 0, migratetype);
 		if (unlikely(page == NULL))
 			break;
 
 		/*
 		 * Split buddy pages returned by expand() are received here
-		 * in physical page order. The page is added to the callers and
+		 * in order zero. The page is added to the callers and
 		 * list and the list head then moves forward. From the callers
 		 * perspective, the linked list is ordered by page number in
 		 * some conditions. This is useful for IO devices that can
@@ -962,7 +961,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
 	return i;
 }
@@ -1192,9 +1191,8 @@ again:
 		list = &pcp->lists[migratetype];
 		local_irq_save(flags);
 		if (list_empty(list)) {
-			pcp->count += rmqueue_bulk(zone, 0,
-					pcp->batch, list,
-					migratetype, cold);
+			pcp->count += rmqueue_single(zone, pcp->batch, list,
+							migratetype, cold);
 			if (unlikely(list_empty(list)))
 				goto failed;
 		}
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 2/4 mm/page_alloc : relieve the zone->lock's pressure for allocation

The __mod_zone_page_state() only require irq disabling,
it does not require the zone's spinlock. So move it out of the guard region of the spinlock to relieve the pressure for allocation.

---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 23df1ed..00aa83a 100644
@@ -961,8 +961,8 @@ static int rmqueue_single(struct zone *zone, unsigned long count,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	return i;
 }
 
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH 3/4 mm/page_alloc : modify the return type of __free_one_page

Modify the return type for __free_one_page.
It will return 1 on success, and return 0 when
the check of the compound page is failed.

---
 mm/page_alloc.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
mm/page_alloc.c +6 -4
index 00aa83a..290dfc3 100644
@@ -445,17 +445,18 @@ static inline int page_is_buddy(struct page *page, struct page *buddy,
  * triggers coalescing into a block of larger size.            
  *
  * -- wli
+ *
+ *  Returns 1 on success, else return 0;
  */
 
-static inline void __free_one_page(struct page *page,
-		struct zone *zone, unsigned int order,
-		int migratetype)
+static inline int __free_one_page(struct page *page, struct zone *zone,
+		       unsigned int order, int migratetype)
 {
 	unsigned long page_idx;
 
 	if (unlikely(PageCompound(page)))
 		if (unlikely(destroy_compound_page(page, order)))
-			return;
+			return 0;
 
 	VM_BUG_ON(migratetype == -1);
 
@@ -485,6 +486,7 @@ static inline void __free_one_page(struct page *page,
 	list_add(&page->lru,
 		&zone->free_area[order].free_list[migratetype]);
 	zone->free_area[order].nr_free++;
+	return 1;
 }
 
 /*
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH 4/4 mm/page_alloc : relieve zone->lock's pressure for memory free

Move the __mod_zone_page_state out the guard region of
the spinlock to relieve the pressure for memory free.

---
 mm/page_alloc.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)
mm/page_alloc.c +16 -10
index 290dfc3..34b9a3a 100644
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,32 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);
 		} while (--count && --batch_free && !list_empty(list));
 	}
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+	}
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
 }
 
 static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+	}
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 13 lines · On Mon, 11 Jan 2010 12:37:14 +0800 Huang Shijie <[email protected]> wrote:

Move the __mod_zone_page_state out the guard region of
the spinlock to relieve the pressure for memory free.

---
 mm/page_alloc.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)
mm/page_alloc.c +0 -0
index 290dfc3..34b9a3a 100644

mm/page_alloc.c static void free_pcppages_bulk(struct zone *zone, int count, · line 536

Quoted 8 lines
mm/page_alloc.c +1 -2
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;

We don't use zone->lock to protect pages_scanned in shrink_[in]active_list. At least, we can move zone->pages_scanned out of lock.

In addition,
sometime we don't use lock to test ZONE_ALL_UNRECLAIMABLE, sometime we do use zone->lock(ex, zoneinfo_show_print).

Now lock for ZONE_ALL_UNRECLAIMABLE is not consistent,

I think we have to use not zone->lock but zone->lru_lock since it's related to reclaim.

Few days ago, Mel and Kosaki discussed about zone->lock. Any thought?

Quoted 52 lines
mm/page_alloc.c +15 -8
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,32 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);
 		} while (--count && --batch_free && !list_empty(list));
 	}
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+	}
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
 }
 
 static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+	}
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 27 lines
Quoted 14 lines

Move the __mod_zone_page_state out the guard region of
the spinlock to relieve the pressure for memory free.

---
  mm/page_alloc.c |   26 ++++++++++++++++----------
  1 files changed, 16 insertions(+), 10 deletions(-)
mm/page_alloc.c +0 -0
index 290dfc3..34b9a3a 100644

mm/page_alloc.c static void free_pcppages_bulk(struct zone *zone, int count, · line 536

Quoted 9 lines
mm/page_alloc.c +1 -2
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
  {
  	int migratetype = 0;
  	int batch_free = 0;
+	int free_ok = 0;
 
  	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
 

We don't use zone->lock to protect pages_scanned in shrink_[in]active_list. At least, we can move zone->pages_scanned out of lock.

Quoted 10 lines

In addition,
sometime we don't use lock to test ZONE_ALL_UNRECLAIMABLE, sometime we do use zone->lock(ex, zoneinfo_show_print).

Now lock for ZONE_ALL_UNRECLAIMABLE is not consistent,

I think we have to use not zone->lock but zone->lru_lock since it's related to reclaim.

agree.
I think zone->lru_lock is more proper.

Quoted 51 lines

Few days ago, Mel and Kosaki discussed about zone->lock. Any thought?

Quoted 47 lines
mm/page_alloc.c +0 -2
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
  	while (count) {
  		struct page *page;

struct list_head *list;

mm/page_alloc.c +15 -6
@@ -558,23 +555,32 @@ static void free_pcppages_bulk(struct zone *zone, int count,
  			page = list_entry(list->prev, struct page, lru);
  			/* must delete as __free_one_page list manipulates */
  			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
  			trace_mm_page_pcpu_drain(page, 0, migratetype);
  		} while (--count&&  --batch_free&&  !list_empty(list));
  	}
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+	}
  	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
  }
 
  static void free_one_page(struct zone *zone, struct page *page, int order,
  				int migratetype)
  {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1<<  order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+	}
  	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok<<  order);
  }
 
  static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 1 line
1.6.5.2
Quoted 8 lines
Quoted 6 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email:<a href=mailto:"[email protected]"> [email protected]</a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

PATCH 4/4 mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to Huang Shijie

Move the __mod_zone_page_state out the guard region of
the spinlock to relieve the pressure for memory free.

Using the zone->lru_lock to replace the zone->lock for
zone->pages_scanned and zone's flag ZONE_ALL_UNRECLAIMABLE.

---
 mm/page_alloc.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)
mm/page_alloc.c +23 -10
index 290dfc3..dfd4be0 100644
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,39 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);
 		} while (--count && --batch_free && !list_empty(list));
 	}
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		spin_lock(&zone->lru_lock);
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		spin_unlock(&zone->lru_lock);
+
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
+	}
 }
 
 static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		spin_lock(&zone->lru_lock);
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		spin_unlock(&zone->lru_lock);
+
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
+	}
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 78 lines · On Mon, 11 Jan 2010 14:27:57 +0800 Huang Shijie <[email protected]> wrote:

Move the __mod_zone_page_state out the guard region of
the spinlock to relieve the pressure for memory free.

Using the zone->lru_lock to replace the zone->lock for
zone->pages_scanned and zone's flag ZONE_ALL_UNRECLAIMABLE.

---
 mm/page_alloc.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)
mm/page_alloc.c +23 -10
index 290dfc3..dfd4be0 100644
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,39 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);
 		} while (--count && --batch_free && !list_empty(list));
 	}
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		spin_lock(&zone->lru_lock);
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		spin_unlock(&zone->lru_lock);
+
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
+	}
 }
 
 static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		spin_lock(&zone->lru_lock);
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		spin_unlock(&zone->lru_lock);
+
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
+	}
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 1 line
1.6.5.2

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

Let's listen other mm guys's opinion.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 6 lines

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

As you know, this functions are one of hot pathes.

Yes. But the PCP suffers most of the pressure ,I think. free_one_page() handles (order != 0) most of the time which is relatively rarely executed.

Quoted 5 lines

In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

Maybe it has already caused a problem, while the problem is hard to find out. :)

Quoted 6 lines

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

Let's listen other mm guys's opinion.

Ok.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to Minchan Kim
Quoted 87 lines · On Mon, 11 Jan 2010 15:38:02 +0900 Minchan Kim <[email protected]> wrote:
Quoted 78 lines · On Mon, 11 Jan 2010 14:27:57 +0800 Huang Shijie <[email protected]> wrote:

Move the __mod_zone_page_state out the guard region of
the spinlock to relieve the pressure for memory free.

Using the zone->lru_lock to replace the zone->lock for
zone->pages_scanned and zone's flag ZONE_ALL_UNRECLAIMABLE.

---
 mm/page_alloc.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)
mm/page_alloc.c +23 -10
index 290dfc3..dfd4be0 100644
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,39 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);
 		} while (--count && --batch_free && !list_empty(list));
 	}
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		spin_lock(&zone->lru_lock);
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		spin_unlock(&zone->lru_lock);
+
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
+	}
 }
 
 static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		spin_lock(&zone->lru_lock);
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		spin_unlock(&zone->lru_lock);
+
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
+	}
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 1 line
1.6.5.2

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

Quoted 8 lines

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 11 lines
Quoted 11 lines

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

Quoted 6 lines
Quoted 4 lines

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

I don't want it either.

Quoted 5 lines

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

How about the `pages_scanned' ?
It's protected by the zone->lru_lock in shrink_{in}active_list().

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 17 lines · On Tue, 12 Jan 2010 10:02:49 +0800 Huang Shijie <[email protected]> wrote:
Quoted 11 lines
Quoted 11 lines

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

Quoted 6 lines
Quoted 4 lines

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

Quoted 9 lines

I don't want it either.

Quoted 5 lines

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

How about the `pages_scanned' ?
It's protected by the zone->lru_lock in shrink_{in}active_list().

Zero-clear by page-scanned is done by a write (atomic). Then, possible race will be this update,

	zone->pages_scanend += scanned;

And failing to reset the number. But, IMHO, failure to reset this counter is not a big problem. We'll finally reset this when we free the next page. So, I have no concerns about resetting this counter.

My only concern is race with other flags.

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 5 lines
Quoted 5 lines

How about the `pages_scanned' ?
It's protected by the zone->lru_lock in shrink_{in}active_list().

Quoted 8 lines

Zero-clear by page-scanned is done by a write (atomic). Then, possible race will be this update,

	zone->pages_scanend += scanned;

And failing to reset the number. But, IMHO, failure to reset this counter is not a big problem. We'll finally reset this when we free the next

This is a good reason to me. Thanks a lot.

Quoted 12 lines

page. So, I have no concerns about resetting this counter.

My only concern is race with other flags.

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to KAMEZAWA Hiroyuki
Quoted 10 lines · KAMEZAWA Hiroyuki
Quoted 10 lines

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

Quoted 8 lines
Quoted 3 lines

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

I'd second it. It's not a big problem to reset ZONE_ALL_UNRECLAIMABLE and pages_scanned outside of zone->lru_lock.

Clear of ZONE_ALL_UNRECLAIMABLE is already atomic; if we lose one pages_scanned=0 due to races, there are plenty of page free events ahead to reset it, before pages_scanned hit the huge zone_reclaimable_pages() * 6.

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 20 lines · KAMEZAWA Hiroyuki
Quoted 10 lines
Quoted 10 lines

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

Quoted 8 lines
Quoted 3 lines

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

Quoted 7 lines

I'd second it. It's not a big problem to reset ZONE_ALL_UNRECLAIMABLE and pages_scanned outside of zone->lru_lock.

Clear of ZONE_ALL_UNRECLAIMABLE is already atomic; if we lose one pages_scanned=0 due to races, there are plenty of page free events ahead to reset it, before pages_scanned hit the huge zone_reclaimable_pages() * 6.

Yes, this patch should be rejected.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines

I don't want to see additional spin_lock, here.

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

I'd second it. It's not a big problem to reset ZONE_ALL_UNRECLAIMABLE and pages_scanned outside of zone->lru_lock.

Quoted 10 lines
Quoted 5 lines

Clear of ZONE_ALL_UNRECLAIMABLE is already atomic; if we lose one pages_scanned=0 due to races, there are plenty of page free events ahead to reset it, before pages_scanned hit the huge zone_reclaimable_pages() * 6.

Yes, this patch should be rejected.

What about the new version?
http://marc.info/?l=linux-mm&m=126326472530210&w=2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to Wu Fengguang
Quoted 16 lines · Wu Fengguang
Quoted 15 lines · KAMEZAWA Hiroyuki
Quoted 5 lines

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

Quoted 8 lines

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

Quoted 8 lines
Quoted 3 lines

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

I'd second it. It's not a big problem to reset ZONE_ALL_UNRECLAIMABLE and pages_scanned outside of zone->lru_lock.

Clear of ZONE_ALL_UNRECLAIMABLE is already atomic; if we lose one

I'd second it? What's meaning? I can't understand your point since I am not english native.

BTW,
Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
* ZONE_ALL_UNRECLAIMALBE
* ZONE_RECLAIM_LOCKED
* ZONE_OOM_LOCKED.

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

Quoted 3 lines

Thanks,
Fengguang

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 21 lines · Minchan Kim
Quoted 20 lines · Wu Fengguang
Quoted 18 lines · KAMEZAWA Hiroyuki
Quoted 5 lines

Thanks, Huang.

Frankly speaking, I am not sure this ir right way. This patch is adding to fine-grained locking overhead

Quoted 8 lines

As you know, this functions are one of hot pathes. In addition, we didn't see the any problem, until now. It means out of synchronization in ZONE_ALL_UNRECLAIMABLE and pages_scanned are all right?

If it is, we can move them out of zone->lock, too. If it isn't, we need one more lock, then.

I don't want to see additional spin_lock, here.

About ZONE_ALL_UNRECLAIMABLE, it's not necessary to be handled in atomic way. If you have concerns with other flags, please modify this with single word, instead of a bit field.

Quoted 7 lines
Quoted 4 lines

I'd second it. It's not a big problem to reset ZONE_ALL_UNRECLAIMABLE and pages_scanned outside of zone->lru_lock.

Clear of ZONE_ALL_UNRECLAIMABLE is already atomic; if we lose one

I'd second it? What's meaning? I can't understand your point since I am not english native.

=> "I agree with Kame." :)

Quoted 8 lines

BTW,
Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
* ZONE_ALL_UNRECLAIMALBE
* ZONE_RECLAIM_LOCKED
* ZONE_OOM_LOCKED.

Quoted 4 lines

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

zone_set_flag()/zone_clear_flag() calls set_bit()/clear_bit() which is atomic. Do you mean more high level exclusion?

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 8 lines · On Tue, 12 Jan 2010 12:21:16 +0800 Wu Fengguang <[email protected]> wrote:
Quoted 8 lines

BTW,
Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
* ZONE_ALL_UNRECLAIMALBE
* ZONE_RECLAIM_LOCKED
* ZONE_OOM_LOCKED.

Quoted 8 lines
Quoted 4 lines

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

zone_set_flag()/zone_clear_flag() calls set_bit()/clear_bit() which is atomic. Do you mean more high level exclusion?

Ah, sorry, I missed that.
In my memory, this wasn't atomic ;) ...maybe recent change.

I don't want to see atomic_ops here...So, how about making this back to be zone->all_unreclaimable word ?

Clearing this is not necessary to be atomic because this is cleard at every page freeing.

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 18 lines · KAMEZAWA Hiroyuki
Quoted 8 lines · On Tue, 12 Jan 2010 12:21:16 +0800 Wu Fengguang <[email protected]> wrote:
Quoted 8 lines

BTW,
Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
* ZONE_ALL_UNRECLAIMALBE
* ZONE_RECLAIM_LOCKED
* ZONE_OOM_LOCKED.

Quoted 8 lines
Quoted 4 lines

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

zone_set_flag()/zone_clear_flag() calls set_bit()/clear_bit() which is atomic. Do you mean more high level exclusion?

Quoted 8 lines

Ah, sorry, I missed that.
In my memory, this wasn't atomic ;) ...maybe recent change.

I don't want to see atomic_ops here...So, how about making this back to be zone->all_unreclaimable word ?

Clearing this is not necessary to be atomic because this is cleard at every page freeing.

Yes the cost is a bit high. This was introduced by David Rientjes in commit e815af95f, let's hear opinions from him :)

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#20 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

[corrected CC to Christoph and Andrea]

Quoted 18 lines · KAMEZAWA Hiroyuki
Quoted 8 lines · On Tue, 12 Jan 2010 12:21:16 +0800 Wu Fengguang <[email protected]> wrote:
Quoted 8 lines

BTW,
Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
* ZONE_ALL_UNRECLAIMALBE
* ZONE_RECLAIM_LOCKED
* ZONE_OOM_LOCKED.

Quoted 8 lines
Quoted 4 lines

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

zone_set_flag()/zone_clear_flag() calls set_bit()/clear_bit() which is atomic. Do you mean more high level exclusion?

Quoted 8 lines

Ah, sorry, I missed that.
In my memory, this wasn't atomic ;) ...maybe recent change.

I don't want to see atomic_ops here...So, how about making this back to be zone->all_unreclaimable word ?

Clearing this is not necessary to be atomic because this is cleard at every page freeing.

Yes the cost is a bit high. This was introduced by David Rientjes in commit e815af95f, let's hear opinions from him :)

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to KAMEZAWA Hiroyuki
Quoted 18 lines
Quoted 8 lines · On Tue, 12 Jan 2010 12:21:16 +0800 Wu Fengguang <[email protected]> wrote:
Quoted 8 lines

BTW,
Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
* ZONE_ALL_UNRECLAIMALBE
* ZONE_RECLAIM_LOCKED
* ZONE_OOM_LOCKED.

Quoted 8 lines
Quoted 4 lines

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

zone_set_flag()/zone_clear_flag() calls set_bit()/clear_bit() which is atomic. Do you mean more high level exclusion?

Quoted 8 lines

Ah, sorry, I missed that.
In my memory, this wasn't atomic ;) ...maybe recent change.

I don't want to see atomic_ops here...So, how about making this back to be zone->all_unreclaimable word ?

Clearing this is not necessary to be atomic because this is cleard at every page freeing.

I agree. How about this?

From 751f197ad256c7245151681d7aece591b1dab343 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Tue, 12 Jan 2010 13:53:47 +0900
Subject: [PATCH] mm: Restore zone->all_unreclaimable to independence word

commit e815af95 (change all_unreclaimable zone member to flags) chage all_unreclaimable member to bit flag. but It have undesireble side effect.
free_one_page() is one of most hot path in linux kernel and increasing atomic ops in it can reduce kernel performance a bit.

Thus, this patch revert such commit partially. at least all_unreclaimable shouldn't share memory word with other zone flags.

---
 include/linux/mmzone.h |    7 +------
 mm/page_alloc.c        |    6 +++---
 mm/vmscan.c            |   20 ++++++++------------
 mm/vmstat.c            |    2 +-
 4 files changed, 13 insertions(+), 22 deletions(-)
include/linux/mmzone.h +1 -6
index 30fe668..4f0c6f1 100644
@@ -341,6 +341,7 @@ struct zone {
 
 	unsigned long		pages_scanned;	   /* since last reclaim */
 	unsigned long		flags;		   /* zone flags, see below */
+	int                     all_unreclaimable; /* All pages pinned */
 
 	/* Zone statistics */
 	atomic_long_t		vm_stat[NR_VM_ZONE_STAT_ITEMS];
@@ -425,7 +426,6 @@ struct zone {
 } ____cacheline_internodealigned_in_smp;
 
 typedef enum {
-	ZONE_ALL_UNRECLAIMABLE,		/* all pages pinned */
 	ZONE_RECLAIM_LOCKED,		/* prevents concurrent reclaim */
 	ZONE_OOM_LOCKED,		/* zone is in OOM killer zonelist */
 } zone_flags_t;
@@ -445,11 +445,6 @@ static inline void zone_clear_flag(struct zone *zone, zone_flags_t flag)
 	clear_bit(flag, &zone->flags);
 }
 
-static inline int zone_is_all_unreclaimable(const struct zone *zone)
-{
-	return test_bit(ZONE_ALL_UNRECLAIMABLE, &zone->flags);
-}
-
 static inline int zone_is_reclaim_locked(const struct zone *zone)
 {
 	return test_bit(ZONE_RECLAIM_LOCKED, &zone->flags);
mm/page_alloc.c +3 -3
index 4e9f5cc..19a5b0e 100644
@@ -530,7 +530,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 	int batch_free = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+	zone->all_unreclaimable = 0;
 	zone->pages_scanned = 0;
 
 	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
@@ -567,7 +567,7 @@ static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+	zone->all_unreclaimable = 0;
 	zone->pages_scanned = 0;
 
 	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
@@ -2270,7 +2270,7 @@ void show_free_areas(void)
 			K(zone_page_state(zone, NR_BOUNCE)),
 			K(zone_page_state(zone, NR_WRITEBACK_TEMP)),
 			zone->pages_scanned,
-			(zone_is_all_unreclaimable(zone) ? "yes" : "no")
+			(zone->all_unreclaimable ? "yes" : "no")
 			);
 		printk("lowmem_reserve[]:");
 		for (i = 0; i < MAX_NR_ZONES; i++)
mm/vmscan.c +8 -12
index 885207a..8057d36 100644
@@ -1694,8 +1694,7 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
 				continue;
 			note_zone_scanning_priority(zone, priority);
 
-			if (zone_is_all_unreclaimable(zone) &&
-						priority != DEF_PRIORITY)
+			if (zone->all_unreclaimable && priority != DEF_PRIORITY)
 				continue;	/* Let kswapd poll it */
 			sc->all_unreclaimable = 0;
 		} else {
@@ -2009,8 +2008,7 @@ loop_again:
 			if (!populated_zone(zone))
 				continue;
 
-			if (zone_is_all_unreclaimable(zone) &&
-			    priority != DEF_PRIORITY)
+			if (zone->all_unreclaimable && priority != DEF_PRIORITY)
 				continue;
 
 			/*
@@ -2053,8 +2051,7 @@ loop_again:
 			if (!populated_zone(zone))
 				continue;
 
-			if (zone_is_all_unreclaimable(zone) &&
-					priority != DEF_PRIORITY)
+			if (zone->all_unreclaimable && priority != DEF_PRIORITY)
 				continue;
 
 			if (!zone_watermark_ok(zone, order,
@@ -2084,12 +2081,11 @@ loop_again:
 						lru_pages);
 			sc.nr_reclaimed += reclaim_state->reclaimed_slab;
 			total_scanned += sc.nr_scanned;
-			if (zone_is_all_unreclaimable(zone))
+			if (zone->all_unreclaimable)
 				continue;
-			if (nr_slab == 0 && zone->pages_scanned >=
-					(zone_reclaimable_pages(zone) * 6))
-					zone_set_flag(zone,
-						      ZONE_ALL_UNRECLAIMABLE);
+			if (nr_slab == 0 &&
+			    zone->pages_scanned >= (zone_reclaimable_pages(zone) * 6))
+				zone->all_unreclaimable = 1;
 			/*
 			 * If we've done a decent amount of scanning and
 			 * the reclaim ratio is low, start doing writepage
@@ -2612,7 +2608,7 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
 	    zone_page_state(zone, NR_SLAB_RECLAIMABLE) <= zone->min_slab_pages)
 		return ZONE_RECLAIM_FULL;
 
-	if (zone_is_all_unreclaimable(zone))
+	if (zone->all_unreclaimable)
 		return ZONE_RECLAIM_FULL;
 
 	/*
mm/vmstat.c +1 -1
index 6051fba..8175c64 100644
@@ -761,7 +761,7 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
 		   "\n  prev_priority:     %i"
 		   "\n  start_pfn:         %lu"
 		   "\n  inactive_ratio:    %u",
-			   zone_is_all_unreclaimable(zone),
+		   zone->all_unreclaimable,
 		   zone->prev_priority,
 		   zone->zone_start_pfn,
 		   zone->inactive_ratio);
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#22 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 11 lines · KOSAKI Motohiro

From 751f197ad256c7245151681d7aece591b1dab343 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Tue, 12 Jan 2010 13:53:47 +0900
Subject: [PATCH] mm: Restore zone->all_unreclaimable to independence word

commit e815af95 (change all_unreclaimable zone member to flags) chage all_unreclaimable member to bit flag. but It have undesireble side effect.
free_one_page() is one of most hot path in linux kernel and increasing atomic ops in it can reduce kernel performance a bit.

Could you please elaborate on "a bit" in the changelog with some data? If it's so egregious, it should be easily be quantifiable.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 14 lines · KOSAKI Motohiro
Quoted 6 lines

From 751f197ad256c7245151681d7aece591b1dab343 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Tue, 12 Jan 2010 13:53:47 +0900
Subject: [PATCH] mm: Restore zone->all_unreclaimable to independence word

Quoted 6 lines

commit e815af95 (change all_unreclaimable zone member to flags) chage all_unreclaimable member to bit flag. but It have undesireble side effect.
free_one_page() is one of most hot path in linux kernel and increasing atomic ops in it can reduce kernel performance a bit.

Quoted 2 lines

Could you please elaborate on "a bit" in the changelog with some data? If it's so egregious, it should be easily be quantifiable.

Unfortunately I can't. atomic ops is mainly the issue of large machine. but I can't access such machine now. but I'm sure we shouldn't take unnecessary atomic ops.

That's fundamental space vs performance tradeoff thing. if we talked about struct page or similar lots created struct, space efficient is very important. but struct zone isn't such one.

Or, do you have strong argue to use bitops without space efficiency?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#24 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 7 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines

commit e815af95 (change all_unreclaimable zone member to flags) chage all_unreclaimable member to bit flag. but It have undesireble side effect.
free_one_page() is one of most hot path in linux kernel and increasing atomic ops in it can reduce kernel performance a bit.

Quoted 7 lines
Quoted 2 lines

Could you please elaborate on "a bit" in the changelog with some data? If it's so egregious, it should be easily be quantifiable.

Unfortunately I can't. atomic ops is mainly the issue of large machine. but I can't access such machine now. but I'm sure we shouldn't take unnecessary atomic ops.

e815af95 was intended to consolidate all bit flags into a single word merely for space efficiency and cleanliness. At that time, we only had one member of struct zone that could be converted, and that was all_unreclaimable. That said, it was part of a larger patchset that later added another zone flag meant to serialize the oom killer by zonelist. So no consideration was given at the time concerning any penalty incurred by moving all_unreclaimable to an atomic op.

Quoted 6 lines

That's fundamental space vs performance tradeoff thing. if we talked about struct page or similar lots created struct, space efficient is very important. but struct zone isn't such one.

Or, do you have strong argue to use bitops without space efficiency?

I'd suggest using a non-atomic variation within zone->flags that may still be reordered so that it does not incur any performance penalty. In other words, instead of readding zone->all_unreclaimable, we should add __zone_set_flag(), __zone_test_and_set_flag(), and __zone_clear_flag() variants to wrap non-atomic bitops.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Quoted 17 lines · KOSAKI Motohiro
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

commit e815af95 (change all_unreclaimable zone member to flags) chage all_unreclaimable member to bit flag. but It have undesireble side effect.
free_one_page() is one of most hot path in linux kernel and increasing atomic ops in it can reduce kernel performance a bit.

Quoted 7 lines
Quoted 2 lines

Could you please elaborate on "a bit" in the changelog with some data? If it's so egregious, it should be easily be quantifiable.

Unfortunately I can't. atomic ops is mainly the issue of large machine. but I can't access such machine now. but I'm sure we shouldn't take unnecessary atomic ops.

Quoted 7 lines

e815af95 was intended to consolidate all bit flags into a single word merely for space efficiency and cleanliness. At that time, we only had one member of struct zone that could be converted, and that was all_unreclaimable. That said, it was part of a larger patchset that later added another zone flag meant to serialize the oom killer by zonelist. So no consideration was given at the time concerning any penalty incurred by moving all_unreclaimable to an atomic op.

I agree ZONE_OOM_LOCKED have lots worth.

Quoted 11 lines
Quoted 5 lines

That's fundamental space vs performance tradeoff thing. if we talked about struct page or similar lots created struct, space efficient is very important. but struct zone isn't such one.

Or, do you have strong argue to use bitops without space efficiency?

I'd suggest using a non-atomic variation within zone->flags that may still be reordered so that it does not incur any performance penalty. In other words, instead of readding zone->all_unreclaimable, we should add __zone_set_flag(), __zone_test_and_set_flag(), and __zone_clear_flag() variants to wrap non-atomic bitops.

No. non-atomic ops assume the flags are protected by same lock. but all_unreclaimable and ZONE_OOM_LOCKED don't have such lock. iow, your opinion might cause ZONE_OOM_LOCKED lost.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#26 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to Wu Fengguang
Quoted 7 lines · Wu Fengguang
Quoted 7 lines

Hmm. It's not atomic as Kame pointed out.

Now, zone->flags have several bit.
 * ZONE_ALL_UNRECLAIMALBE
 * ZONE_RECLAIM_LOCKED
 * ZONE_OOM_LOCKED.

Quoted 7 lines
Quoted 4 lines

I think this flags are likely to race when the memory pressure is high. If we don't prevent race, concurrent reclaim and killing could be happened. So I think reset zone->flags outside of zone->lock would make our efforts which prevent current reclaim and killing invalidate.

zone_set_flag()/zone_clear_flag() calls set_bit()/clear_bit() which is atomic. Do you mean more high level exclusion?

No. I was wrong. I though it's not atomic operation. I confused it with __set_bit. :)
Sorry for the noise.
Thanks, Wu. :)

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#27 lore raw

PATCH 4/4 mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to Huang Shijie

Move the {__mod_zone_page_state, pages_scanned, clear zone's flags}
out the guard region of the spinlock to relieve the pressure for memory free.

---
 mm/page_alloc.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)
mm/page_alloc.c +17 -10
index 290dfc3..1c7e32e 100644
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,33 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);
 		} while (--count && --batch_free && !list_empty(list));
 	}
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
+	}
 }
 
 static void free_one_page(struct zone *zone, struct page *page, int order,
 				int migratetype)
 {
-	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
+	}
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
Signature · 7 lines
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#28 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

Hi Shijie,

mm/page_alloc.c static void free_pcppages_bulk(struct zone *zone, int count, · line 584

Quoted 13 lines
mm/page_alloc.c +9 -2
+	int free_ok;
 
-	__mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
-	__free_one_page(page, zone, order, migratetype);
+	spin_lock(&zone->lock);
+	free_ok = __free_one_page(page, zone, order, migratetype);
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok << order);
+	}

If we do

        __mod_zone_page_state(zone, -NR_FREE_PAGES, count);

in __free_one_page() on error, we can remove the likely(free_ok) test.

This sounds a bit hacky though.

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#29 lore raw

Re: [PATCH 4/4] mm/page_alloc : relieve zone->lock's pressure for memory free

In reply to Huang Shijie
Quoted 33 lines

Move the {__mod_zone_page_state, pages_scanned, clear zone's flags}
out the guard region of the spinlock to relieve the pressure for memory free.

---
 mm/page_alloc.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)
mm/page_alloc.c +2 -5
index 290dfc3..1c7e32e 100644
@@ -530,12 +530,9 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
 	int migratetype = 0;
 	int batch_free = 0;
+	int free_ok = 0;
 
 	spin_lock(&zone->lock);
-	zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
-	zone->pages_scanned = 0;
-
-	__mod_zone_page_state(zone, NR_FREE_PAGES, count);
 	while (count) {
 		struct page *page;
 		struct list_head *list;
@@ -558,23 +555,33 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 			page = list_entry(list->prev, struct page, lru);
 			/* must delete as __free_one_page list manipulates */
 			list_del(&page->lru);
-			__free_one_page(page, zone, 0, migratetype);
+			free_ok += __free_one_page(page, zone, 0, migratetype);
 			trace_mm_page_pcpu_drain(page, 0, migratetype);

mm/page_alloc.c static void free_pcppages_bulk(struct zone *zone, int count, · line 569

Quoted 10 lines
mm/page_alloc.c +6 -0
 		} while (--count && --batch_free && !list_empty(list));
 	}
 	spin_unlock(&zone->lock);
+
+	if (likely(free_ok)) {
+		zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
+		zone->pages_scanned = 0;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, free_ok);
+	}
 }

No. To introduce new branch have big performance degression risk. I don't think this patch improve performance.

Why can't we remove this "if (free_ok)" statement?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 3/4
#30 lore raw

Re: [PATCH 3/4] mm/page_alloc : modify the return type of __free_one_page

In reply to Huang Shijie
Quoted 5 lines · On Mon, 11 Jan 2010 12:37:13 +0800 Huang Shijie <[email protected]> wrote:

Modify the return type for __free_one_page.
It will return 1 on success, and return 0 when
the check of the compound page is failed.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#31 lore raw

Re: [PATCH 3/4] mm/page_alloc : modify the return type of __free_one_page

In reply to Huang Shijie
Quoted 3 lines

Modify the return type for __free_one_page.
It will return 1 on success, and return 0 when
the check of the compound page is failed.

This patch should be merged [4/4]. but I really dislike 4/4...

Quoted 43 lines
---
 mm/page_alloc.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
mm/page_alloc.c +6 -4
index 00aa83a..290dfc3 100644
@@ -445,17 +445,18 @@ static inline int page_is_buddy(struct page *page, struct page *buddy,
  * triggers coalescing into a block of larger size.            
  *
  * -- wli
+ *
+ *  Returns 1 on success, else return 0;
  */
 
-static inline void __free_one_page(struct page *page,
-		struct zone *zone, unsigned int order,
-		int migratetype)
+static inline int __free_one_page(struct page *page, struct zone *zone,
+		       unsigned int order, int migratetype)
 {
 	unsigned long page_idx;
 
 	if (unlikely(PageCompound(page)))
 		if (unlikely(destroy_compound_page(page, order)))
-			return;
+			return 0;
 
 	VM_BUG_ON(migratetype == -1);
 
@@ -485,6 +486,7 @@ static inline void __free_one_page(struct page *page,
 	list_add(&page->lru,
 		&zone->free_area[order].free_list[migratetype]);
 	zone->free_area[order].nr_free++;
+	return 1;
 }
 
 /*
Signature · 1 line
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#32 lore raw

Re: [PATCH 3/4] mm/page_alloc : modify the return type of __free_one_page

In reply to Huang Shijie
Quoted 4 lines · Huang Shijie

Modify the return type for __free_one_page.
It will return 1 on success, and return 0 when
the check of the compound page is failed.

Why?

I assume it's something to do with patch 4, but it's unclear at this point why it's necessary. A brief explanation is needed in the changelog.

Quoted 43 lines
---
 mm/page_alloc.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
mm/page_alloc.c +6 -4
index 00aa83a..290dfc3 100644
@@ -445,17 +445,18 @@ static inline int page_is_buddy(struct page *page, struct page *buddy,
  * triggers coalescing into a block of larger size.            
  *
  * -- wli
+ *
+ *  Returns 1 on success, else return 0;
  */
 
-static inline void __free_one_page(struct page *page,
-		struct zone *zone, unsigned int order,
-		int migratetype)
+static inline int __free_one_page(struct page *page, struct zone *zone,
+		       unsigned int order, int migratetype)
 {
 	unsigned long page_idx;
 
 	if (unlikely(PageCompound(page)))
 		if (unlikely(destroy_compound_page(page, order)))
-			return;
+			return 0;
 
 	VM_BUG_ON(migratetype == -1);
 
@@ -485,6 +486,7 @@ static inline void __free_one_page(struct page *page,
 	list_add(&page->lru,
 		&zone->free_area[order].free_list[migratetype]);
 	zone->free_area[order].nr_free++;
+	return 1;
 }
 
 /*
Signature · 1 line
1.6.5.2
Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#33 lore raw

Re: [PATCH 3/4] mm/page_alloc : modify the return type of __free_one_page

Quoted 8 lines · Huang Shijie
Quoted 6 lines

Modify the return type for __free_one_page.
It will return 1 on success, and return 0 when
the check of the compound page is failed.

Quoted 7 lines

Why?

I assume it's something to do with patch 4, but it's unclear at this point why it's necessary. A brief explanation is needed in the changelog.

Just ignore this patch. Changing the return value of __free_one_page() is not needed ,even when the check of compand page is failed.

Just as Wu Fengguang pointed out, a hacker method maybe better.

Quoted 39 lines
Quoted 39 lines
---
  mm/page_alloc.c |   10 ++++++----
  1 files changed, 6 insertions(+), 4 deletions(-)
mm/page_alloc.c +6 -4
index 00aa83a..290dfc3 100644
@@ -445,17 +445,18 @@ static inline int page_is_buddy(struct page *page, struct page *buddy,
   * triggers coalescing into a block of larger size.
   *
   * -- wli
+ *
+ *  Returns 1 on success, else return 0;
   */
 
-static inline void __free_one_page(struct page *page,
-		struct zone *zone, unsigned int order,
-		int migratetype)
+static inline int __free_one_page(struct page *page, struct zone *zone,
+		       unsigned int order, int migratetype)
  {
  	unsigned long page_idx;
 
  	if (unlikely(PageCompound(page)))
  		if (unlikely(destroy_compound_page(page, order)))
-			return;
+			return 0;
 
  	VM_BUG_ON(migratetype == -1);
 
@@ -485,6 +486,7 @@ static inline void __free_one_page(struct page *page,
  	list_add(&page->lru,
  		&zone->free_area[order].free_list[migratetype]);
  	zone->free_area[order].nr_free++;
+	return 1;
  }
 
Quoted 6 lines
Quoted 5 lines
mm/page_alloc.c +0 -0
  /*
Signature · 1 line
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 2/4
#34 lore raw

Re: [PATCH 2/4] mm/page_alloc : relieve the zone->lock's pressure for allocation

In reply to Huang Shijie
Quoted 27 lines · On Mon, 11 Jan 2010 12:37:12 +0800 Huang Shijie <[email protected]> wrote:

The __mod_zone_page_state() only require irq disabling,
it does not require the zone's spinlock. So move it out of the guard region of the spinlock to relieve the pressure for allocation.

---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 23df1ed..00aa83a 100644
@@ -961,8 +961,8 @@ static int rmqueue_single(struct zone *zone, unsigned long count,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	return i;
 }
 
Signature · 1 line
1.6.5.2

How about moving this patch into [4/4]?
Otherwise, Looks good to me.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#35 lore raw

Re: [PATCH 2/4] mm/page_alloc : relieve the zone->lock's pressure for allocation

Quoted 25 lines
Quoted 25 lines

The __mod_zone_page_state() only require irq disabling,
it does not require the zone's spinlock. So move it out of the guard region of the spinlock to relieve the pressure for allocation.

---
  mm/page_alloc.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 23df1ed..00aa83a 100644
@@ -961,8 +961,8 @@ static int rmqueue_single(struct zone *zone, unsigned long count,
  		set_page_private(page, migratetype);
  		list =&page->lru;
  	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
  	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
  	return i;
  }
 
Quoted 8 lines
Quoted 4 lines
Signature · 1 line
1.6.5.2

How about moving this patch into [4/4]?
Otherwise, Looks good to me.

I just want to make the patches more clear : two for memory allocation, two for memory free.

Quoted 3 lines

thanks a lot.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 2/4
#36 lore raw

Re: [PATCH 2/4] mm/page_alloc : relieve the zone->lock's pressure for allocation

In reply to Huang Shijie
Quoted 6 lines

The __mod_zone_page_state() only require irq disabling,
it does not require the zone's spinlock. So move it out of the guard region of the spinlock to relieve the pressure for allocation.

Quoted 21 lines
---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 23df1ed..00aa83a 100644
@@ -961,8 +961,8 @@ static int rmqueue_single(struct zone *zone, unsigned long count,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	return i;
 }
 
Signature · 1 line
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 2/4
#37 lore raw

Re: [PATCH 2/4] mm/page_alloc : relieve the zone->lock's pressure for allocation

In reply to Huang Shijie
Quoted 6 lines · Huang Shijie

The __mod_zone_page_state() only require irq disabling,
it does not require the zone's spinlock. So move it out of the guard region of the spinlock to relieve the pressure for allocation.

Looks fine. Even if patch 1 is dropped and rmqueue_bulk remains, it still makes sense.

Quoted 21 lines
---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 23df1ed..00aa83a 100644
@@ -961,8 +961,8 @@ static int rmqueue_single(struct zone *zone, unsigned long count,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	return i;
 }
 
Signature · 1 line
1.6.5.2
Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/4
#38 lore raw
In reply to Huang Shijie
Quoted 5 lines · On Mon, 11 Jan 2010 12:37:11 +0800 Huang Shijie <[email protected]> wrote:

There is only one place calls rmqueue_bulk to allocate the single pages. So rename it to rmqueue_single, and remove an argument order.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#39 lore raw
In reply to Huang Shijie
Quoted 5 lines

There is only one place calls rmqueue_bulk to allocate the single pages. So rename it to rmqueue_single, and remove an argument order.

Hmm. _bulk' doesn't mean high order page, it mean allocate multiple pages at once. nobody imazine _single' mean "allocate multiple pages".

Quoted 63 lines
---
 mm/page_alloc.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
mm/page_alloc.c +8 -10
index 4e9f5cc..23df1ed 100644
@@ -930,25 +930,24 @@ retry_reserve:
 }
 
 /* 
- * Obtain a specified number of elements from the buddy allocator, all under
+ * Obtain a specified number of single page from the buddy allocator, all under
  * a single hold of the lock, for efficiency.  Add them to the supplied list.
  * Returns the number of new pages which were placed at *list.
  */
-static int rmqueue_bulk(struct zone *zone, unsigned int order, 
-			unsigned long count, struct list_head *list,
-			int migratetype, int cold)
+static int rmqueue_single(struct zone *zone, unsigned long count,
+		       struct list_head *list, int migratetype, int cold)
 {
 	int i;
 
 	spin_lock(&zone->lock);
 	for (i = 0; i < count; ++i) {
-		struct page *page = __rmqueue(zone, order, migratetype);
+		struct page *page = __rmqueue(zone, 0, migratetype);
 		if (unlikely(page == NULL))
 			break;
 
 		/*
 		 * Split buddy pages returned by expand() are received here
-		 * in physical page order. The page is added to the callers and
+		 * in order zero. The page is added to the callers and
 		 * list and the list head then moves forward. From the callers
 		 * perspective, the linked list is ordered by page number in
 		 * some conditions. This is useful for IO devices that can
@@ -962,7 +961,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
 	return i;
 }
@@ -1192,9 +1191,8 @@ again:
 		list = &pcp->lists[migratetype];
 		local_irq_save(flags);
 		if (list_empty(list)) {
-			pcp->count += rmqueue_bulk(zone, 0,
-					pcp->batch, list,
-					migratetype, cold);
+			pcp->count += rmqueue_single(zone, pcp->batch, list,
+							migratetype, cold);
 			if (unlikely(list_empty(list)))
 				goto failed;
 		}
Signature · 1 line
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#40 lore raw
In reply to Huang Shijie
Quoted 4 lines · Huang Shijie

There is only one place calls rmqueue_bulk to allocate the single pages. So rename it to rmqueue_single, and remove an argument order.

Why do this? The name rmqueue_bulk means "remove a number of pages in bulk with the lock held" i.e. count is the important parameter to this function, not order. rmqueue_batch might make more sense as the count is pcp->batch. If this patch is to be anything, it would just remove the "order" parameter as being unnecessary but leave the naming alone. I doubt the performance difference would be measurable though.

Quoted 64 lines
---
 mm/page_alloc.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
mm/page_alloc.c +8 -10
index 4e9f5cc..23df1ed 100644
@@ -930,25 +930,24 @@ retry_reserve:
 }
 
 /* 
- * Obtain a specified number of elements from the buddy allocator, all under
+ * Obtain a specified number of single page from the buddy allocator, all under
  * a single hold of the lock, for efficiency.  Add them to the supplied list.
  * Returns the number of new pages which were placed at *list.
  */
-static int rmqueue_bulk(struct zone *zone, unsigned int order, 
-			unsigned long count, struct list_head *list,
-			int migratetype, int cold)
+static int rmqueue_single(struct zone *zone, unsigned long count,
+		       struct list_head *list, int migratetype, int cold)
 {
 	int i;
 
 	spin_lock(&zone->lock);
 	for (i = 0; i < count; ++i) {
-		struct page *page = __rmqueue(zone, order, migratetype);
+		struct page *page = __rmqueue(zone, 0, migratetype);
 		if (unlikely(page == NULL))
 			break;
 
 		/*
 		 * Split buddy pages returned by expand() are received here
-		 * in physical page order. The page is added to the callers and
+		 * in order zero. The page is added to the callers and
 		 * list and the list head then moves forward. From the callers
 		 * perspective, the linked list is ordered by page number in
 		 * some conditions. This is useful for IO devices that can
@@ -962,7 +961,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
 		set_page_private(page, migratetype);
 		list = &page->lru;
 	}
-	__mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
+	__mod_zone_page_state(zone, NR_FREE_PAGES, -i);
 	spin_unlock(&zone->lock);
 	return i;
 }
@@ -1192,9 +1191,8 @@ again:
 		list = &pcp->lists[migratetype];
 		local_irq_save(flags);
 		if (list_empty(list)) {
-			pcp->count += rmqueue_bulk(zone, 0,
-					pcp->batch, list,
-					migratetype, cold);
+			pcp->count += rmqueue_single(zone, pcp->batch, list,
+							migratetype, cold);
 			if (unlikely(list_empty(list)))
 				goto failed;
 		}
Signature · 1 line
1.6.5.2
Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>