Re: [RFC] mm: allow to decrease swap.max below actual swap usage
From: Roman Gushchin
Date: Thu Apr 05 2018 - 10:48:27 EST
On Tue, Mar 20, 2018 at 10:35:43PM +0000, Roman Gushchin wrote:
> Currently an attempt to set swap.max into a value lower
> than the actual swap usage fails. And a user can't do much
> with it, except turning off swap globally (using swapoff).
>
> This patch aims to fix this issue by allowing setting swap.max
> into any value (which corresponds to cgroup v2 API design),
> and schedule a background job to fit swap size into the new limit.
>
> The following script can be used to test the memory.swap behavior:
> #!/bin/bash
>
> mkdir -p /sys/fs/cgroup/test_swap
> echo 100M > /sys/fs/cgroup/test_swap/memory.max
> echo max > /sys/fs/cgroup/test_swap/memory.swap.max
>
> mkdir -p /sys/fs/cgroup/test_swap_2
> echo 100M > /sys/fs/cgroup/test_swap_2/memory.max
> echo max > /sys/fs/cgroup/test_swap_2/memory.swap.max
>
> echo $$ > /sys/fs/cgroup/test_swap/cgroup.procs
> allocate 200M &
>
> echo $$ > /sys/fs/cgroup/test_swap_2/cgroup.procs
> allocate 200M &
>
> sleep 2
>
> cat /sys/fs/cgroup/test_swap/memory.swap.current
> cat /sys/fs/cgroup/test_swap_2/memory.swap.current
>
> echo max > /sys/fs/cgroup/test_swap/memory.max
> echo 50M > /sys/fs/cgroup/test_swap/memory.swap.max
>
> sleep 10
>
> cat /sys/fs/cgroup/test_swap/memory.swap.current
> cat /sys/fs/cgroup/test_swap_2/memory.swap.current
>
> pkill allocate
>
> Original test results:
> 106024960
> 106348544
> ./swap.sh: line 23: echo: write error: Device or resource busy
> 106024960
> 106348544
>
> With this patch applied:
> 106045440
> 106352640
> 52428800
> 106201088
Any comments, thoughts, feedback?
Rebased version below.
---