linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zswap: Add shrink_enabled that can disable swap shrink to increase store performance
@ 2019-10-25  8:02 Hui Zhu
  2019-11-08 16:04 ` Dan Streetman
  0 siblings, 1 reply; 4+ messages in thread
From: Hui Zhu @ 2019-10-25  8:02 UTC (permalink / raw)
  To: sjenning, ddstreet, linux-mm, linux-kernel; +Cc: Hui Zhu

zswap will try to shrink pool when zswap is full.
This commit add shrink_enabled that can disable swap shrink to increase
store performance.  User can disable swap shrink if care about the store
performance.

For example in a VM with 1 CPU 1G memory 4G swap:
echo lz4 > /sys/module/zswap/parameters/compressor
echo z3fold > /sys/module/zswap/parameters/zpool
echo 0 > /sys/module/zswap/parameters/same_filled_pages_enabled
echo 1 > /sys/module/zswap/parameters/enabled
usemem -a -n 1 $((4000 * 1024 * 1024))
4718592000 bytes / 114937822 usecs = 40091 KB/s
101700 usecs to free memory
echo 0 > /sys/module/zswap/parameters/shrink_enabled
usemem -a -n 1 $((4000 * 1024 * 1024))
4718592000 bytes / 8837320 usecs = 521425 KB/s
129577 usecs to free memory

The store speed increased when zswap shrink disabled.

Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
---
 mm/zswap.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/zswap.c b/mm/zswap.c
index 46a3223..731e3d1e 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -114,6 +114,10 @@ static bool zswap_same_filled_pages_enabled = true;
 module_param_named(same_filled_pages_enabled, zswap_same_filled_pages_enabled,
 		   bool, 0644);
 
+/* Enable/disable zswap shrink (enabled by default) */
+static bool zswap_shrink_enabled = true;
+module_param_named(shrink_enabled, zswap_shrink_enabled, bool, 0644);
+
 /*********************************
 * data structures
 **********************************/
@@ -947,6 +951,9 @@ static int zswap_shrink(void)
 	struct zswap_pool *pool;
 	int ret;
 
+	if (!zswap_shrink_enabled)
+		return -EPERM;
+
 	pool = zswap_pool_last_get();
 	if (!pool)
 		return -ENOENT;
-- 
2.7.4


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

* Re: [PATCH] zswap: Add shrink_enabled that can disable swap shrink to increase store performance
  2019-10-25  8:02 [PATCH] zswap: Add shrink_enabled that can disable swap shrink to increase store performance Hui Zhu
@ 2019-11-08 16:04 ` Dan Streetman
  2019-11-11  1:57   ` Hui Zhu
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Streetman @ 2019-11-08 16:04 UTC (permalink / raw)
  To: Hui Zhu; +Cc: Seth Jennings, Linux-MM, linux-kernel

On Fri, Oct 25, 2019 at 4:02 AM Hui Zhu <teawaterz@linux.alibaba.com> wrote:
>
> zswap will try to shrink pool when zswap is full.
> This commit add shrink_enabled that can disable swap shrink to increase
> store performance.  User can disable swap shrink if care about the store
> performance.

I don't understand - if zswap is full it can't store any more pages
without shrinking the current pool.  This commit will just force all
pages to swap when zswap is full.  This has nothing to do with 'store
performance'.

I think it would be much better to remove any user option for this and
implement some hysteresis; store pages normally until the zpool is
full, then reject all pages going to that pool until there is some %
free, at which point allow pages to be stored into the pool again.
That will prevent (or at least reduce) the constant performance hit
when a zpool fills up, and just fallback to normal swapping to disk
until the zpool has some amount of free space again.

>
> For example in a VM with 1 CPU 1G memory 4G swap:
> echo lz4 > /sys/module/zswap/parameters/compressor
> echo z3fold > /sys/module/zswap/parameters/zpool
> echo 0 > /sys/module/zswap/parameters/same_filled_pages_enabled
> echo 1 > /sys/module/zswap/parameters/enabled
> usemem -a -n 1 $((4000 * 1024 * 1024))
> 4718592000 bytes / 114937822 usecs = 40091 KB/s
> 101700 usecs to free memory
> echo 0 > /sys/module/zswap/parameters/shrink_enabled
> usemem -a -n 1 $((4000 * 1024 * 1024))
> 4718592000 bytes / 8837320 usecs = 521425 KB/s
> 129577 usecs to free memory
>
> The store speed increased when zswap shrink disabled.
>
> Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
> ---
>  mm/zswap.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 46a3223..731e3d1e 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -114,6 +114,10 @@ static bool zswap_same_filled_pages_enabled = true;
>  module_param_named(same_filled_pages_enabled, zswap_same_filled_pages_enabled,
>                    bool, 0644);
>
> +/* Enable/disable zswap shrink (enabled by default) */
> +static bool zswap_shrink_enabled = true;
> +module_param_named(shrink_enabled, zswap_shrink_enabled, bool, 0644);
> +
>  /*********************************
>  * data structures
>  **********************************/
> @@ -947,6 +951,9 @@ static int zswap_shrink(void)
>         struct zswap_pool *pool;
>         int ret;
>
> +       if (!zswap_shrink_enabled)
> +               return -EPERM;
> +
>         pool = zswap_pool_last_get();
>         if (!pool)
>                 return -ENOENT;
> --
> 2.7.4
>

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

* Re: [PATCH] zswap: Add shrink_enabled that can disable swap shrink to increase store performance
  2019-11-08 16:04 ` Dan Streetman
@ 2019-11-11  1:57   ` Hui Zhu
  2020-01-26 19:36     ` Dan Streetman
  0 siblings, 1 reply; 4+ messages in thread
From: Hui Zhu @ 2019-11-11  1:57 UTC (permalink / raw)
  To: Dan Streetman; +Cc: Seth Jennings, Linux-MM, linux-kernel



On 2019/11/9 12:04 上午, Dan Streetman wrote:
> On Fri, Oct 25, 2019 at 4:02 AM Hui Zhu <teawaterz@linux.alibaba.com> wrote:
>>
>> zswap will try to shrink pool when zswap is full.
>> This commit add shrink_enabled that can disable swap shrink to increase
>> store performance.  User can disable swap shrink if care about the store
>> performance.
> 
> I don't understand - if zswap is full it can't store any more pages
> without shrinking the current pool.  This commit will just force all
> pages to swap when zswap is full.  This has nothing to do with 'store
> performance'.
> 
> I think it would be much better to remove any user option for this and
> implement some hysteresis; store pages normally until the zpool is
> full, then reject all pages going to that pool until there is some %
> free, at which point allow pages to be stored into the pool again.
> That will prevent (or at least reduce) the constant performance hit
> when a zpool fills up, and just fallback to normal swapping to disk
> until the zpool has some amount of free space again.
> 

This idea is really cool!
Do you mind I make a patch for it?

Thanks,
Hui

>>
>> For example in a VM with 1 CPU 1G memory 4G swap:
>> echo lz4 > /sys/module/zswap/parameters/compressor
>> echo z3fold > /sys/module/zswap/parameters/zpool
>> echo 0 > /sys/module/zswap/parameters/same_filled_pages_enabled
>> echo 1 > /sys/module/zswap/parameters/enabled
>> usemem -a -n 1 $((4000 * 1024 * 1024))
>> 4718592000 bytes / 114937822 usecs = 40091 KB/s
>> 101700 usecs to free memory
>> echo 0 > /sys/module/zswap/parameters/shrink_enabled
>> usemem -a -n 1 $((4000 * 1024 * 1024))
>> 4718592000 bytes / 8837320 usecs = 521425 KB/s
>> 129577 usecs to free memory
>>
>> The store speed increased when zswap shrink disabled.
>>
>> Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
>> ---
>>   mm/zswap.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/mm/zswap.c b/mm/zswap.c
>> index 46a3223..731e3d1e 100644
>> --- a/mm/zswap.c
>> +++ b/mm/zswap.c
>> @@ -114,6 +114,10 @@ static bool zswap_same_filled_pages_enabled = true;
>>   module_param_named(same_filled_pages_enabled, zswap_same_filled_pages_enabled,
>>                     bool, 0644);
>>
>> +/* Enable/disable zswap shrink (enabled by default) */
>> +static bool zswap_shrink_enabled = true;
>> +module_param_named(shrink_enabled, zswap_shrink_enabled, bool, 0644);
>> +
>>   /*********************************
>>   * data structures
>>   **********************************/
>> @@ -947,6 +951,9 @@ static int zswap_shrink(void)
>>          struct zswap_pool *pool;
>>          int ret;
>>
>> +       if (!zswap_shrink_enabled)
>> +               return -EPERM;
>> +
>>          pool = zswap_pool_last_get();
>>          if (!pool)
>>                  return -ENOENT;
>> --
>> 2.7.4
>>

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

* Re: [PATCH] zswap: Add shrink_enabled that can disable swap shrink to increase store performance
  2019-11-11  1:57   ` Hui Zhu
@ 2020-01-26 19:36     ` Dan Streetman
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Streetman @ 2020-01-26 19:36 UTC (permalink / raw)
  To: Hui Zhu, Vitaly Wool; +Cc: Seth Jennings, Linux-MM, linux-kernel

On Sun, Nov 10, 2019 at 8:58 PM Hui Zhu <teawaterz@linux.alibaba.com> wrote:
>
>
>
> On 2019/11/9 12:04 上午, Dan Streetman wrote:
> > On Fri, Oct 25, 2019 at 4:02 AM Hui Zhu <teawaterz@linux.alibaba.com> wrote:
> >>
> >> zswap will try to shrink pool when zswap is full.
> >> This commit add shrink_enabled that can disable swap shrink to increase
> >> store performance.  User can disable swap shrink if care about the store
> >> performance.
> >
> > I don't understand - if zswap is full it can't store any more pages
> > without shrinking the current pool.  This commit will just force all
> > pages to swap when zswap is full.  This has nothing to do with 'store
> > performance'.
> >
> > I think it would be much better to remove any user option for this and
> > implement some hysteresis; store pages normally until the zpool is
> > full, then reject all pages going to that pool until there is some %
> > free, at which point allow pages to be stored into the pool again.
> > That will prevent (or at least reduce) the constant performance hit
> > when a zpool fills up, and just fallback to normal swapping to disk
> > until the zpool has some amount of free space again.
> >
>
> This idea is really cool!
> Do you mind I make a patch for it?

Sorry for the delay, again.

I think Vitaly has a patch adding this.

>
> Thanks,
> Hui
>
> >>
> >> For example in a VM with 1 CPU 1G memory 4G swap:
> >> echo lz4 > /sys/module/zswap/parameters/compressor
> >> echo z3fold > /sys/module/zswap/parameters/zpool
> >> echo 0 > /sys/module/zswap/parameters/same_filled_pages_enabled
> >> echo 1 > /sys/module/zswap/parameters/enabled
> >> usemem -a -n 1 $((4000 * 1024 * 1024))
> >> 4718592000 bytes / 114937822 usecs = 40091 KB/s
> >> 101700 usecs to free memory
> >> echo 0 > /sys/module/zswap/parameters/shrink_enabled
> >> usemem -a -n 1 $((4000 * 1024 * 1024))
> >> 4718592000 bytes / 8837320 usecs = 521425 KB/s
> >> 129577 usecs to free memory
> >>
> >> The store speed increased when zswap shrink disabled.
> >>
> >> Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
> >> ---
> >>   mm/zswap.c | 7 +++++++
> >>   1 file changed, 7 insertions(+)
> >>
> >> diff --git a/mm/zswap.c b/mm/zswap.c
> >> index 46a3223..731e3d1e 100644
> >> --- a/mm/zswap.c
> >> +++ b/mm/zswap.c
> >> @@ -114,6 +114,10 @@ static bool zswap_same_filled_pages_enabled = true;
> >>   module_param_named(same_filled_pages_enabled, zswap_same_filled_pages_enabled,
> >>                     bool, 0644);
> >>
> >> +/* Enable/disable zswap shrink (enabled by default) */
> >> +static bool zswap_shrink_enabled = true;
> >> +module_param_named(shrink_enabled, zswap_shrink_enabled, bool, 0644);
> >> +
> >>   /*********************************
> >>   * data structures
> >>   **********************************/
> >> @@ -947,6 +951,9 @@ static int zswap_shrink(void)
> >>          struct zswap_pool *pool;
> >>          int ret;
> >>
> >> +       if (!zswap_shrink_enabled)
> >> +               return -EPERM;
> >> +
> >>          pool = zswap_pool_last_get();
> >>          if (!pool)
> >>                  return -ENOENT;
> >> --
> >> 2.7.4
> >>

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

end of thread, other threads:[~2020-01-26 19:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  8:02 [PATCH] zswap: Add shrink_enabled that can disable swap shrink to increase store performance Hui Zhu
2019-11-08 16:04 ` Dan Streetman
2019-11-11  1:57   ` Hui Zhu
2020-01-26 19:36     ` Dan Streetman

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