From patchwork Mon Aug 15 07:11:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CGEL X-Patchwork-Id: 12943202 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 0BAEFC00140 for ; Mon, 15 Aug 2022 07:14:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53B8E6B0089; Mon, 15 Aug 2022 03:14:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 450FF8D0001; Mon, 15 Aug 2022 03:14:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C7976B008C; Mon, 15 Aug 2022 03:14:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 176406B0089 for ; Mon, 15 Aug 2022 03:14:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EB7541A0D2F for ; Mon, 15 Aug 2022 07:14:37 +0000 (UTC) X-FDA: 79800964194.09.3E0C413 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf17.hostedemail.com (Postfix) with ESMTP id 8AF624000B for ; Mon, 15 Aug 2022 07:14:37 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id m2so5706440pls.4 for ; Mon, 15 Aug 2022 00:14:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=DTMT8hoLjJB/orrtWMlqwT6cn7CDgzNtrQnAm9ijTQg=; b=JKPUll07EKwOwZpZ+xuSWHHTA9Q/FAIIEApg5y/br8C6061slymiseOGFUaOhAtjqG MlhPgAAyeSXcjAnLKd3LdbtL8OEWr/EcEJOh39RwMNjI8EY/Uz4iYFdKBs2a2oGrzJj9 bdIQpufHw6l9zOqUQeb8BbWAONVuWWxxBZ4dWELZ21cdxrgmqa44e5pvCmTapr0LZaJ7 gVaiaHWaZfF+NI73BLrCkj3G2+yoQhEwXD2xU2JJHryv1RBwaqWsU5w1VYhx1M8bNlIJ qZ551UrRxuAGhzhSFfXf3gpEkPPriVPvF0VjKNTtV1NyESZ4JqWv7MEJ/0ap9fkFcjKo XBjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=DTMT8hoLjJB/orrtWMlqwT6cn7CDgzNtrQnAm9ijTQg=; b=n+IuHUIz5P8LI0ewSDE7e+BH5yrjFL/AWIAywEDae8JIb261rElsqPWp0EzmWiwkzO btwB+xWbs3pI3SAoATRTPWJAeFlSymEMvZNnOeVNM///IN66jVqis7EerYqUqVr20G2d HdCLg7VPsl1fFhFwaGvo4ui31m12FjKbo8kljJtt5AWoCpwsdWQ35LkdZzEkk6lVEVFm J9KEuwUJs8dQp492CC5vCUv+RcUUyPuuawpPi7Gsj526bJix8HWl6fo9SKDsku1qebAi 28oNLGBvUvxpG+wODIWqpgB131b4gUMEJ/mQJAuPz8FziGNdvS34lcGrB1NX+w6ubMsD XLAg== X-Gm-Message-State: ACgBeo3Rb9U4BbFW9DIrir3aWI3bx6YcruqYKHvyYccrnnkInHx6Cnyi mYhhElqsqhoaM/cV3rccBE8= X-Google-Smtp-Source: AA6agR4scsuaEt80ywtS9mg6M5jLafTWgBa9vOO9V2ztaIu1rJYKs9L+TG73N4VBawcF+LkHcraaXg== X-Received: by 2002:a17:90b:3558:b0:1fa:7d01:4e04 with SMTP id lt24-20020a17090b355800b001fa7d014e04mr3632978pjb.5.1660547676359; Mon, 15 Aug 2022 00:14:36 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id m13-20020a62a20d000000b0052e82671a57sm6039527pff.73.2022.08.15.00.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 00:14:35 -0700 (PDT) From: cgel.zte@gmail.com X-Google-Original-From: yang.yang29@zte.com.cn To: bsingharora@gmail.com, akpm@linux-foundation.org, iamjoonsoo.kim@lge.com Cc: mingo@redhat.com, bristot@redhat.com, vschneid@redhat.com, willy@infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Yang Yang , CGEL ZTE , Ran Xiaokai , wangyong Subject: [PATCH v2 1/2] delayacct: support re-entrance detection of thrashing accounting Date: Mon, 15 Aug 2022 07:11:35 +0000 Message-Id: <20220815071134.74551-1-yang.yang29@zte.com.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660547677; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=DTMT8hoLjJB/orrtWMlqwT6cn7CDgzNtrQnAm9ijTQg=; b=fONd7jHL311SgP+7wye/X0MTPjAiAxSV1lIxISWYzw+C6YZm7eNfVaniFh0yoOBo3Bl/mb bJ1CVCTnbLCvRkeVpoba1d+U7T+B5a9M6syTjI8qGmIRQTmcnB+OLg0BNmyw6WsXeOXG9i K9Mq0U5pa2VDb80FRVxyJc9RjxqipWY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JKPUll07; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660547677; a=rsa-sha256; cv=none; b=IVa2nr9mFOcTp/4ZstosiRdVtVJ2NT+Vo8g8G9WYaSLayNe3IVSD1vxY9cZc0F/ezXxyrQ /qrikC8v3B6QP5msEdXFHmc+eIPG6X5pnsjsQVGC3sxnVke8wxSHRVIYvip95RV6Ct4SKH FD3yAIgI4kyzqellwDA6ebLkvU2l4bc= X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 8AF624000B X-Rspam-User: X-Stat-Signature: ug6pfmiezfj1mz6puio5fnpizdrp1k3x Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JKPUll07; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com X-HE-Tag: 1660547677-166788 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: Yang Yang Once upon a time, we only support accounting thrashing of page cache. Then Joonsoo introduced workingset detection for anonymous pages and we gained the ability to account thrashing of them[1]. For page cache thrashing accounting, there is no suitable place to do it in fs level likes swap_readpage(). So we have to do it in folio_wait_bit_common(). Then for anonymous pages thrashing accounting, we have to do it in both swap_readpage() and folio_wait_bit_common(). This likes PSI, so we should let thrashing accounting supports re-entrance detection. This patch is to prepare complete thrashing accounting, and is based on patch "filemap: make the accounting of thrashing more consistent". [1] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") Signed-off-by: Yang Yang Signed-off-by: CGEL ZTE Reviewed-by: Andrew Morton Reviewed-by: Ran Xiaokai Reviewed-by: wangyong Cc: Joonsoo Kim Acked-by: Joonsoo Kim --- Change for v2: - use bool *in_thrashing instead of unsigned long *flags --- include/linux/delayacct.h | 16 ++++++++-------- include/linux/sched.h | 4 ++++ kernel/delayacct.c | 13 +++++++++++-- mm/filemap.c | 10 ++++++---- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h index 58aea2d7385c..0da97dba9ef8 100644 --- a/include/linux/delayacct.h +++ b/include/linux/delayacct.h @@ -73,8 +73,8 @@ extern int delayacct_add_tsk(struct taskstats *, struct task_struct *); extern __u64 __delayacct_blkio_ticks(struct task_struct *); extern void __delayacct_freepages_start(void); extern void __delayacct_freepages_end(void); -extern void __delayacct_thrashing_start(void); -extern void __delayacct_thrashing_end(void); +extern void __delayacct_thrashing_start(bool *in_thrashing); +extern void __delayacct_thrashing_end(bool *in_thrashing); extern void __delayacct_swapin_start(void); extern void __delayacct_swapin_end(void); extern void __delayacct_compact_start(void); @@ -143,22 +143,22 @@ static inline void delayacct_freepages_end(void) __delayacct_freepages_end(); } -static inline void delayacct_thrashing_start(void) +static inline void delayacct_thrashing_start(bool *in_thrashing) { if (!static_branch_unlikely(&delayacct_key)) return; if (current->delays) - __delayacct_thrashing_start(); + __delayacct_thrashing_start(in_thrashing); } -static inline void delayacct_thrashing_end(void) +static inline void delayacct_thrashing_end(bool *in_thrashing) { if (!static_branch_unlikely(&delayacct_key)) return; if (current->delays) - __delayacct_thrashing_end(); + __delayacct_thrashing_end(in_thrashing); } static inline void delayacct_swapin_start(void) @@ -237,9 +237,9 @@ static inline void delayacct_freepages_start(void) {} static inline void delayacct_freepages_end(void) {} -static inline void delayacct_thrashing_start(void) +static inline void delayacct_thrashing_start(bool *in_thrashing) {} -static inline void delayacct_thrashing_end(void) +static inline void delayacct_thrashing_end(bool *in_thrashing) {} static inline void delayacct_swapin_start(void) {} diff --git a/include/linux/sched.h b/include/linux/sched.h index d6b0866c71ed..5fb942e29583 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -943,6 +943,10 @@ struct task_struct { #ifdef CONFIG_CPU_SUP_INTEL unsigned reported_split_lock:1; #endif +#ifdef CONFIG_TASK_DELAY_ACCT + /* delay due to memory thrashing */ + unsigned in_thrashing:1; +#endif unsigned long atomic_flags; /* Flags requiring atomic access. */ diff --git a/kernel/delayacct.c b/kernel/delayacct.c index 164ed9ef77a3..e39cb696cfbd 100644 --- a/kernel/delayacct.c +++ b/kernel/delayacct.c @@ -214,13 +214,22 @@ void __delayacct_freepages_end(void) ¤t->delays->freepages_count); } -void __delayacct_thrashing_start(void) +void __delayacct_thrashing_start(bool *in_thrashing) { + *in_thrashing = !!current->in_thrashing; + if (*in_thrashing) + return; + + current->in_thrashing = 1; current->delays->thrashing_start = local_clock(); } -void __delayacct_thrashing_end(void) +void __delayacct_thrashing_end(bool *in_thrashing) { + if (*in_thrashing) + return; + + current->in_thrashing = 0; delayacct_end(¤t->delays->lock, ¤t->delays->thrashing_start, ¤t->delays->thrashing_delay, diff --git a/mm/filemap.c b/mm/filemap.c index cfe15e89b3c2..bc37a93bb29a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1222,10 +1222,11 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, wait_queue_entry_t *wait = &wait_page.wait; bool thrashing = false; unsigned long pflags; + bool in_thrashing; if (bit_nr == PG_locked && !folio_test_uptodate(folio) && folio_test_workingset(folio)) { - delayacct_thrashing_start(); + delayacct_thrashing_start(&in_thrashing); psi_memstall_enter(&pflags); thrashing = true; } @@ -1325,7 +1326,7 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, finish_wait(q, wait); if (thrashing) { - delayacct_thrashing_end(); + delayacct_thrashing_end(&in_thrashing); psi_memstall_leave(&pflags); } @@ -1374,12 +1375,13 @@ void migration_entry_wait_on_locked(swp_entry_t entry, pte_t *ptep, wait_queue_entry_t *wait = &wait_page.wait; bool thrashing = false; unsigned long pflags; + bool in_thrashing; wait_queue_head_t *q; struct folio *folio = page_folio(pfn_swap_entry_to_page(entry)); q = folio_waitqueue(folio); if (!folio_test_uptodate(folio) && folio_test_workingset(folio)) { - delayacct_thrashing_start(); + delayacct_thrashing_start(&in_thrashing); psi_memstall_enter(&pflags); thrashing = true; } @@ -1426,7 +1428,7 @@ void migration_entry_wait_on_locked(swp_entry_t entry, pte_t *ptep, finish_wait(q, wait); if (thrashing) { - delayacct_thrashing_end(); + delayacct_thrashing_end(&in_thrashing); psi_memstall_leave(&pflags); } }