Skip to content

Commit

Permalink
mm: memcontrol: deprecate swapaccounting=0 mode
Browse files Browse the repository at this point in the history
The swapaccounting= commandline option already does very little today.  To
close a trivial containment failure case, the swap ownership tracking part
of the swap controller has recently become mandatory (see commit
2d1c498 ("mm: memcontrol: make swap tracking an integral part of
memory control") for details), which makes up the majority of the work
during swapout, swapin, and the swap slot map.

The only thing left under this flag is the page_counter operations and the
visibility of the swap control files in the first place, which are rather
meager savings.  There also aren't many scenarios, if any, where
controlling the memory of a cgroup while allowing it unlimited access to a
global swap space is a workable resource isolation strategy.

On the other hand, there have been several bugs and confusion around the
many possible swap controller states (cgroup1 vs cgroup2 behavior, memory
accounting without swap accounting, memcg runtime disabled).

This puts the maintenance overhead of retaining the toggle above its
practical benefits.  Deprecate it.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Johannes Weiner <[email protected]>
Suggested-by: Shakeel Butt <[email protected]>
Reviewed-by: Shakeel Butt <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Roman Gushchin <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
hnaz authored and akpm00 committed Oct 3, 2022
1 parent c91bdc9 commit b25806d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 46 deletions.
6 changes: 0 additions & 6 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6036,12 +6036,6 @@
This parameter controls use of the Protected
Execution Facility on pSeries.

swapaccount= [KNL]
Format: [0|1]
Enable accounting of swap in memory resource
controller if no parameter or 1 is given or disable
it if 0 is given (See Documentation/admin-guide/cgroup-v1/memory.rst)

swiotlb= [ARM,IA-64,PPC,MIPS,X86]
Format: { <int> [,<int>] | force | noforce }
<int> -- Number of I/O TLB slabs
Expand Down
50 changes: 10 additions & 40 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,14 @@ static bool cgroup_memory_nosocket __ro_after_init;
/* Kernel memory accounting disabled? */
static bool cgroup_memory_nokmem __ro_after_init;

/* Whether the swap controller is active */
#ifdef CONFIG_MEMCG_SWAP
static bool cgroup_memory_noswap __initdata;

static DEFINE_STATIC_KEY_FALSE(memcg_swap_enabled_key);
static inline bool memcg_swap_enabled(void)
{
return static_branch_likely(&memcg_swap_enabled_key);
}
#else
static inline bool memcg_swap_enabled(void)
{
return false;
}
#endif

#ifdef CONFIG_CGROUP_WRITEBACK
static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
#endif

/* Whether legacy memory+swap accounting is active */
static bool do_memsw_account(void)
{
return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg_swap_enabled();
return !cgroup_subsys_on_dfl(memory_cgrp_subsys);
}

#define THRESHOLDS_EVENTS_TARGET 128
Expand Down Expand Up @@ -7379,7 +7363,7 @@ void mem_cgroup_swapout(struct folio *folio, swp_entry_t entry)
if (!mem_cgroup_is_root(memcg))
page_counter_uncharge(&memcg->memory, nr_entries);

if (memcg_swap_enabled() && memcg != swap_memcg) {
if (memcg != swap_memcg) {
if (!mem_cgroup_is_root(swap_memcg))
page_counter_charge(&swap_memcg->memsw, nr_entries);
page_counter_uncharge(&memcg->memsw, nr_entries);
Expand Down Expand Up @@ -7431,7 +7415,7 @@ int __mem_cgroup_try_charge_swap(struct folio *folio, swp_entry_t entry)

memcg = mem_cgroup_id_get_online(memcg);

if (memcg_swap_enabled() && !mem_cgroup_is_root(memcg) &&
if (!mem_cgroup_is_root(memcg) &&
!page_counter_try_charge(&memcg->swap, nr_pages, &counter)) {
memcg_memory_event(memcg, MEMCG_SWAP_MAX);
memcg_memory_event(memcg, MEMCG_SWAP_FAIL);
Expand Down Expand Up @@ -7466,7 +7450,7 @@ void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages)
rcu_read_lock();
memcg = mem_cgroup_from_id(id);
if (memcg) {
if (memcg_swap_enabled() && !mem_cgroup_is_root(memcg)) {
if (!mem_cgroup_is_root(memcg)) {
if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
page_counter_uncharge(&memcg->swap, nr_pages);
else
Expand All @@ -7482,7 +7466,7 @@ long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg)
{
long nr_swap_pages = get_nr_swap_pages();

if (!memcg_swap_enabled() || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
if (mem_cgroup_disabled() || do_memsw_account())
return nr_swap_pages;
for (; memcg != root_mem_cgroup; memcg = parent_mem_cgroup(memcg))
nr_swap_pages = min_t(long, nr_swap_pages,
Expand All @@ -7499,7 +7483,7 @@ bool mem_cgroup_swap_full(struct folio *folio)

if (vm_swap_full())
return true;
if (!memcg_swap_enabled() || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
if (do_memsw_account())
return false;

memcg = folio_memcg(folio);
Expand All @@ -7519,10 +7503,9 @@ bool mem_cgroup_swap_full(struct folio *folio)

static int __init setup_swap_account(char *s)
{
bool res;

if (!kstrtobool(s, &res))
cgroup_memory_noswap = !res;
pr_warn_once("The swapaccount= commandline option is deprecated. "
"Please report your usecase to [email protected] if you "
"depend on this functionality.\n");
return 1;
}
__setup("swapaccount=", setup_swap_account);
Expand Down Expand Up @@ -7791,31 +7774,18 @@ static struct cftype zswap_files[] = {
};
#endif /* CONFIG_MEMCG_KMEM && CONFIG_ZSWAP */

/*
* If mem_cgroup_swap_init() is implemented as a subsys_initcall()
* instead of a core_initcall(), this could mean cgroup_memory_noswap still
* remains set to false even when memcg is disabled via "cgroup_disable=memory"
* boot parameter. This may result in premature OOPS inside
* mem_cgroup_get_nr_swap_pages() function in corner cases.
*/
static int __init mem_cgroup_swap_init(void)
{
/* No memory control -> no swap control */
if (mem_cgroup_disabled())
cgroup_memory_noswap = true;

if (cgroup_memory_noswap)
return 0;

static_branch_enable(&memcg_swap_enabled_key);

WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, swap_files));
WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys, memsw_files));
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, zswap_files));
#endif
return 0;
}
core_initcall(mem_cgroup_swap_init);
subsys_initcall(mem_cgroup_swap_init);

#endif /* CONFIG_MEMCG_SWAP */

0 comments on commit b25806d

Please sign in to comment.