From patchwork Thu Mar 9 09:31:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13167118 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 9AF8EC6FD1C for ; Thu, 9 Mar 2023 09:31:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C8F8280002; Thu, 9 Mar 2023 04:31:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3784F6B0078; Thu, 9 Mar 2023 04:31:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24068280002; Thu, 9 Mar 2023 04:31:32 -0500 (EST) 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 15B846B0075 for ; Thu, 9 Mar 2023 04:31:32 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 93355403E0 for ; Thu, 9 Mar 2023 09:31:31 +0000 (UTC) X-FDA: 80548841982.07.8E2119B Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf09.hostedemail.com (Postfix) with ESMTP id BC877140013 for ; Thu, 9 Mar 2023 09:31:29 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KzU6h4ue; spf=pass (imf09.hostedemail.com: domain of 3cKcJZAoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3cKcJZAoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678354289; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=o6dgxagOpBb1myYnk/1Y2AGrRWWDZLYTueWoLu8qIY4=; b=K8ytITM9SZ4CuJmhpi1wjgQOjQQd1LSHDXfCD0hgVRAOZ2LLu2DlZeyU8pd600gCoZVE9C GGH5uFezj24zbQngLzW2LUelaXRGG1QbCrZP9xMt/Qs08d6/m+rdyJJqBnaxqqJVE2W5Uw 8klRnb3YaO5JAIwk04odsIe3NT8bIdE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KzU6h4ue; spf=pass (imf09.hostedemail.com: domain of 3cKcJZAoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3cKcJZAoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678354289; a=rsa-sha256; cv=none; b=6VU0cUvDp0+h41x6RlgsmcWMDG9mjeNNDRPk/2vBgLmnbQEFED28eYC4ysbFDNCknluSoV GHoicfz8y79e/aGdhEZ0F7pEEOrSKPPcZIAkccHrMLdQq8jr3vhIxC1+ixoqEr7R52AiCz 3KMCCi/CiJzaGbBlb81y1Ap/jvWQrh0= Received: by mail-pg1-f202.google.com with SMTP id d22-20020a63d716000000b00502e3fb8ff3so452279pgg.10 for ; Thu, 09 Mar 2023 01:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678354288; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=o6dgxagOpBb1myYnk/1Y2AGrRWWDZLYTueWoLu8qIY4=; b=KzU6h4ueyt1nc3fHTw62ynzTN6cM5FPoDfMBmAqJ1Wwes61zVej5BOhlYyPncxm4Zm nkjKeBNIQMZU0E9YJO2405czXqReQIP71dpM6JRcIVBwGfbOfnDAO+93r67dHWvV1VcL zONddPvKo2/hWkzUIRnhDO3Zqp+7yh7T+acFffATa66sYzOvTr15BMFihxW3t2a2tMq/ 8Ig75rYkpQRqgddwtZBlA3k3y0eMCsf3xzOYsCI2yvjWMp0avrLAbOSW5a+OH2FI5iL+ ETd/0TFbN+DnBMOE/8xtP1qGx1HOTcBW/q+JbvhFqWJVi18NNllY9Hag5hM4SObpgkS6 mKfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678354288; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o6dgxagOpBb1myYnk/1Y2AGrRWWDZLYTueWoLu8qIY4=; b=nFlrjvHaHEgblbHpyNmbNQsUjKJP4AiDQhiyFPO1LZxtgVSHZtQil0tLCMKsRAHZzt 2+aXdYGIf8I36g4f5AkEwIeUuSSYveY/JtXkTon7wXO4Yv2zxNJClxw6H7Z9nsVavQCe plVolAkY5Ye3Odm6SbeyAH35hSq9LB+QXXZLUGZA2YqaZojWfcX5Q0zuR7GGPFk+dnGM aoZN+13hVSlApVherQcnHyHY4DZpPjDINSGTPpMNd1GDX6KaIrPDa2PvbBcfP1s81Amg P/OPmHnNVP5F7eZ1E9n3LqHIk7gCyUR5I89NKYrSbozsq+qsI7Z9hf+MEDG2pX9QScsW YeMg== X-Gm-Message-State: AO0yUKVgsgKKgPbRcP2acqEsLmekaYIHZI6n7n0xu+3JrrUo22WuLEBZ +5M2e7D+FIv2vwWKn4iAlGvxR8+hIokfkHWW X-Google-Smtp-Source: AK7set82CEBSuqo8FpS3nsNPKqDoN9u1SA11kEpTwZaYFka9KSS8D9zMVtgu+8uzsp90VdIxYuFl/oAa7auTdfM+ X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a63:5508:0:b0:502:fd71:d58c with SMTP id j8-20020a635508000000b00502fd71d58cmr7728137pgb.9.1678354288447; Thu, 09 Mar 2023 01:31:28 -0800 (PST) Date: Thu, 9 Mar 2023 09:31:07 +0000 In-Reply-To: <20230309093109.3039327-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230309093109.3039327-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230309093109.3039327-2-yosryahmed@google.com> Subject: [PATCH v2 1/3] mm: vmscan: move set_task_reclaim_state() after cgroup_reclaim() From: Yosry Ahmed To: Alexander Viro , "Darrick J. Wong" , Christoph Lameter , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Shakeel Butt , Michal Hocko , Yu Zhao Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Stat-Signature: rgeeqd4uipdm8ardn9ubjtaohuxtgydb X-Rspam-User: X-Rspamd-Queue-Id: BC877140013 X-Rspamd-Server: rspam06 X-HE-Tag: 1678354289-109279 X-HE-Meta: U2FsdGVkX1+c0KiYMniyXRQ7nUeay8BbAfofifw3iTDhV8kUF7kmkiWvh7a8opVA3valABRt8NgKgnvd7q8WDPEvLsYFTaMMu4OTLyFHTcPikp5VAwFk6O+4yyWrxHY6ygLcuGWGC8nWRGx+/yIt32mgmRdxaIL1KaqIv9chxA4ViKSAbN1iM904HTQch1dQG63ChngwzksA9TV3TVF/3ZbVPqyTRY/eojnEWHET82LOJuzspNPsh/Y8eBLSl79grUcOkrEF/ot9H7qct2biGZMk1Jgpnr1pfdowjWF/DlLTaE71ZSOWVH1kOXfEh9VwfaW8cClXHDpJsQAXUZHgLGGivgC2Q7MagxggfagZ5HfFQja3qebmoNx4hqTUX2dybrQ7eBcJ/D9+gXmLxnI3Sz6kIj3x4vns5Kdrm27PsXT943DVzT6AK3UIb7iLdp+S2sW++ScUU6tQUfKz3klsH0C3hDcq+2f8hVDs6ohu1prUWuqj+VeHnmRIiz43lfmQtIJ/JOTekXE76WjzHnzgg2yc5KgGVA7AaqvyflFqewcN+30NktnNqfeKJhMZP/oInJPPOnPcPDptMo0sJNd8pHj7lAVxRmFVKXZ5YhnpvhsmhX61gD71UI7MjRfNf9QymPW57A7dqjraXLSYqaSiQdfBI81ZWa3pHIF1cbueWrkUpBsKtgMLZLJngs3+ovMj/nClGkhulyk+XzX2IF6aD/ncmOS8rZCNo9QdgKorylpUYDpwd1h8q/TFu7aTkjwkqUXVN1MfDTnny/u+EjASv+YJpt+zcj4ERVR0nvpsO2JkujVy1aF80SrxW3XSOSvrNd1XLn6G2ymWTnVJU/pg0S9Pk003rpLhVXUfUVwrJj82EiTZ7+zX4ZbRWAgyjfMSSJNHHyytpX2LkeIkpswhQKpXo/P3za12s7G3zLG8jpylgJrrBLCsZqGEMy3tHsERIdO+ZdMSXsqgi1kdlX3 35a80nKD P5zz7eJZ/LCv0MU8HS6TY7FZmDRbtLSqQGtpu+iZDBexaGATlN+TKmZUBvGvnje7qFfxntr2tQBGTD7zwskYkbOU1sd3rLedKBHFR+P567bChgYo5L2Wp8bR8uuWMtViXreG2vO/SYTxhyGwXEUnJneDvpP8WRdxm9K4FQpBjTZHEUxj5XVLlbS/iB3eEwED9Dy8apmojvw5Nj0pFZkazXSNKR8zKzjV73Aujvz30aniAt8qfHzb28njwTd8pX9z2kVkOqaV/ZKAWXqat1Pqd6Rj+he4ZRgr5CZXOK53JHji1hyG08W1wlIurBCw1CBh/WtrZdUfOevA//XjPdrhSXmeGm8pdkEUuFmh3IJwEXrQfwr71DW20+mWjFV70jJc8GOQGRyiyrUU/4vhCwIgk9DbrchD1XdN25ZVSDI5EAyJrUjFH0BPBGCSVq61HaGO8u2FJNM7teQURWCWdK3+DXs8XWpWvEpkRG1CrMAEzG0p3uFHCwajlNIYc+XEDS0XOzaAHEr20yxzP7eEu8cezFdPb/oiRGuRsZUo27br7cJlQqP8gakelBPpfR4Dd15YkKp2DKrQ9xOZ8ajE1ivJYi7VFRAQLCXQ0l1eW94V3NPh3+P2kOhaP6RY0if4VvF0FG0eiCK9ud6ziZknErc6q5WxkXFUi6O/cp49JUp1IdIDz4dTaDmqRyilaSX7/Q5iFcFfAx2c7/3eQyysDmaw+ZekiH6u4rZdgcqjpC3Ezu+Z7dBnnRXpP62HpeaRv4qyPoCBjQebS3UUd0b4= 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: set_task_reclaim_state() is currently defined in mm/vmscan.c above an #ifdef CONFIG_MEMCG block where cgroup_reclaim() is defined. We are about to add some more helpers that operate on reclaim_state, and will need to use cgroup_reclaim(). Move set_task_reclaim_state() after the #ifdef CONFIG_MEMCG block containing the definition of cgroup_reclaim() to keep helpers operating on reclaim_state together. Signed-off-by: Yosry Ahmed --- mm/vmscan.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9c1c5e8b24b8..fef7d1c0f82b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -188,18 +188,6 @@ struct scan_control { */ int vm_swappiness = 60; -static void set_task_reclaim_state(struct task_struct *task, - struct reclaim_state *rs) -{ - /* Check for an overwrite */ - WARN_ON_ONCE(rs && task->reclaim_state); - - /* Check for the nulling of an already-nulled member */ - WARN_ON_ONCE(!rs && !task->reclaim_state); - - task->reclaim_state = rs; -} - LIST_HEAD(shrinker_list); DECLARE_RWSEM(shrinker_rwsem); @@ -511,6 +499,18 @@ static bool writeback_throttling_sane(struct scan_control *sc) } #endif +static void set_task_reclaim_state(struct task_struct *task, + struct reclaim_state *rs) +{ + /* Check for an overwrite */ + WARN_ON_ONCE(rs && task->reclaim_state); + + /* Check for the nulling of an already-nulled member */ + WARN_ON_ONCE(!rs && !task->reclaim_state); + + task->reclaim_state = rs; +} + static long xchg_nr_deferred(struct shrinker *shrinker, struct shrink_control *sc) { From patchwork Thu Mar 9 09:31:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13167119 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 F3612C6FD1F for ; Thu, 9 Mar 2023 09:31:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F810280003; Thu, 9 Mar 2023 04:31:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A85D6B0078; Thu, 9 Mar 2023 04:31:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72C7E280003; Thu, 9 Mar 2023 04:31:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6500B6B0075 for ; Thu, 9 Mar 2023 04:31:34 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 348321404B9 for ; Thu, 9 Mar 2023 09:31:34 +0000 (UTC) X-FDA: 80548842108.14.A13E32B Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf28.hostedemail.com (Postfix) with ESMTP id 68548C0013 for ; Thu, 9 Mar 2023 09:31:32 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=BIspgDfg; spf=pass (imf28.hostedemail.com: domain of 3c6cJZAoKCBAE487Eqx2utw44w1u.s421y3AD-220Bqs0.47w@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3c6cJZAoKCBAE487Eqx2utw44w1u.s421y3AD-220Bqs0.47w@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678354292; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=h6SnRTgbJt8uctknxsPWdjBgy9HatQBYNy5scoYuFng=; b=CxJh3n2j1eAfrS26mT70phbvqHXUhlFKqT+dsvCylTHMWZY9f9GoMAoATW+gMrP1AN1M51 E2Jws5F2BZgkbzyhzUJT62G4F2ZOkBbtzfo43ppYpUNwRRPcA4Q3NiNOIvyyqFpTacWXPf fRdwcD3m7Gyzf8+hfILqNDlmwsp3WxY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=BIspgDfg; spf=pass (imf28.hostedemail.com: domain of 3c6cJZAoKCBAE487Eqx2utw44w1u.s421y3AD-220Bqs0.47w@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3c6cJZAoKCBAE487Eqx2utw44w1u.s421y3AD-220Bqs0.47w@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678354292; a=rsa-sha256; cv=none; b=wYzTSRYErNAYuBBWJwCZ94YW+VtWhBbIe/sWxId1cizEDtp0lnb9r+n2rbgrRdebRgcvq5 XpnFwhRCU1p8kqN8vLnFsbzBpCuOlxJeu/3TRRPKm7oC+j9AHaFGqrVLVEFLiNul4f6hcQ XDLrsmDNED3t9Bg8WDlK2NQH4u1rTQA= Received: by mail-pl1-f202.google.com with SMTP id bh9-20020a170902a98900b0019e506b80d0so826218plb.13 for ; Thu, 09 Mar 2023 01:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678354291; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=h6SnRTgbJt8uctknxsPWdjBgy9HatQBYNy5scoYuFng=; b=BIspgDfgpDn4bkLxtBabsOU9Uhv4DiqHmpsyEYFdYYQOsugC1O3FyPc6aDReE1SUAN 5uV0uFO+sQlWKI/40WV3HZDPsDyksERJrVxwFRis6lKh0WsNGujWmErL0jVg9DFJ7Sxd IuVjwB/VEOvIqca+ISasnf6kTvYtPtyS5xSUuEuv0nl1KwuTEi21GUVG3fYoJYL/P/IC HyKUQOiXj+7FJ83bqgaNXvvsRkza48cZcoJSntHuv6rgRw6VPmYf64OIgEh4BzpyXPFS xbI1nWERtwBhK1R2RwjpugpOVd7LTuQKHDFNUS6dv8MWFgB5hNM2IG1rMMNwqORxP1qi hAOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678354291; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h6SnRTgbJt8uctknxsPWdjBgy9HatQBYNy5scoYuFng=; b=rkc91QcqC0mvJPpYw1XwPmLD92xel8dN+npCdrO+zRSiYzN5lPUvsypRTH2XPP1TrH YFBDFGqVogE/HTuujRsXafg9b1i9hovAPrmdVXe++Gbq6QDYs6f3mLM7ZW6PZoOfu0Dh dCJmJc71E7i9nwe3MGuvwYAQaS6oD5mvZTViNKrvuSLANGknGBVA8+o5lVqlxEU+9Hyl SOwYffx1+j1fEtZwaXk1eR+s3RX5W+AATmdSC+d3ID6QHFa4v+O4cnNLK4yEDJIfcrcK Bbav2w9vBHYofoOHWMfbuWNbKVbzD1W6kG2p+Aar1k9I+DSDHtjf3PLG7IYb2aC4BDqQ tvZA== X-Gm-Message-State: AO0yUKWg7Cacne8DFqJckqXwO9g3U2dN8L8/qegrcOGkfcH0ZhRP2kk8 IcYcXE93lVTN5lPLPQa6v6I2xjHaSZOxAp+B X-Google-Smtp-Source: AK7set/xvyeflSxZY0dqmtHjFakw/c6fvI1rhtdCuvGq7DrJIicLLxLjDK/zNls11ytQyWAWIJilVYP0U74iRmT+ X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:ef8a:b0:19a:9434:af24 with SMTP id iz10-20020a170902ef8a00b0019a9434af24mr8176829plb.10.1678354291238; Thu, 09 Mar 2023 01:31:31 -0800 (PST) Date: Thu, 9 Mar 2023 09:31:08 +0000 In-Reply-To: <20230309093109.3039327-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230309093109.3039327-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230309093109.3039327-3-yosryahmed@google.com> Subject: [PATCH v2 2/3] mm: vmscan: refactor updating reclaimed pages in reclaim_state From: Yosry Ahmed To: Alexander Viro , "Darrick J. Wong" , Christoph Lameter , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Shakeel Butt , Michal Hocko , Yu Zhao Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 68548C0013 X-Stat-Signature: ba6tnggxs1cgtcc7137qhua41z8781u6 X-Rspam-User: X-HE-Tag: 1678354292-788470 X-HE-Meta: U2FsdGVkX18vLNLFWiaEyAOwUXlXDRwVx9w0FbMV5grsiUVtYdiqmXKJ8JpP8Y9GRTWCwm60NPFzZkMBD8TH2a7dUCNuepViH/uwvEKd1C6zz+Ix1SMsGWZpV5EBjCnM59RSpOxvOfI/fpihSjEBsdB4hsaRQj5nIDL/zIGuENZij9UKzOuAhTz7F0jTsh2Bql1dj0sEDlypiVs8yQ7kMl6S0REIE+p38kaxIZRNV4UJ2j1uznwJKM7dNIfC+96I71K45qAuA3DjpDWdxZrafGWqA6qqyioUzLz+aaK9EPYQIgIpLj3Ea4K6AZV7oi4+EXsfBaW7WBA3gDAbyoOapjS0yg+RHPnRHtarU9cGa6teJn2sauNIDQDU0kYg7Z2j7+j1YRSK6d0tXJf09j9FL+CR+ec34PQA6Nd0gtR1IID81kTeSp2iPfrkz6WrfQPONdBH+0L1AuIx4mXiFlbOu3d5JIIoNl2UXxYuE3LoAUE4WQoAOUQA6PJse6CgIQZTHILrIpIQ850DWtrbMqZGK5xobUFxkco7K2UudK0TXLunw+FbPzIao8qDWwV4T8GvgnDTzSo5L0EzOm71AuFTpHWwkPHuj6nzHOFG6bbGprdWkLetHn08lY4WkxJz6+YwU//d3eHupeUsKQoGTZ5/6iaiMHupMq/3V3z46hrvhov3eXsBxMNNS6Y+gECvMQCbw5drSLNChvWHKYhDi3KpiS4e8N+tqBereiM+pco2I1MQxW1voPayECGSmkeaOrvNayzfdCKntxNQTirafBEToHfaQaUjcgE0QapxybfaId6LP9p/2Vatb7AzUnbuLlcXkhm2pYAVTVdesouQd3t5C4T90yzIHNP4EfhTleTcO96lbBrBrBqegfRwW/GM2ZMZilGYsn1bWW1r/1fpaOBCAsDD2t8wiIQAmXMz0YRIMPciDlpIJIyJ9ci0tMpMUE3z8DayCJuR1tCg4y1cxNf B4G5Hs2g aSWH8iKnelnka5r6sqJIecTnHozlxQ9txJd24ItvgLZ2B6+1Pa80nnZtgEKDOmpnXVo67FN/J3OlRPOZy5k5o9BY0vBQ7yjiFYdpT/jQB6lIUVuQuigle7PNb3TtYTR70CqlNTeGw6e0RTqjiM7pCBV3uTF0M6UdDk9WjBOwg0YUnaNPP7ZfA3MPHd33Xk+FKAy9acm8nH+NwMNhKLs1SmQp/+tEpQTHBWeIAPQz94C4XXHZQfQQ2O3KIkdiaGZuF06BeHnOgGyiFXPSLmoNFgE7sm7AFIv+2KxsIFke/kYkVl6XtLSebaMrpVqkqqOjh2XtjMa/SZQkVQvBeIMkQuAhBI/0RWGbD9OehA6OOa+8E7uLHD9RK6O28A9TfECXJLnUMz9qpiKh0UO1dygLQrTz+XA2BEDbPSHHxclLTJDkhrachEkVRKnYElh51xMrUK5lPE4fEvyBrHIc+BOZA6bPB02xmkvTxF+pG2S3eerwF4NvOWZPPLYB36ZaS9nGOzVHZVriW+ECOuoEhu2JvCQq1u67YLv6Nmd+nG4YIbaf2x+0brBo3w5XBGTdNklYmnDT/4/NmorshjtBiYPeQcNET87tg5Jm/C3AaEIaL93W71DXhxAY/IBMO7UI3yRGveBM1soVXbAnK593BNRDJIGDWfKw7ADbVX3PlD5M1x+1TPwRykSWHle6zKZZMO4Jp2e12gGilLt8b53eqo9Yq2t82tpezWIb9ZhQOU0QHN4L55GaSOopdSDhpIHRpg7QxpEVeskQdaTSoiMQF7hl/sUMNQQ== 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: During reclaim, we keep track of pages reclaimed from other means than LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab, which we stash a pointer to in current task_struct. However, we keep track of more than just reclaimed slab pages through this. We also use it for clean file pages dropped through pruned inodes, and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add a helper function that wraps updating it through current, so that future changes to this logic are contained within mm/vmscan.c. Signed-off-by: Yosry Ahmed --- fs/inode.c | 3 +-- fs/xfs/xfs_buf.c | 3 +-- include/linux/swap.h | 5 ++++- mm/slab.c | 3 +-- mm/slob.c | 6 ++---- mm/slub.c | 5 ++--- mm/vmscan.c | 36 ++++++++++++++++++++++++++++++------ 7 files changed, 41 insertions(+), 20 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4558dc2f1355..e60fcc41faf1 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -864,8 +864,7 @@ static enum lru_status inode_lru_isolate(struct list_head *item, __count_vm_events(KSWAPD_INODESTEAL, reap); else __count_vm_events(PGINODESTEAL, reap); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += reap; + mm_account_reclaimed_pages(reap); } iput(inode); spin_lock(lru_lock); diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 54c774af6e1c..060079f1e966 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -286,8 +286,7 @@ xfs_buf_free_pages( if (bp->b_pages[i]) __free_page(bp->b_pages[i]); } - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += bp->b_page_count; + report_freed_pages(bp->b_page_count); if (bp->b_pages != bp->b_page_array) kmem_free(bp->b_pages); diff --git a/include/linux/swap.h b/include/linux/swap.h index 209a425739a9..589ea2731931 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -153,13 +153,16 @@ union swap_header { * memory reclaim */ struct reclaim_state { - unsigned long reclaimed_slab; + /* pages reclaimed outside of LRU-based reclaim */ + unsigned long reclaimed; #ifdef CONFIG_LRU_GEN /* per-thread mm walk data */ struct lru_gen_mm_walk *mm_walk; #endif }; +void mm_account_reclaimed_pages(unsigned long pages); + #ifdef __KERNEL__ struct address_space; diff --git a/mm/slab.c b/mm/slab.c index dabc2a671fc6..64bf1de817b2 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1392,8 +1392,7 @@ static void kmem_freepages(struct kmem_cache *cachep, struct slab *slab) smp_wmb(); __folio_clear_slab(folio); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += 1 << order; + mm_account_reclaimed_pages(1 << order); unaccount_slab(slab, order, cachep); __free_pages(&folio->page, order); } diff --git a/mm/slob.c b/mm/slob.c index fe567fcfa3a3..79cc8680c973 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -61,7 +61,7 @@ #include #include -#include /* struct reclaim_state */ +#include /* mm_account_reclaimed_pages() */ #include #include #include @@ -211,9 +211,7 @@ static void slob_free_pages(void *b, int order) { struct page *sp = virt_to_page(b); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += 1 << order; - + mm_account_reclaimed_pages(1 << order); mod_node_page_state(page_pgdat(sp), NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); __free_pages(sp, order); diff --git a/mm/slub.c b/mm/slub.c index 39327e98fce3..7aa30eef8235 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -11,7 +11,7 @@ */ #include -#include /* struct reclaim_state */ +#include /* mm_account_reclaimed_pages() */ #include #include #include @@ -2063,8 +2063,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab) /* Make the mapping reset visible before clearing the flag */ smp_wmb(); __folio_clear_slab(folio); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += pages; + mm_account_reclaimed_pages(pages); unaccount_slab(slab, order, s); __free_pages(&folio->page, order); } diff --git a/mm/vmscan.c b/mm/vmscan.c index fef7d1c0f82b..a3e38851b34a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -511,6 +511,34 @@ static void set_task_reclaim_state(struct task_struct *task, task->reclaim_state = rs; } +/* + * mm_account_reclaimed_pages(): account reclaimed pages outside of LRU-based + * reclaim + * @pages: number of pages reclaimed + * + * If the current process is undergoing a reclaim operation, increment the + * number of reclaimed pages by @pages. + */ +void mm_account_reclaimed_pages(unsigned long pages) +{ + if (current->reclaim_state) + current->reclaim_state->reclaimed += pages; +} +EXPORT_SYMBOL(mm_account_reclaimed_pages); + +/* + * flush_reclaim_state(): add pages reclaimed outside of LRU-based reclaim to + * scan_control->nr_reclaimed. + */ +static void flush_reclaim_state(struct scan_control *sc, + struct reclaim_state *rs) +{ + if (rs) { + sc->nr_reclaimed += rs->reclaimed; + rs->reclaimed = 0; + } +} + static long xchg_nr_deferred(struct shrinker *shrinker, struct shrink_control *sc) { @@ -5346,8 +5374,7 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) vmpressure(sc->gfp_mask, memcg, false, sc->nr_scanned - scanned, sc->nr_reclaimed - reclaimed); - sc->nr_reclaimed += current->reclaim_state->reclaimed_slab; - current->reclaim_state->reclaimed_slab = 0; + flush_reclaim_state(sc, current->reclaim_state); return success ? MEMCG_LRU_YOUNG : 0; } @@ -6472,10 +6499,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) shrink_node_memcgs(pgdat, sc); - if (reclaim_state) { - sc->nr_reclaimed += reclaim_state->reclaimed_slab; - reclaim_state->reclaimed_slab = 0; - } + flush_reclaim_state(sc, reclaim_state); /* Record the subtree's reclaim efficiency */ if (!sc->proactive) From patchwork Thu Mar 9 09:31:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13167120 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 D0C0CC6FD1F for ; Thu, 9 Mar 2023 09:31:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66198280004; Thu, 9 Mar 2023 04:31:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 610526B0078; Thu, 9 Mar 2023 04:31:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D81B280004; Thu, 9 Mar 2023 04:31:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3F0E36B0075 for ; Thu, 9 Mar 2023 04:31:39 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 085BCA0652 for ; Thu, 9 Mar 2023 09:31:39 +0000 (UTC) X-FDA: 80548842318.12.6939E7A Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf25.hostedemail.com (Postfix) with ESMTP id 517D8A0015 for ; Thu, 9 Mar 2023 09:31:36 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ze5OIdzu; spf=pass (imf25.hostedemail.com: domain of 3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678354296; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LEwBMGSn5GpbGlanBqXFsfdHu3Z53NaeJ1a3nMwnQiU=; b=kRu2Cj2Iduke9VWWL3Ix3OHdHbFPIzLMnbSkgl+U1pFyIAZX4ofH23RKL2xa5pQVkhTcoS s3L+/8BVXSUBpa0J7sMqdKyjTPoAGaXLhZFpB7fZ6kWbrP2xz0iixXjSykqUbw3bCndv6i nQSDwyRekwxKQG7rZUYvYaVKwWtJZQo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ze5OIdzu; spf=pass (imf25.hostedemail.com: domain of 3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3d6cJZAoKCBQI8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678354296; a=rsa-sha256; cv=none; b=bqyoZtMyuV7J5Skd651ouFiNxseQC+uZ7yhjAifW+qU4ZoRg0oyAH/C6CRm9UfLpL+JxeI 9noVY2LbMnLbROVcwlufmygsGRzwh7ZZNMwCoAXGIdcRyC0u1obE6NmrqbWBzwtU0cD01L 0n8dAsPPTG11ffT5fve3DfrX6inJV94= Received: by mail-pl1-f201.google.com with SMTP id s15-20020a170902ea0f00b0019d0c7a83dfso821415plg.14 for ; Thu, 09 Mar 2023 01:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678354295; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LEwBMGSn5GpbGlanBqXFsfdHu3Z53NaeJ1a3nMwnQiU=; b=Ze5OIdzu8ujFo9cbq83YqFk9GJOpYr3a3BQKfOSfr4rWI6Yo1wqOYG0VZvkRQl/DgU ONZDb780V2AJLPqQWE3i1IZDOj2DrlnYx2p9SESApSRJk73I5fI+TzBG7cY4phGhOfvE fsxBi+Mbo+Sti9UuMrxl9QnG0QjPUVEa7+s1cz+Q3wYagCiAWB2+bxT6WbOhwW63YCyL vx4QV8MkTkeQi+EJ1ehIcECB6ITq43CvVn8IyyqwmqR4ySJXDiat0u00fzVgzef7Kjx0 9ui6RevSQ/etQzip+tetVSB6hNPcbI8D0n9SoMlj9xGPz0n+yHL+qWibozRsuDEXX+zi /5CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678354295; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LEwBMGSn5GpbGlanBqXFsfdHu3Z53NaeJ1a3nMwnQiU=; b=EGs+S0pwpyvdmzu4tlS5F6SRgflL5TPhjwfnUKbGsG28tw40b9hoUA5SuW08gra+fp Zq6zWTo0ZCK4KrGo3da+VHfBkKkLyOSfnd7SjyCGMUpsgPvdD4TYrnsGWp653JKh5biB hx3v9p1nPaLpIL30qHTfPku34g/3XZXPgdmxijk+c/kHNlBmGPzAQgUgpLtOyQcYauDN d2deCvW0JCWxnuhVd7SEAcnY9B2KVkce5x2UVx/00/xgoNcykRnQbIeFOLpFyXaniBo5 3jgit4m/B4cDA18IgIYMkMFoOQPM5mn7vTy2SEBspYXcmEhICD/waubKAhs58eapu9eN 36SA== X-Gm-Message-State: AO0yUKWA0JlNAWtYBNpAHzlX6NW+3JxUg5Z9daBKcw9V++25snJIg9VM eU31GjrskvIX1+tcjTTTUBHcSUiNOTvDe5kJ X-Google-Smtp-Source: AK7set/0zSElUk4SV6Jx9e5eK8m600vzb0RCF1MUNHWJepBbU4SjCTMuv6lVZNxTeTFxx/o7bLiMKSNeOfppeLHP X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a63:2953:0:b0:502:ecb9:4f23 with SMTP id bu19-20020a632953000000b00502ecb94f23mr7361890pgb.5.1678354295295; Thu, 09 Mar 2023 01:31:35 -0800 (PST) Date: Thu, 9 Mar 2023 09:31:09 +0000 In-Reply-To: <20230309093109.3039327-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230309093109.3039327-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230309093109.3039327-4-yosryahmed@google.com> Subject: [PATCH v2 3/3] mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim From: Yosry Ahmed To: Alexander Viro , "Darrick J. Wong" , Christoph Lameter , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Shakeel Butt , Michal Hocko , Yu Zhao Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 517D8A0015 X-Stat-Signature: un4jc8i4sjnbux3dbw1biw6hsetcas9p X-HE-Tag: 1678354296-872574 X-HE-Meta: U2FsdGVkX1/rn7lg8sL3fHe+I4+WKjNzqJmitSSbntTINzp3dh5+rLTLY1G6PTx5E0Qf2fMawbqskzFB98P0UgPaXz9jq6mcR+PuNFNl747y1VZ5Nmky2rLnkibNlpH5DOPTFTJ7fy7RkW7KlLWB8NJw6OFZNRL1oLbEJQ75tzOxhvvqQTvlUuqtgLPyKzFhidUo5xWUgffqUqXoYlYeHO6yGa95HXip91BiI7monZ9X8f7RL25o2Vr35o/Qi1Qf5K3KZt7qxzsGsPYkZqYnjABUj5TX4/pPeo2l/9M7bwAL4NJWg4Vcy+hhMf9aZwhOIGG4Y8L5XdjQxevkwn+RV/b39ahB4h0KtUR61OmJClsuyd7W3dY/r+QRsZ/bvH1Akr4JwXb8Y0lamSd+JIji7b1Ufu4P2WtskJY5bq8F9yE2zZIYErbbaZxTw0xtrGKB/nP8o5Y6jdLNh5QXNzjKAcNGLjXfeQKPSuNYwz55q6ajwDGFHwX+yMole/qCekAlCiPyy32IXDvj6U7axFZg7umTMbGafI5/X4mD8j1tmWe42YJo6hVrucUjQJe/fdO8rUOfur2VEr7Ri/5gMGj1oeGM+kb2AgDxnkTn2tCdfxZcQ1hLqMGBuz6d5a1CsAJ89eMffbwqz79yFFzSwl1/xYbhpQ6XfCs48G/9DXuFKxknqCd6Y5DRsBurzUZtwMyoBxrH83HAtImyP26mF2BX/T1XjTwHqxowYfadNQ+V00SFpfNbOogwQnKFtciLvS/uJciQOuMHTZ4DqrMKbXkgXYdmn3M5/r1nvtwxAYhkTJRvW3cXjAjgM5lb4kYawrV6eMl9TKCYmrjA85/bLj7vMolwoC9veTVsYR7T1K9mo6s5aHVjdNUfPKwK/qOcDzmlwwP0p8v1/HKfIiIVo4MwUyB+bbo1nYN4qAJOm9lxlg5Tf0NmLp345y/yieKZf3tF9/T4Z9qQOIZwavbD9DU 4vOzXLxK dqZFtdUBlFyXj4XjFf3d/WG8Ujt5AxuBaBJocypBcllCcs/atiJvV0cTioqi/+hJmStOYQRbeQpsbeOEuOjIYVQvHnDsCjkXNGAC8OBOh5IYD1yah4sJ2McWe4BuwbAo3wudT48Tu9qnTpWDjQ3HBIyvkDZEE5nTbL3gQRfmqTyxMNzK6YiCa8tUudEedpG90VW0+Er8CLjOKhyohp+0v4yuwGWsffaIGgp+M7pNuX4uxj4A3R8B+nrTe4zUOVV7RkwpTSRTyZWFjCyS2dc9KNM9qx2DTGbPcq3KruTTkpflbN23PrNaWLeZpBQ14MET2Xf1o8B1X0xMb79r5/ApqfsqEZXarTC3h1ld38Y8Gjg4I+46J7maBOfMVW0YS5CnJ5ujTYz2WD33gCBrw+hB5ZbH4d5Xpr6iGjGr/e1eaxaNwCaYcE83LElE44rjdeX2rcbdkrejMKp7E8JffwBPD8j2hrpcbxZy/nRdDNs5qoYRMGZ1AUr7Wo7oA6edsl/AkpC/p2QTdTtDMew9P9O5/+u20s8UqrM9nKaEa07+gtqFib+HW+Ky/L3RbZ0wlYD2qrtZfT0CBId4UEcqS3/y6XX6kEWZS1NL4ZM6YBNcIPf8EQy2EhJfniDwZWHov8Aa2pN2fN+An1Og1S9b/ZgdSrdLPKlPfE2PDkN4eKrVRmmn3HW5MDodbS3GI2qKRgelkBgCQi+mHM27O/PU7yJCWp1tMjHPEL5YgmyqO 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: We keep track of different types of reclaimed pages through reclaim_state->reclaimed, and we add them to the reported number of reclaimed pages. For non-memcg reclaim, this makes sense. For memcg reclaim, we have no clue if those pages are charged to the memcg under reclaim. Slab pages are shared by different memcgs, so a freed slab page may have only been partially charged to the memcg under reclaim. The same goes for clean file pages from pruned inodes (on highmem systems) or xfs buffer pages, there is no simple way to currently link them to the memcg under reclaim. Stop reporting those freed pages as reclaimed pages during memcg reclaim. This should make the return value of writing to memory.reclaim, and may help reduce unnecessary reclaim retries during memcg charging. Generally, this should make the return value of try_to_free_mem_cgroup_pages() more accurate. In some limited cases (e.g. freed a slab page that was mostly charged to the memcg under reclaim), the return value of try_to_free_mem_cgroup_pages() can be underestimated, but this should be fine. The freed pages will be uncharged anyway, and we can charge the memcg the next time around as we usually do memcg reclaim in a retry loop. Signed-off-by: Yosry Ahmed --- mm/vmscan.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a3e38851b34a..bf9d8e175e92 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -533,7 +533,35 @@ EXPORT_SYMBOL(mm_account_reclaimed_pages); static void flush_reclaim_state(struct scan_control *sc, struct reclaim_state *rs) { - if (rs) { + /* + * Currently, reclaim_state->reclaimed includes three types of pages + * freed outside of vmscan: + * (1) Slab pages. + * (2) Clean file pages from pruned inodes. + * (3) XFS freed buffer pages. + * + * For all of these cases, we have no way of finding out whether these + * pages were related to the memcg under reclaim. For example, a freed + * slab page could have had only a single object charged to the memcg + * under reclaim. Also, populated inodes are not on shrinker LRUs + * anymore except on highmem systems. + * + * Instead of over-reporting the reclaimed pages in a memcg reclaim, + * only count such pages in system-wide reclaim. This prevents + * unnecessary retries during memcg charging and false positive from + * proactive reclaim (memory.reclaim). + * + * For uncommon cases were the freed pages were actually significantly + * charged to the memcg under reclaim, and we end up under-reporting, it + * should be fine. The freed pages will be uncharged anyway, even if + * they are not reported properly, and we will be able to make forward + * progress in charging (which is usually in a retry loop). + * + * We can go one step further, and report the uncharged objcg pages in + * memcg reclaim, to make reporting more accurate and reduce + * under-reporting, but it's probably not worth the complexity for now. + */ + if (rs && !cgroup_reclaim(sc)) { sc->nr_reclaimed += rs->reclaimed; rs->reclaimed = 0; }