mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, bsingharora@gmail.com,
	jiang.xuexin@zte.com.cn, linux-mm@kvack.org,
	mm-commits@vger.kernel.org, torvalds@linux-foundation.org,
	wang.yong12@zte.com.cn, yang.yang29@zte.com.cn,
	zhang.wenya1@zte.com.cn
Subject: [patch 48/55] delayacct: track delays from memory compact
Date: Wed, 19 Jan 2022 18:10:15 -0800	[thread overview]
Message-ID: <20220120021015.B4I3KD9M2%akpm@linux-foundation.org> (raw)
In-Reply-To: <20220119180714.9e187ce100e4510de3cd9f7d@linux-foundation.org>

From: wangyong <wang.yong12@zte.com.cn>
Subject: delayacct: track delays from memory compact

Delay accounting does not track the delay of memory compact.  When there
is not enough free memory, tasks can spend a amount of their time waiting
for compact.

To get the impact of tasks in direct memory compact, measure the delay
when allocating memory through memory compact.

Also update tools/accounting/getdelays.c:
/ # ./getdelays_next  -di -p 304
print delayacct stats ON
printing IO accounting
PID     304

CPU             count     real total  virtual total    delay total  delay average
                  277      780000000      849039485       18877296          0.068ms
IO              count    delay total  delay average
                    0              0              0ms
SWAP            count    delay total  delay average
                    0              0              0ms
RECLAIM         count    delay total  delay average
                    5    11088812685           2217ms
THRASHING       count    delay total  delay average
                    0              0              0ms
COMPACT         count    delay total  delay average
                    3          72758              0ms
watch: read=0, write=0, cancelled_write=0

Link: https://lkml.kernel.org/r/1638619795-71451-1-git-send-email-wang.yong12@zte.com.cn
Signed-off-by: wangyong <wang.yong12@zte.com.cn>
Reviewed-by: Jiang Xuexin <jiang.xuexin@zte.com.cn>
Reviewed-by: Zhang Wenya <zhang.wenya1@zte.com.cn>
Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/delayacct.h      |   28 ++++++++++++++++++++++++++++
 include/uapi/linux/taskstats.h |    6 +++++-
 kernel/delayacct.c             |   15 +++++++++++++++
 mm/page_alloc.c                |    3 +++
 tools/accounting/getdelays.c   |    8 +++++++-
 5 files changed, 58 insertions(+), 2 deletions(-)

--- a/include/linux/delayacct.h~delayacct-track-delays-from-memory-compact
+++ a/include/linux/delayacct.h
@@ -42,8 +42,12 @@ struct task_delay_info {
 	u64 thrashing_start;
 	u64 thrashing_delay;	/* wait for thrashing page */
 
+	u64 compact_start;
+	u64 compact_delay;	/* wait for memory compact */
+
 	u32 freepages_count;	/* total count of memory reclaim */
 	u32 thrashing_count;	/* total count of thrash waits */
+	u32 compact_count;	/* total count of memory compact */
 };
 #endif
 
@@ -72,6 +76,8 @@ extern void __delayacct_thrashing_start(
 extern void __delayacct_thrashing_end(void);
 extern void __delayacct_swapin_start(void);
 extern void __delayacct_swapin_end(void);
+extern void __delayacct_compact_start(void);
+extern void __delayacct_compact_end(void);
 
 static inline void delayacct_tsk_init(struct task_struct *tsk)
 {
@@ -170,6 +176,24 @@ static inline void delayacct_swapin_end(
 		__delayacct_swapin_end();
 }
 
+static inline void delayacct_compact_start(void)
+{
+	if (!static_branch_unlikely(&delayacct_key))
+		return;
+
+	if (current->delays)
+		__delayacct_compact_start();
+}
+
+static inline void delayacct_compact_end(void)
+{
+	if (!static_branch_unlikely(&delayacct_key))
+		return;
+
+	if (current->delays)
+		__delayacct_compact_end();
+}
+
 #else
 static inline void delayacct_init(void)
 {}
@@ -200,6 +224,10 @@ static inline void delayacct_swapin_star
 {}
 static inline void delayacct_swapin_end(void)
 {}
+static inline void delayacct_compact_start(void)
+{}
+static inline void delayacct_compact_end(void)
+{}
 
 #endif /* CONFIG_TASK_DELAY_ACCT */
 
--- a/include/uapi/linux/taskstats.h~delayacct-track-delays-from-memory-compact
+++ a/include/uapi/linux/taskstats.h
@@ -34,7 +34,7 @@
  */
 
 
-#define TASKSTATS_VERSION	10
+#define TASKSTATS_VERSION	11
 #define TS_COMM_LEN		32	/* should be >= TASK_COMM_LEN
 					 * in linux/sched.h */
 
@@ -172,6 +172,10 @@ struct taskstats {
 
 	/* v10: 64-bit btime to avoid overflow */
 	__u64	ac_btime64;		/* 64-bit begin time */
+
+	/* Delay waiting for memory compact */
+	__u64	compact_count;
+	__u64	compact_delay_total;
 };
 
 
--- a/kernel/delayacct.c~delayacct-track-delays-from-memory-compact
+++ a/kernel/delayacct.c
@@ -155,10 +155,13 @@ int delayacct_add_tsk(struct taskstats *
 	d->freepages_delay_total = (tmp < d->freepages_delay_total) ? 0 : tmp;
 	tmp = d->thrashing_delay_total + tsk->delays->thrashing_delay;
 	d->thrashing_delay_total = (tmp < d->thrashing_delay_total) ? 0 : tmp;
+	tmp = d->compact_delay_total + tsk->delays->compact_delay;
+	d->compact_delay_total = (tmp < d->compact_delay_total) ? 0 : tmp;
 	d->blkio_count += tsk->delays->blkio_count;
 	d->swapin_count += tsk->delays->swapin_count;
 	d->freepages_count += tsk->delays->freepages_count;
 	d->thrashing_count += tsk->delays->thrashing_count;
+	d->compact_count += tsk->delays->compact_count;
 	raw_spin_unlock_irqrestore(&tsk->delays->lock, flags);
 
 	return 0;
@@ -214,3 +217,15 @@ void __delayacct_swapin_end(void)
 		      &current->delays->swapin_count);
 }
 
+void __delayacct_compact_start(void)
+{
+	current->delays->compact_start = local_clock();
+}
+
+void __delayacct_compact_end(void)
+{
+	delayacct_end(&current->delays->lock,
+		      &current->delays->compact_start,
+		      &current->delays->compact_delay,
+		      &current->delays->compact_count);
+}
--- a/mm/page_alloc.c~delayacct-track-delays-from-memory-compact
+++ a/mm/page_alloc.c
@@ -74,6 +74,7 @@
 #include <linux/padata.h>
 #include <linux/khugepaged.h>
 #include <linux/buffer_head.h>
+#include <linux/delayacct.h>
 #include <asm/sections.h>
 #include <asm/tlbflush.h>
 #include <asm/div64.h>
@@ -4365,6 +4366,7 @@ __alloc_pages_direct_compact(gfp_t gfp_m
 		return NULL;
 
 	psi_memstall_enter(&pflags);
+	delayacct_compact_start();
 	noreclaim_flag = memalloc_noreclaim_save();
 
 	*compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
@@ -4372,6 +4374,7 @@ __alloc_pages_direct_compact(gfp_t gfp_m
 
 	memalloc_noreclaim_restore(noreclaim_flag);
 	psi_memstall_leave(&pflags);
+	delayacct_compact_end();
 
 	if (*compact_result == COMPACT_SKIPPED)
 		return NULL;
--- a/tools/accounting/getdelays.c~delayacct-track-delays-from-memory-compact
+++ a/tools/accounting/getdelays.c
@@ -205,6 +205,8 @@ static void print_delayacct(struct tasks
 	       "RECLAIM  %12s%15s%15s\n"
 	       "      %15llu%15llu%15llums\n"
 	       "THRASHING%12s%15s%15s\n"
+	       "      %15llu%15llu%15llums\n"
+	       "COMPACT  %12s%15s%15s\n"
 	       "      %15llu%15llu%15llums\n",
 	       "count", "real total", "virtual total",
 	       "delay total", "delay average",
@@ -228,7 +230,11 @@ static void print_delayacct(struct tasks
 	       "count", "delay total", "delay average",
 	       (unsigned long long)t->thrashing_count,
 	       (unsigned long long)t->thrashing_delay_total,
-	       average_ms(t->thrashing_delay_total, t->thrashing_count));
+	       average_ms(t->thrashing_delay_total, t->thrashing_count),
+	       "count", "delay total", "delay average",
+	       (unsigned long long)t->compact_count,
+	       (unsigned long long)t->compact_delay_total,
+	       average_ms(t->compact_delay_total, t->compact_count));
 }
 
 static void task_context_switch_counts(struct taskstats *t)
_

  parent reply	other threads:[~2022-01-20  2:10 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  2:07 incoming Andrew Morton
2022-01-20  2:07 ` [patch 01/55] mm: percpu: generalize percpu related config Andrew Morton
2022-01-20  2:07 ` [patch 02/55] mm: percpu: add pcpu_fc_cpu_to_node_fn_t typedef Andrew Morton
2022-01-20  2:07 ` [patch 03/55] mm: percpu: add generic pcpu_fc_alloc/free funciton Andrew Morton
2022-01-20  2:07 ` [patch 04/55] mm: percpu: add generic pcpu_populate_pte() function Andrew Morton
2022-01-20  2:07 ` [patch 05/55] proc/vmcore: don't fake reading zeroes on surprise vmcore_cb unregistration Andrew Morton
2022-01-20  2:08 ` [patch 06/55] proc: make the proc_create[_data]() stubs static inlines Andrew Morton
2022-01-20  2:08 ` [patch 07/55] proc: convert the return type of proc_fd_access_allowed() to be boolean Andrew Morton
2022-01-20  2:08 ` [patch 08/55] sysctl: fix duplicate path separator in printed entries Andrew Morton
2022-01-20  2:08 ` [patch 09/55] sysctl: remove redundant ret assignment Andrew Morton
2022-01-20  2:08 ` [patch 10/55] include/linux/unaligned: replace kernel.h with the necessary inclusions Andrew Morton
2022-01-20  2:08 ` [patch 11/55] kernel.h: include a note to discourage people from including it in headers Andrew Morton
2022-01-20  2:08 ` [patch 12/55] fs/exec: replace strlcpy with strscpy_pad in __set_task_comm Andrew Morton
2022-01-20  2:08 ` [patch 13/55] fs/exec: replace strncpy with strscpy_pad in __get_task_comm Andrew Morton
2022-01-20  2:08 ` [patch 14/55] drivers/infiniband: replace open-coded string copy with get_task_comm Andrew Morton
2022-01-20  2:08 ` [patch 15/55] fs/binfmt_elf: " Andrew Morton
2022-01-20  2:08 ` [patch 16/55] samples/bpf/test_overhead_kprobe_kern: replace bpf_probe_read_kernel with bpf_probe_read_kernel_str to get task comm Andrew Morton
2022-01-20  2:08 ` [patch 17/55] tools/bpf/bpftool/skeleton: " Andrew Morton
2022-01-20  2:08 ` [patch 18/55] tools/testing/selftests/bpf: replace open-coded 16 with TASK_COMM_LEN Andrew Morton
2022-01-20  2:08 ` [patch 19/55] kthread: dynamically allocate memory to store kthread's full name Andrew Morton
2022-01-20  2:08 ` [patch 20/55] kernel/sys.c: only take tasklist_lock for get/setpriority(PRIO_PGRP) Andrew Morton
2022-01-20  2:08 ` [patch 21/55] get_maintainer: don't remind about no git repo when --nogit is used Andrew Morton
2022-01-20  2:08 ` [patch 22/55] kstrtox: uninline everything Andrew Morton
2022-01-20  2:08 ` [patch 23/55] list: introduce list_is_head() helper and re-use it in list.h Andrew Morton
2022-01-20  2:08 ` [patch 24/55] lib/list_debug.c: print more list debugging context in __list_del_entry_valid() Andrew Morton
2022-01-20  2:09 ` [patch 25/55] hash.h: remove unused define directive Andrew Morton
2022-01-20  2:09 ` [patch 26/55] test_hash.c: split test_int_hash into arch-specific functions Andrew Morton
2022-01-20  2:09 ` [patch 27/55] test_hash.c: split test_hash_init Andrew Morton
2022-01-20  2:09 ` [patch 28/55] lib/Kconfig.debug: properly split hash test kernel entries Andrew Morton
2022-01-20  2:09 ` [patch 29/55] test_hash.c: refactor into kunit Andrew Morton
2022-01-20  2:09 ` [patch 30/55] kunit: replace kernel.h with the necessary inclusions Andrew Morton
2022-01-20  2:09 ` [patch 31/55] uuid: discourage people from using UAPI header in new code Andrew Morton
2022-01-20  2:09 ` [patch 32/55] uuid: remove licence boilerplate text from the header Andrew Morton
2022-01-20  2:09 ` [patch 33/55] lib/test_meminit: destroy cache in kmem_cache_alloc_bulk() test Andrew Morton
2022-01-20  2:09 ` [patch 34/55] checkpatch: relax regexp for COMMIT_LOG_LONG_LINE Andrew Morton
2022-01-20  2:09 ` [patch 35/55] checkpatch: improve Kconfig help test Andrew Morton
2022-01-20  2:09 ` [patch 36/55] const_structs.checkpatch: add frequently used ops structs Andrew Morton
2022-01-20  2:09 ` [patch 37/55] fs/binfmt_elf: use PT_LOAD p_align values for static PIE Andrew Morton
2022-01-20  2:09 ` [patch 38/55] nilfs2: remove redundant pointer sbufs Andrew Morton
2022-01-20  2:09 ` [patch 39/55] hfsplus: use struct_group_attr() for memcpy() region Andrew Morton
2022-01-20  2:09 ` [patch 40/55] FAT: use io_schedule_timeout() instead of congestion_wait() Andrew Morton
2022-01-20  2:09 ` [patch 41/55] fs/adfs: remove unneeded variable make code cleaner Andrew Morton
2022-01-20  2:09 ` [patch 42/55] panic: use error_report_end tracepoint on warnings Andrew Morton
2022-01-20  2:09 ` [patch 43/55] panic: remove oops_id Andrew Morton
2022-01-20  2:10 ` [patch 44/55] delayacct: support swapin delay accounting for swapping without blkio Andrew Morton
2022-01-20  2:10 ` [patch 45/55] delayacct: fix incomplete disable operation when switch enable to disable Andrew Morton
2022-01-20  2:10 ` [patch 46/55] delayacct: cleanup flags in struct task_delay_info and functions use it Andrew Morton
2022-01-20  2:10 ` [patch 47/55] Documentation/accounting/delay-accounting.rst: add thrashing page cache and direct compact Andrew Morton
2022-01-20  2:10 ` Andrew Morton [this message]
2022-01-20  2:10 ` [patch 49/55] configs: introduce debug.config for CI-like setup Andrew Morton
2022-01-20  2:10 ` [patch 50/55] arch/Kconfig: split PAGE_SIZE_LESS_THAN_256KB from PAGE_SIZE_LESS_THAN_64KB Andrew Morton
2022-01-20  2:10 ` [patch 51/55] btrfs: use generic Kconfig option for 256kB page size limit Andrew Morton
2022-01-20  2:10 ` [patch 52/55] lib/Kconfig.debug: make TEST_KMOD depend on PAGE_SIZE_LESS_THAN_256KB Andrew Morton
2022-01-20  2:10 ` [patch 53/55] kcov: fix generic Kconfig dependencies if ARCH_WANTS_NO_INSTR Andrew Morton
2022-01-20  2:10 ` [patch 54/55] ubsan: remove CONFIG_UBSAN_OBJECT_SIZE Andrew Morton
2022-01-20  2:10 ` [patch 55/55] lib: remove redundant assignment to variable ret Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220120021015.B4I3KD9M2%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bsingharora@gmail.com \
    --cc=jiang.xuexin@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=wang.yong12@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    --cc=zhang.wenya1@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).