Skip to content

Commit c077719

Browse files
hkamezawatorvalds
authored andcommitted
memcg: mem+swap controller Kconfig
Config and control variable for mem+swap controller. This patch adds CONFIG_CGROUP_MEM_RES_CTLR_SWAP (memory resource controller swap extension.) For accounting swap, it's obvious that we have to use additional memory to remember "who uses swap". This adds more overhead. So, it's better to offer "choice" to users. This patch adds 2 choices. This patch adds 2 parameters to enable swap extension or not. - CONFIG - boot option Reviewed-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Balbir Singh <balbir@in.ibm.com> Cc: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d13d144 commit c077719

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

Documentation/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,9 @@ and is between 256 and 4096 characters. It is defined in the file
15621562

15631563
nosoftlockup [KNL] Disable the soft-lockup detector.
15641564

1565+
noswapaccount [KNL] Disable accounting of swap in memory resource
1566+
controller. (See Documentation/controllers/memory.txt)
1567+
15651568
nosync [HW,M68K] Disables sync negotiation for all devices.
15661569

15671570
notsc [BUGS=X86-32] Disable Time Stamp Counter

include/linux/memcontrol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
7777
extern long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone,
7878
int priority, enum lru_list lru);
7979

80+
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
81+
extern int do_swap_account;
82+
#endif
8083

8184
#else /* CONFIG_CGROUP_MEM_RES_CTLR */
8285
struct mem_cgroup;

init/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,23 @@ config CGROUP_MEM_RES_CTLR
428428
config MM_OWNER
429429
bool
430430

431+
config CGROUP_MEM_RES_CTLR_SWAP
432+
bool "Memory Resource Controller Swap Extension(EXPERIMENTAL)"
433+
depends on CGROUP_MEM_RES_CTLR && SWAP && EXPERIMENTAL
434+
help
435+
Add swap management feature to memory resource controller. When you
436+
enable this, you can limit mem+swap usage per cgroup. In other words,
437+
when you disable this, memory resource controller has no cares to
438+
usage of swap...a process can exhaust all of the swap. This extension
439+
is useful when you want to avoid exhaustion swap but this itself
440+
adds more overheads and consumes memory for remembering information.
441+
Especially if you use 32bit system or small memory system, please
442+
be careful about enabling this. When memory resource controller
443+
is disabled by boot option, this will be automatically disabled and
444+
there will be no overhead from this. Even when you set this config=y,
445+
if boot option "noswapaccount" is set, swap will not be accounted.
446+
447+
431448
endmenu
432449

433450
config SYSFS_DEPRECATED

mm/memcontrol.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
struct cgroup_subsys mem_cgroup_subsys __read_mostly;
4242
#define MEM_CGROUP_RECLAIM_RETRIES 5
4343

44+
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
45+
/* Turned on only when memory cgroup is enabled && really_do_swap_account = 0 */
46+
int do_swap_account __read_mostly;
47+
static int really_do_swap_account __initdata = 1; /* for remember boot option*/
48+
#else
49+
#define do_swap_account (0)
50+
#endif
51+
52+
4453
/*
4554
* Statistics for memory cgroup.
4655
*/
@@ -1404,6 +1413,18 @@ static void mem_cgroup_free(struct mem_cgroup *mem)
14041413
}
14051414

14061415

1416+
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
1417+
static void __init enable_swap_cgroup(void)
1418+
{
1419+
if (!mem_cgroup_subsys.disabled && really_do_swap_account)
1420+
do_swap_account = 1;
1421+
}
1422+
#else
1423+
static void __init enable_swap_cgroup(void)
1424+
{
1425+
}
1426+
#endif
1427+
14071428
static struct cgroup_subsys_state *
14081429
mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
14091430
{
@@ -1419,6 +1440,9 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
14191440
for_each_node_state(node, N_POSSIBLE)
14201441
if (alloc_mem_cgroup_per_zone_info(mem, node))
14211442
goto free_out;
1443+
/* root ? */
1444+
if (cont->parent == NULL)
1445+
enable_swap_cgroup();
14221446

14231447
return &mem->css;
14241448
free_out:
@@ -1490,3 +1514,13 @@ struct cgroup_subsys mem_cgroup_subsys = {
14901514
.attach = mem_cgroup_move_task,
14911515
.early_init = 0,
14921516
};
1517+
1518+
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
1519+
1520+
static int __init disable_swap_account(char *s)
1521+
{
1522+
really_do_swap_account = 0;
1523+
return 1;
1524+
}
1525+
__setup("noswapaccount", disable_swap_account);
1526+
#endif

0 commit comments

Comments
 (0)