linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out
       [not found] ` <01f201d1f2dc$bd43f750$37cbe5f0$@alibaba-inc.com>
@ 2016-08-10  8:01   ` Hillf Danton
  2016-08-10 14:45     ` Huang, Ying
  0 siblings, 1 reply; 5+ messages in thread
From: Hillf Danton @ 2016-08-10  8:01 UTC (permalink / raw)
  To: 'Huang Ying'; +Cc: linux-mm

> 
> @@ -187,6 +221,14 @@ int add_to_swap(struct page *page, struct list_head *list)
>  	VM_BUG_ON_PAGE(!PageLocked(page), page);
>  	VM_BUG_ON_PAGE(!PageUptodate(page), page);
> 
> +	if (unlikely(PageTransHuge(page))) {
> +		err = add_to_swap_trans_huge(page, list);
> +		if (err < 0)
> +			return 0;
> +		else if (err > 0)
> +			return err;
> +		/* fallback to split firstly if return 0 */

switch (err) and add vm event count according to the meaning of err? 
> +	}

thanks
Hillf

--
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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out
  2016-08-10  8:01   ` [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out Hillf Danton
@ 2016-08-10 14:45     ` Huang, Ying
  2016-08-10 16:28       ` Dave Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Huang, Ying @ 2016-08-10 14:45 UTC (permalink / raw)
  To: Hillf Danton; +Cc: 'Huang Ying', linux-mm

Hi, Hill,

Thanks for comments!

Hillf Danton <hillf.zj@alibaba-inc.com> writes:

>> 
>> @@ -187,6 +221,14 @@ int add_to_swap(struct page *page, struct list_head *list)
>>  	VM_BUG_ON_PAGE(!PageLocked(page), page);
>>  	VM_BUG_ON_PAGE(!PageUptodate(page), page);
>> 
>> +	if (unlikely(PageTransHuge(page))) {
>> +		err = add_to_swap_trans_huge(page, list);
>> +		if (err < 0)
>> +			return 0;
>> +		else if (err > 0)
>> +			return err;
>> +		/* fallback to split firstly if return 0 */
>
> switch (err) and add vm event count according to the meaning of err?

Yes.  switch(err) looks better, I will change it.

For vm event, I found for now there are only two vm event for swap:
PSWPIN and PSWPOUT.  There are counted when page and read from or write
to the block device.  So I think we have no existing vm event to count
here.

Best Regards,
Huang, Ying

--
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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out
  2016-08-10 14:45     ` Huang, Ying
@ 2016-08-10 16:28       ` Dave Hansen
  2016-08-10 16:49         ` Huang, Ying
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2016-08-10 16:28 UTC (permalink / raw)
  To: Huang, Ying, Hillf Danton; +Cc: linux-mm

On 08/10/2016 07:45 AM, Huang, Ying wrote:
> For vm event, I found for now there are only two vm event for swap:
> PSWPIN and PSWPOUT.  There are counted when page and read from or write
> to the block device.  So I think we have no existing vm event to count
> here.

I think the point still stands that we should ensure that we have proper
instrumentation to see when huge swap is being used and if/how pages are
being split during the process.

--
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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out
  2016-08-10 16:28       ` Dave Hansen
@ 2016-08-10 16:49         ` Huang, Ying
  0 siblings, 0 replies; 5+ messages in thread
From: Huang, Ying @ 2016-08-10 16:49 UTC (permalink / raw)
  To: Dave Hansen; +Cc: Huang, Ying, Hillf Danton, linux-mm

Dave Hansen <dave.hansen@intel.com> writes:

> On 08/10/2016 07:45 AM, Huang, Ying wrote:
>> For vm event, I found for now there are only two vm event for swap:
>> PSWPIN and PSWPOUT.  There are counted when page and read from or write
>> to the block device.  So I think we have no existing vm event to count
>> here.
>
> I think the point still stands that we should ensure that we have proper
> instrumentation to see when huge swap is being used and if/how pages are
> being split during the process.

Sounds reasonable to me.  I think we can count the event that a huge
swap entry is allocated and put into swap cache successfully, say
THP_SWPCACHE.  I am not good at naming, so feel free to suggest a better
name.

And this patchset is just the first step of THP swap support.  In the
near future, the THP splitting during swapping out could be further
delayed after writing the THP to the block device.  At that time, we
will have a THP_SWPOUT vm event for THP swapping out.  Then the
THP_SWPCACHE event may appear unnecessary?  If so, we add the event now
and remove it at that time?

Best Regards,
Huang, Ying

--
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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out
  2016-08-09 16:37 [RFC 00/11] THP swap: Delay splitting THP during swapping out Huang, Ying
@ 2016-08-09 16:37 ` Huang, Ying
  0 siblings, 0 replies; 5+ messages in thread
From: Huang, Ying @ 2016-08-09 16:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: tim.c.chen, dave.hansen, andi.kleen, aaron.lu,
	Kirill A . Shutemov, Andrea Arcangeli, linux-mm, linux-kernel,
	Huang Ying, Hugh Dickins, Shaohua Li, Minchan Kim, Rik van Riel

From: Huang Ying <ying.huang@intel.com>

In this patch, the splitting huge page is delayed from almost the first
step of swapping out to after allocating the swap space for THP and
adding the THP into swap cache.  This will reduce lock
acquiring/releasing for locks used for swap space and swap cache
management.

This is the also first step for THP (Transparent Huge Page) swap
support.  The plan is to delaying splitting THP step by step and avoid
splitting THP finally.

The advantages of THP swap support are:

- Batch swap operations for THP to reduce lock acquiring/releasing,
  including allocating/freeing swap space, adding/deleting to/from swap
  cache, and writing/reading swap space, etc.

- THP swap space read/write will be 2M sequence IO.  It is particularly
  helpful for swap read, which usually are 4k random IO.

- It will help memory fragmentation, especially when THP is heavily used
  by the applications.  2M continuous pages will be free up after THP
  swapping out.

With the patchset, the swap out bandwidth improved 12.1% in
vm-scalability swap-w-seq test case with 16 processes on a Xeon E5 v3
system.  To test sequence swap out, the test case uses 16 processes
sequentially allocate and write to anonymous pages until RAM and part of
the swap device is used up.

The detailed compare result is as follow,

base             base+patchset
---------------- --------------------------
         %stddev     %change         %stddev
             \          |                \
   1118821 A+-  0%     +12.1%    1254241 A+-  1%  vmstat.swap.so
   2460636 A+-  1%     +10.6%    2720983 A+-  1%  vm-scalability.throughput
    308.79 A+-  1%      -7.9%     284.53 A+-  1%  vm-scalability.time.elapsed_time
      1639 A+-  4%    +232.3%       5446 A+-  1%  meminfo.SwapCached
      0.70 A+-  3%      +8.7%       0.77 A+-  5%  perf-stat.ipc
      9.82 A+-  8%     -31.6%       6.72 A+-  2%  perf-profile.cycles-pp._raw_spin_lock_irq.__add_to_swap_cache.add_to_swap_cache.add_to_swap.shrink_page_list

Cc: Hugh Dickins <hughd@google.com>
Cc: Shaohua Li <shli@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
---
 mm/swap_state.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index a41fd10..5316fbc 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -17,6 +17,7 @@
 #include <linux/blkdev.h>
 #include <linux/pagevec.h>
 #include <linux/migrate.h>
+#include <linux/huge_mm.h>
 
 #include <asm/pgtable.h>
 
@@ -172,12 +173,45 @@ void __delete_from_swap_cache(struct page *page)
 	ADD_CACHE_INFO(del_total, nr);
 }
 
+int add_to_swap_trans_huge(struct page *page, struct list_head *list)
+{
+	swp_entry_t entry;
+	int ret = 0;
+
+	/* cannot split, which may be needed during swap in, skip it */
+	if (!can_split_huge_page(page))
+		return -EBUSY;
+	/* fallback to split huge page firstly if no PMD map */
+	if (!compound_mapcount(page))
+		return 0;
+	entry = get_huge_swap_page();
+	if (!entry.val)
+		return 0;
+	if (mem_cgroup_try_charge_swap(page, entry, HPAGE_PMD_NR)) {
+		__swapcache_free(entry, true);
+		return -EOVERFLOW;
+	}
+	ret = add_to_swap_cache(page, entry,
+				__GFP_HIGH | __GFP_NOMEMALLOC|__GFP_NOWARN);
+	/* -ENOMEM radix-tree allocation failure */
+	if (ret) {
+		__swapcache_free(entry, true);
+		return 0;
+	}
+	ret = split_huge_page_to_list(page, list);
+	if (ret) {
+		delete_from_swap_cache(page);
+		return -EBUSY;
+	}
+	return 1;
+}
+
 /**
  * add_to_swap - allocate swap space for a page
  * @page: page we want to move to swap
  *
  * Allocate swap space for the page and add the page to the
- * swap cache.  Caller needs to hold the page lock. 
+ * swap cache.  Caller needs to hold the page lock.
  */
 int add_to_swap(struct page *page, struct list_head *list)
 {
@@ -187,6 +221,14 @@ int add_to_swap(struct page *page, struct list_head *list)
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(!PageUptodate(page), page);
 
+	if (unlikely(PageTransHuge(page))) {
+		err = add_to_swap_trans_huge(page, list);
+		if (err < 0)
+			return 0;
+		else if (err > 0)
+			return err;
+		/* fallback to split firstly if return 0 */
+	}
 	entry = get_swap_page();
 	if (!entry.val)
 		return 0;
@@ -306,7 +348,7 @@ struct page * lookup_swap_cache(swp_entry_t entry)
 
 	page = find_get_page(swap_address_space(entry), entry.val);
 
-	if (page) {
+	if (page && likely(!PageCompound(page))) {
 		INC_CACHE_INFO(find_success);
 		if (TestClearPageReadahead(page))
 			atomic_inc(&swapin_readahead_hits);
@@ -332,8 +374,13 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
 		 * that would confuse statistics.
 		 */
 		found_page = find_get_page(swapper_space, entry.val);
-		if (found_page)
+		if (found_page) {
+			if (unlikely(PageCompound(found_page))) {
+				put_page(found_page);
+				found_page = NULL;
+			}
 			break;
+		}
 
 		/*
 		 * Get a new page to read into from swap.
-- 
2.8.1

--
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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-08-10 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <01f101d1f2da$5e943aa0$1bbcafe0$@alibaba-inc.com>
     [not found] ` <01f201d1f2dc$bd43f750$37cbe5f0$@alibaba-inc.com>
2016-08-10  8:01   ` [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out Hillf Danton
2016-08-10 14:45     ` Huang, Ying
2016-08-10 16:28       ` Dave Hansen
2016-08-10 16:49         ` Huang, Ying
2016-08-09 16:37 [RFC 00/11] THP swap: Delay splitting THP during swapping out Huang, Ying
2016-08-09 16:37 ` [RFC 11/11] mm, THP, swap: Delay splitting THP during swap out Huang, Ying

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox