Commit be09102b authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

mm: memcg: allow lowering memory.swap.max below the current usage

Currently an attempt to set swap.max into a value lower than the actual
swap usage fails, which causes configuration problems as there's no way
of lowering the configuration below the current usage short of turning
off swap entirely.  This makes swap.max difficult to use and allows
delegatees to lock the delegator out of reducing swap allocation.

This patch updates swap_max_write() so that the limit can be lowered
below the current usage.  It doesn't implement active reclaiming of swap
entries for the following reasons.

* mem_cgroup_swap_full() already tells the swap machinary to
  aggressively reclaim swap entries if the usage is above 50% of
  limit, so simply lowering the limit automatically triggers gradual

* Forcing back swapped out pages is likely to heavily impact the
  workload and mess up the working set.  Given that swap usually is a
  lot less valuable and less scarce, letting the existing usage
  dissipate over time through the above gradual reclaim and as they're
  falted back in is likely the better behavior.

Link:[email protected]Signed-off-by: default avatarTejun Heo <[email protected]>
Acked-by: default avatarRoman Gushchin <[email protected]>
Acked-by: default avatarRik van Riel <[email protected]>
Acked-by: default avatarJohannes Weiner <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Shaohua Li <[email protected]>
Signed-off-by: default avatarAndrew Morton <[email protected]>
Signed-off-by: default avatarLinus Torvalds <[email protected]>
parent 20acce67
...@@ -1245,6 +1245,11 @@ PAGE_SIZE multiple when read back. ...@@ -1245,6 +1245,11 @@ PAGE_SIZE multiple when read back.
because of running out of swap system-wide or max because of running out of swap system-wide or max
limit. limit.
When reduced under the current usage, the existing swap
entries are reclaimed gradually and the swap usage may stay
higher than the limit for an extended period of time. This
reduces the impact on the workload and memory management.
Usage Guidelines Usage Guidelines
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
...@@ -6280,11 +6280,7 @@ static ssize_t swap_max_write(struct kernfs_open_file *of, ...@@ -6280,11 +6280,7 @@ static ssize_t swap_max_write(struct kernfs_open_file *of,
if (err) if (err)
return err; return err;
mutex_lock(&memcg_max_mutex); xchg(&memcg->swap.max, max);
err = page_counter_set_max(&memcg->swap, max);
if (err)
return err;
return nbytes; return nbytes;
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment