From patchwork Fri Dec 3 09:19:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 12654503 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 12154C433F5 for ; Fri, 3 Dec 2021 09:20:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 925346B0074; Fri, 3 Dec 2021 04:20:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D4536B0075; Fri, 3 Dec 2021 04:20:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C4A86B0078; Fri, 3 Dec 2021 04:20:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 6E9626B0074 for ; Fri, 3 Dec 2021 04:20:11 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3BC0E183D9839 for ; Fri, 3 Dec 2021 09:20:01 +0000 (UTC) X-FDA: 78875936202.18.A2116CF Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf30.hostedemail.com (Postfix) with ESMTP id D8375E001983 for ; Fri, 3 Dec 2021 09:20:00 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id x5so2367274pfr.0 for ; Fri, 03 Dec 2021 01:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id; bh=jYAv0iWmWBE455h4D1IoUIYFZpKUBtbS2GMUOFjDnlE=; b=kRYjEoBxRWU78OrMfvBtdKgvs6qE/KJjO3fy91csgbbJWqzmiiAdqT5p6zDn7yo0YL bb9R4uXRxa2eOdhpGBbZOZHnduqW+4MjxSNmI9u0AJGrykeAyqGJSjPtWQ37188QV/s3 oEhBfj73LjJMFw06iSe8nL6pLjcZB4xsuMq856NXbpwVoOj1quy8KM0oarCMF8ogWuxU 8Mar2BNjwyEmHB+0eytQrCDl0TcUq4/Rgck3Zoi+FklpoWhP4xqSDjs4x8ZwN/jr5p3m 2IMsEgjAxZN5nDLAOLq9AY8ZvWYHh/2t6XlwrsdMeDx/9ZacZ1JBVjXjGYq+58pZJZtf 4nCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id; bh=jYAv0iWmWBE455h4D1IoUIYFZpKUBtbS2GMUOFjDnlE=; b=fRcrAY+YmS8eS4HhouhEoCRBdqunuogmlzEuxAFDcmMcCc7Il+v7krsWcAhX8FWTXz ceae3pX5JVgIGIjGl8eFGQ5ET0nfFiJf+t14pWixUcGh5tKWi1WpwDHzjQNAiaewzT69 uYrAcm/y3sbgOrZ+qbG/HJwUAIEcXooalPvRYlsJ7k3yt8TRP3VO39EusS+CjGP4+qG8 Bj/uz/TLNfi+aAxur1roFrKph03ZaJIiRshUB8hKn7IicRwdbUIBVYULh1stjwRMxkfE JLbRUx6S6ac+pHM6JI5OGDZBNQURvBMKT8jyqcxRKGcz8ClQuOOUkMjCTTJoupLZZCXo C8Kg== X-Gm-Message-State: AOAM530JtjjS1zWvsqUK/AsLqkQMBq9X/0nai5YNEyAZQvf928dEOt+N l2ezmwThWk57oz8XkHkwRbM= X-Google-Smtp-Source: ABdhPJyKFkn8+whNJapWOI58OhVFjpnY70TICL+9MQy4V3v/NORKVWagAb4THUVQq+VWQ2MOvZmbDw== X-Received: by 2002:a63:6c81:: with SMTP id h123mr3766011pgc.313.1638523199638; Fri, 03 Dec 2021 01:19:59 -0800 (PST) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d19sm2602423pfv.199.2021.12.03.01.19.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Dec 2021 01:19:59 -0800 (PST) From: Huangzhaoyang To: Nitin Gupta , Sergey Senozhatsky , Jens Axboe , Andrew Morton , Johannes Weiner , Minchan Kim , Michal Hocko , Zhaoyang Huang , Ingo Molnar , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm: count swap_writepage into PSI_IO STALL Date: Fri, 3 Dec 2021 17:19:40 +0800 Message-Id: <1638523180-4884-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Stat-Signature: oin6m5h9xf1o89rr1fzx491qgif3sz5d Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kRYjEoBx; spf=pass (imf30.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D8375E001983 X-HE-Tag: 1638523200-994815 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: Zhaoyang Huang We would like to count swap_writepage into PSI_IO STALL time. There are two reasons for doing so: 1. Swap_writepage introduces non-productive times. especially under the scenario of RAM based swap device. 2. High swappiness value will lead to more anon pages to be swap out. 3. IO pressure is inconsistent to PGSWPOUT. Signed-off-by: Zhaoyang Huang --- include/linux/psi.h | 6 ++++++ kernel/sched/psi.c | 15 +++++++++++++++ mm/vmscan.c | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/linux/psi.h b/include/linux/psi.h index 65eb147..6eb3a6f 100644 --- a/include/linux/psi.h +++ b/include/linux/psi.h @@ -23,6 +23,9 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next, void psi_memstall_enter(unsigned long *flags); void psi_memstall_leave(unsigned long *flags); +void psi_iostall_enter(void); +void psi_iostall_leave(void); + int psi_show(struct seq_file *s, struct psi_group *group, enum psi_res res); #ifdef CONFIG_CGROUPS @@ -45,6 +48,9 @@ static inline void psi_init(void) {} static inline void psi_memstall_enter(unsigned long *flags) {} static inline void psi_memstall_leave(unsigned long *flags) {} +static inline void psi_iostall_enter(void) {} +static inline void psi_iostall_leave(void) {} + #ifdef CONFIG_CGROUPS static inline int psi_cgroup_alloc(struct cgroup *cgrp) { diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 923a0d6..643b48c 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -958,6 +958,21 @@ void psi_memstall_leave(unsigned long *flags) rq_unlock_irq(rq, &rf); } +void psi_iostall_enter(void) +{ + if (static_branch_likely(&psi_disabled)) + return; + + psi_task_change(current, 0, TSK_IOWAIT); +} + +void psi_iostall_leave(void) +{ + if (static_branch_likely(&psi_disabled)) + return; + + psi_task_change(current, TSK_IOWAIT, 0); +} #ifdef CONFIG_CGROUPS int psi_cgroup_alloc(struct cgroup *cgroup) { diff --git a/mm/vmscan.c b/mm/vmscan.c index 74296c2..798907b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1072,7 +1072,17 @@ static pageout_t pageout(struct page *page, struct address_space *mapping) }; SetPageReclaim(page); + + /* + * For the ram based swap device, there is no chance for reclaim + * context sleeping on the congested IO while it really introduce + * non-productive time. So count the period into PSI_IO. + * Don't worry about the file page, just counting it in as it has + * less chance to be here. + */ + psi_iostall_enter(); res = mapping->a_ops->writepage(page, &wbc); + psi_iostall_leave(); if (res < 0) handle_write_error(mapping, page, res); if (res == AOP_WRITEPAGE_ACTIVATE) {