From patchwork Sat Dec 4 12:09:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yong w X-Patchwork-Id: 12656497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4711CC433EF for ; Sat, 4 Dec 2021 12:10:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CFEC6B007E; Sat, 4 Dec 2021 07:10:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6809D6B0080; Sat, 4 Dec 2021 07:10:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 547AE6B0081; Sat, 4 Dec 2021 07:10:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 443B16B007E for ; Sat, 4 Dec 2021 07:10:43 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0272B1837CD68 for ; Sat, 4 Dec 2021 12:10:33 +0000 (UTC) X-FDA: 78879994746.07.708C601 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf29.hostedemail.com (Postfix) with ESMTP id A16C7900013E for ; Sat, 4 Dec 2021 12:10:31 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id d24so11737219wra.0 for ; Sat, 04 Dec 2021 04:10:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=bVVV3uEtfiYj88cCYd+MCtwH/YItJDy9WxebFmCU/7w=; b=OsY4t9p8LrFFBl8yk56eU9qzL57nnbKuaqzNrR/0NnbjBJRMqld+YXEYl1eLLKPcg4 ehT6unbVBhZxyueBoYjmTsIT7DkMQrGCYlJ6VRYgb05+XC5uJUox6znNaVnW6jlVyFTV 6XN3nTyQmsXE7+/K9EJKTjROZ1MlNAfzIpAnKuGJGWTpjz7QVMP3os2WmRwIdBGgqKeG 7P5EAsDV6JqBPPACXJzI5/HrHs/aO2Rv3o4Z+nyyZtaTjJnxG7fHD3zneeEN9vPHraOY 9/YhfbOvFEpA33mTaEvaQRodvTTcCquOlQk5i4oDh+/b23TZwQoh9H4TpjtgfGu5fwrk 53NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bVVV3uEtfiYj88cCYd+MCtwH/YItJDy9WxebFmCU/7w=; b=vzw15yLbQBN+/OfFfP3s4g8Lex855JOwh4ZVMcDGBfm24mdMgrWjnKUtLNwBfl8SoJ gCMG1pdwo5Ho7mEw7DioBQ0rw5nRjdMDO5GZg9E5IsT85Skw6lApNnLpn03YnOvJGFy8 UmSEXWjaIqGbcezRaLxskaUz4ZvJfBFpEjWw6FRo/sU54+hRUYbr1Wa/3hA5RLlThLaZ zgADhUxybl6VJixkXDmo4MUz5AN9ykwRAhB8mzpwi5Tsf6lTZZgirRwvnqppAPn/1+Yz zOtbxyYJK74mwaUVeJkV06EfAawLfrU597mmjqq51EnTQ63xCUA99r82y1EL7GYVtPzs +bww== X-Gm-Message-State: AOAM5321BoXJ5wAY0JDJUm7k8mZGcfOWsch3SBIqJU96wBY7eU4PNntr NSK0HUIiuEG+pPf5UE4Lkf4= X-Google-Smtp-Source: ABdhPJxNiYyPQzRRXLr+fDR3CKcI4exMAVM56SAftbu9ysjlo8h+YEk1aRHm7OSEn6JZ8yQofVL/YA== X-Received: by 2002:adf:d0d0:: with SMTP id z16mr29135384wrh.601.1638619831400; Sat, 04 Dec 2021 04:10:31 -0800 (PST) Received: from localhost.localdomain ([45.67.146.70]) by smtp.gmail.com with ESMTPSA id g198sm5709024wme.23.2021.12.04.04.10.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Dec 2021 04:10:31 -0800 (PST) From: yongw.pur@gmail.com X-Google-Original-From: wang.yong12@zte.com.cn To: bsingharora@gmail.com, akpm@linux-foundation.org, peterz@infradead.org, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, yang.yang29@zte.com.cn, wang.yong12@zte.com.cn Subject: [PATCH v2 linux-next] delayacct: track delays from memory compact Date: Sat, 4 Dec 2021 04:09:55 -0800 Message-Id: <1638619795-71451-1-git-send-email-wang.yong12@zte.com.cn> X-Mailer: git-send-email 2.7.4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A16C7900013E X-Stat-Signature: rbjf41t9xidxfsc4eoyzbwxg5eyorof6 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OsY4t9p8; spf=pass (imf29.hostedemail.com: domain of yongw.pur@gmail.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=yongw.pur@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1638619831-464840 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: wangyong 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 Reported-by: Zeal Robot Reported-by: kernel test robot Signed-off-by: wangyong Reviewed-by: Andrew Morton Reviewed-by: Jiang Xuexin Reviewed-by: Zhang Wenya Reviewed-by: Yang Yang Reviewed-by: Balbir Singh Reviewed-by: Balbir Singh --- Changes since v1: -fixed duplicate member freepages_start. 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(-) diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h index 435c365..3e03d01 100644 --- a/include/linux/delayacct.h +++ b/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(void); 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(void) __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_start(void) {} 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 */ diff --git a/include/uapi/linux/taskstats.h b/include/uapi/linux/taskstats.h index ccbd087..12327d3 100644 --- a/include/uapi/linux/taskstats.h +++ b/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; }; diff --git a/kernel/delayacct.c b/kernel/delayacct.c index 11f3cd8..c5e8cea 100644 --- a/kernel/delayacct.c +++ b/kernel/delayacct.c @@ -155,10 +155,13 @@ int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk) 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) ¤t->delays->swapin_count); } +void __delayacct_compact_start(void) +{ + current->delays->compact_start = local_clock(); +} + +void __delayacct_compact_end(void) +{ + delayacct_end(¤t->delays->lock, + ¤t->delays->compact_start, + ¤t->delays->compact_delay, + ¤t->delays->compact_count); +} diff --git a/mm/page_alloc.c b/mm/page_alloc.c index edfd6c8..6430226 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -4363,6 +4364,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, 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, @@ -4370,6 +4372,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, memalloc_noreclaim_restore(noreclaim_flag); psi_memstall_leave(&pflags); + delayacct_compact_end(); if (*compact_result == COMPACT_SKIPPED) return NULL; diff --git a/tools/accounting/getdelays.c b/tools/accounting/getdelays.c index 5ef1c15..11e8673 100644 --- a/tools/accounting/getdelays.c +++ b/tools/accounting/getdelays.c @@ -205,6 +205,8 @@ static void print_delayacct(struct taskstats *t) "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 taskstats *t) "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)