Skip to content

Commit d7911ef

Browse files
kosakitorvalds
authored andcommitted
vmscan: implement swap token priority aging
While testing for memcg aware swap token, I observed a swap token was often grabbed an intermittent running process (eg init, auditd) and they never release a token. Why? Some processes (eg init, auditd, audispd) wake up when a process exiting. And swap token can be get first page-in process when a process exiting makes no swap token owner. Thus such above intermittent running process often get a token. And currently, swap token priority is only decreased at page fault path. Then, if the process sleep immediately after to grab swap token, the swap token priority never be decreased. That's obviously undesirable. This patch implement very poor (and lightweight) priority aging. It only be affect to the above corner case and doesn't change swap tendency workload performance (eg multi process qsbench load) Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Reviewed-by: Rik van Riel <riel@redhat.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 83cd81a commit d7911ef

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

‎include/trace/events/vmscan.h‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,26 +366,32 @@ DEFINE_EVENT_CONDITION(put_swap_token_template, disable_swap_token,
366366

367367
TRACE_EVENT_CONDITION(update_swap_token_priority,
368368
TP_PROTO(struct mm_struct *mm,
369-
unsigned int old_prio),
369+
unsigned int old_prio,
370+
struct mm_struct *swap_token_mm),
370371

371-
TP_ARGS(mm, old_prio),
372+
TP_ARGS(mm, old_prio, swap_token_mm),
372373

373374
TP_CONDITION(mm->token_priority != old_prio),
374375

375376
TP_STRUCT__entry(
376377
__field(struct mm_struct*, mm)
377378
__field(unsigned int, old_prio)
378379
__field(unsigned int, new_prio)
380+
__field(struct mm_struct*, swap_token_mm)
381+
__field(unsigned int, swap_token_prio)
379382
),
380383

381384
TP_fast_assign(
382-
__entry->mm = mm;
383-
__entry->old_prio = old_prio;
384-
__entry->new_prio = mm->token_priority;
385+
__entry->mm = mm;
386+
__entry->old_prio = old_prio;
387+
__entry->new_prio = mm->token_priority;
388+
__entry->swap_token_mm = swap_token_mm;
389+
__entry->swap_token_prio = swap_token_mm ? swap_token_mm->token_priority : 0;
385390
),
386391

387-
TP_printk("mm=%p old_prio=%u new_prio=%u",
388-
__entry->mm, __entry->old_prio, __entry->new_prio)
392+
TP_printk("mm=%p old_prio=%u new_prio=%u swap_token_mm=%p token_prio=%u",
393+
__entry->mm, __entry->old_prio, __entry->new_prio,
394+
__entry->swap_token_mm, __entry->swap_token_prio)
389395
);
390396

391397
#endif /* _TRACE_VMSCAN_H */

‎mm/thrash.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525

2626
#include <trace/events/vmscan.h>
2727

28+
#define TOKEN_AGING_INTERVAL (0xFF)
29+
2830
static DEFINE_SPINLOCK(swap_token_lock);
2931
struct mm_struct *swap_token_mm;
3032
struct mem_cgroup *swap_token_memcg;
3133
static unsigned int global_faults;
34+
static unsigned int last_aging;
3235

3336
#ifdef CONFIG_CGROUP_MEM_RES_CTLR
3437
static struct mem_cgroup *swap_token_memcg_from_mm(struct mm_struct *mm)
@@ -64,6 +67,11 @@ void grab_swap_token(struct mm_struct *mm)
6467
if (!swap_token_mm)
6568
goto replace_token;
6669

70+
if ((global_faults - last_aging) > TOKEN_AGING_INTERVAL) {
71+
swap_token_mm->token_priority /= 2;
72+
last_aging = global_faults;
73+
}
74+
6775
if (mm == swap_token_mm) {
6876
mm->token_priority += 2;
6977
goto update_priority;
@@ -81,7 +89,7 @@ void grab_swap_token(struct mm_struct *mm)
8189
goto replace_token;
8290

8391
update_priority:
84-
trace_update_swap_token_priority(mm, old_prio);
92+
trace_update_swap_token_priority(mm, old_prio, swap_token_mm);
8593

8694
out:
8795
mm->faultstamp = global_faults;
@@ -94,6 +102,7 @@ void grab_swap_token(struct mm_struct *mm)
94102
trace_replace_swap_token(swap_token_mm, mm);
95103
swap_token_mm = mm;
96104
swap_token_memcg = swap_token_memcg_from_mm(mm);
105+
last_aging = global_faults;
97106
goto out;
98107
}
99108

0 commit comments

Comments
 (0)