Skip to content

Commit eccb52e

Browse files
hnaztorvalds
authored andcommitted
mm: memcontrol: prepare swap controller setup for integration
A few cleanups to streamline the swap controller setup: - Replace the do_swap_account flag with cgroup_memory_noswap. This brings it in line with other functionality that is usually available unless explicitly opted out of - nosocket, nokmem. - Remove the really_do_swap_account flag that stores the boot option and is later used to switch the do_swap_account. It's not clear why this indirection is/was necessary. Use do_swap_account directly. - Minor coding style polishing Signed-off-by: Johannes Weiner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Joonsoo Kim <[email protected]> Cc: Alex Shi <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Balbir Singh <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent f0e45fb commit eccb52e

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

include/linux/memcontrol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim,
558558
void mem_cgroup_print_oom_group(struct mem_cgroup *memcg);
559559

560560
#ifdef CONFIG_MEMCG_SWAP
561-
extern int do_swap_account;
561+
extern bool cgroup_memory_noswap;
562562
#endif
563563

564564
struct mem_cgroup *lock_page_memcg(struct page *page);

mm/memcontrol.c

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ static bool cgroup_memory_nokmem;
8383

8484
/* Whether the swap controller is active */
8585
#ifdef CONFIG_MEMCG_SWAP
86-
int do_swap_account __read_mostly;
86+
#ifdef CONFIG_MEMCG_SWAP_ENABLED
87+
bool cgroup_memory_noswap __read_mostly;
8788
#else
88-
#define do_swap_account 0
89-
#endif
89+
bool cgroup_memory_noswap __read_mostly = 1;
90+
#endif /* CONFIG_MEMCG_SWAP_ENABLED */
91+
#else
92+
#define cgroup_memory_noswap 1
93+
#endif /* CONFIG_MEMCG_SWAP */
9094

9195
#ifdef CONFIG_CGROUP_WRITEBACK
9296
static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
@@ -95,7 +99,7 @@ static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
9599
/* Whether legacy memory+swap accounting is active */
96100
static bool do_memsw_account(void)
97101
{
98-
return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && do_swap_account;
102+
return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_noswap;
99103
}
100104

101105
#define THRESHOLDS_EVENTS_TARGET 128
@@ -6528,18 +6532,19 @@ int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask,
65286532
/*
65296533
* Every swap fault against a single page tries to charge the
65306534
* page, bail as early as possible. shmem_unuse() encounters
6531-
* already charged pages, too. The USED bit is protected by
6532-
* the page lock, which serializes swap cache removal, which
6535+
* already charged pages, too. page->mem_cgroup is protected
6536+
* by the page lock, which serializes swap cache removal, which
65336537
* in turn serializes uncharging.
65346538
*/
65356539
VM_BUG_ON_PAGE(!PageLocked(page), page);
65366540
if (compound_head(page)->mem_cgroup)
65376541
goto out;
65386542

6539-
if (do_swap_account) {
6543+
if (!cgroup_memory_noswap) {
65406544
swp_entry_t ent = { .val = page_private(page), };
6541-
unsigned short id = lookup_swap_cgroup_id(ent);
6545+
unsigned short id;
65426546

6547+
id = lookup_swap_cgroup_id(ent);
65436548
rcu_read_lock();
65446549
memcg = mem_cgroup_from_id(id);
65456550
if (memcg && !css_tryget_online(&memcg->css))
@@ -7012,7 +7017,7 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry)
70127017
struct mem_cgroup *memcg;
70137018
unsigned short oldid;
70147019

7015-
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) || !do_swap_account)
7020+
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) || cgroup_memory_noswap)
70167021
return 0;
70177022

70187023
memcg = page->mem_cgroup;
@@ -7056,7 +7061,7 @@ void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages)
70567061
struct mem_cgroup *memcg;
70577062
unsigned short id;
70587063

7059-
if (!do_swap_account)
7064+
if (cgroup_memory_noswap)
70607065
return;
70617066

70627067
id = swap_cgroup_record(entry, 0, nr_pages);
@@ -7079,7 +7084,7 @@ long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg)
70797084
{
70807085
long nr_swap_pages = get_nr_swap_pages();
70817086

7082-
if (!do_swap_account || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
7087+
if (cgroup_memory_noswap || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
70837088
return nr_swap_pages;
70847089
for (; memcg != root_mem_cgroup; memcg = parent_mem_cgroup(memcg))
70857090
nr_swap_pages = min_t(long, nr_swap_pages,
@@ -7096,7 +7101,7 @@ bool mem_cgroup_swap_full(struct page *page)
70967101

70977102
if (vm_swap_full())
70987103
return true;
7099-
if (!do_swap_account || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
7104+
if (cgroup_memory_noswap || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
71007105
return false;
71017106

71027107
memcg = page->mem_cgroup;
@@ -7114,22 +7119,15 @@ bool mem_cgroup_swap_full(struct page *page)
71147119
return false;
71157120
}
71167121

7117-
/* for remember boot option*/
7118-
#ifdef CONFIG_MEMCG_SWAP_ENABLED
7119-
static int really_do_swap_account __initdata = 1;
7120-
#else
7121-
static int really_do_swap_account __initdata;
7122-
#endif
7123-
7124-
static int __init enable_swap_account(char *s)
7122+
static int __init setup_swap_account(char *s)
71257123
{
71267124
if (!strcmp(s, "1"))
7127-
really_do_swap_account = 1;
7125+
cgroup_memory_noswap = 0;
71287126
else if (!strcmp(s, "0"))
7129-
really_do_swap_account = 0;
7127+
cgroup_memory_noswap = 1;
71307128
return 1;
71317129
}
7132-
__setup("swapaccount=", enable_swap_account);
7130+
__setup("swapaccount=", setup_swap_account);
71337131

71347132
static u64 swap_current_read(struct cgroup_subsys_state *css,
71357133
struct cftype *cft)
@@ -7226,7 +7224,7 @@ static struct cftype swap_files[] = {
72267224
{ } /* terminate */
72277225
};
72287226

7229-
static struct cftype memsw_cgroup_files[] = {
7227+
static struct cftype memsw_files[] = {
72307228
{
72317229
.name = "memsw.usage_in_bytes",
72327230
.private = MEMFILE_PRIVATE(_MEMSWAP, RES_USAGE),
@@ -7255,13 +7253,12 @@ static struct cftype memsw_cgroup_files[] = {
72557253

72567254
static int __init mem_cgroup_swap_init(void)
72577255
{
7258-
if (!mem_cgroup_disabled() && really_do_swap_account) {
7259-
do_swap_account = 1;
7260-
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys,
7261-
swap_files));
7262-
WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys,
7263-
memsw_cgroup_files));
7264-
}
7256+
if (mem_cgroup_disabled() || cgroup_memory_noswap)
7257+
return 0;
7258+
7259+
WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, swap_files));
7260+
WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys, memsw_files));
7261+
72657262
return 0;
72667263
}
72677264
subsys_initcall(mem_cgroup_swap_init);

mm/swap_cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
171171
unsigned long length;
172172
struct swap_cgroup_ctrl *ctrl;
173173

174-
if (!do_swap_account)
174+
if (cgroup_memory_noswap)
175175
return 0;
176176

177177
length = DIV_ROUND_UP(max_pages, SC_PER_PAGE);
@@ -209,7 +209,7 @@ void swap_cgroup_swapoff(int type)
209209
unsigned long i, length;
210210
struct swap_cgroup_ctrl *ctrl;
211211

212-
if (!do_swap_account)
212+
if (cgroup_memory_noswap)
213213
return;
214214

215215
mutex_lock(&swap_cgroup_mutex);

0 commit comments

Comments
 (0)