From patchwork Fri Mar 31 07:08:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13195316 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 5F1D4C77B6D for ; Fri, 31 Mar 2023 07:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B28026B0075; Fri, 31 Mar 2023 03:08:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A89766B0078; Fri, 31 Mar 2023 03:08:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 903D66B007D; Fri, 31 Mar 2023 03:08:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 827CF6B0075 for ; Fri, 31 Mar 2023 03:08:26 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4D366A0BB2 for ; Fri, 31 Mar 2023 07:08:26 +0000 (UTC) X-FDA: 80628315012.05.01C15BB Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf27.hostedemail.com (Postfix) with ESMTP id 8E63F4001A for ; Fri, 31 Mar 2023 07:08:24 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=k4Nyjagi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 354YmZAoKCLYukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=354YmZAoKCLYukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680246504; 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=B2pWBeS3GCf3oNfr31dlSqb/2UGMYxzBqyAxEtHKHDE=; b=ka8Cj7r00wrAe/fx0vsRqBeKS74cxxWnIqgM7oQ5uJIUcBy+fU3HDnZKORXOkgVH8hsTd5 hD/tAMU7b+3G1RCYOACa6rObfwJq8NvcB4jX2hjdr5J6WDVnupi1ZY5e0TwEh95YwKb35a lksUS7fLYsULycZuMnELhwmRlXYR2to= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=k4Nyjagi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 354YmZAoKCLYukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=354YmZAoKCLYukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680246504; a=rsa-sha256; cv=none; b=ZYIT93L+7U2Hi1AaBexLICFz4PimNHF0vM5vAEjLHUuAn0Ui4pgozsJj+73WAX62Tkz+y7 il1qYUHbm6GO/oGV3G/6KYBNL5c/a0uEizdrlqtMZ1fR658jQnxcGQ/LdtneqocfKolNXM pRW7lHFSMqO9iuyqYaAk+IbvyN2+JmY= Received: by mail-pf1-f202.google.com with SMTP id t67-20020a628146000000b0062d6d838243so7628461pfd.21 for ; Fri, 31 Mar 2023 00:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680246503; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=B2pWBeS3GCf3oNfr31dlSqb/2UGMYxzBqyAxEtHKHDE=; b=k4NyjagiGkCklbJVsqIMtonbdCMcTupGTS8hoHaC0gv8FOGuM+Bs5S57llv7e0EaSv Cdr8aYY+xrBbCtFlM6wcVGLHr43sIVgLRjo6N9VGVd6RPJWbRRFixWbs+ilYQFqKNFaX XmIjhQjyQd9NZkc3tv9rRK0BApt1ddgQG5Hmi7auJiptlkO709XlGaRHtR6d3pQ9Avj3 N34PvmS9EWNDok32raE4oK5g8hggDeU3zDAViHIjtdEdByWnmMFFSaEjcfkCBkO01CnD 9fsOaBbQNmSszl6BuqVSwa5jOVOxj6sT1Ok05l7fpvj5jCSBxdjsIIURvPSg0lRWYZMb t+xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680246503; 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=B2pWBeS3GCf3oNfr31dlSqb/2UGMYxzBqyAxEtHKHDE=; b=wWR7NcSiJeMkycPwFbjZk1YXo6je6kTtw9DxtmUPsn86ykNptVnU6Yw1vqXZPQjvQX jOEEFstL1j8JFdUdIMqf7PC/ChL8jFPCkY4ziJUjifRdw615BsugQLsSq8A/B2fi/O89 1vdc7mmApxiVIJvG3H2P7rotZE6EaTCyISQfoPhCX0XajZerj29kY5rAyECy0UceX3c/ o9d1q/MHuhc2AA/fQ5zBYtF7kZQUaOMEsjx4AA0rd/0su+igI2DN3V1nwZbtTwxAtmpk WtwBoG+t6V3LscFTr7ruexyxblzN6KrXlQDr6aHnLIu30M+ZlTJ3ba+UWnxeE/pLp06P POHA== X-Gm-Message-State: AAQBX9csx+rm/SIo5oJ2T7oP3xd6BH0U3r0lRIgsJTqUmAIazWu97wr3 Y8Hl914tbjpDMHeK/uqzhvd9MnwI9PkmF1he X-Google-Smtp-Source: AKy350bRvjgd15ALJuao0xdVFVls0BdarK49AoD9W3kOxaJ3kd852in4QhALpf6ZkL2aYK5+VCe3mI8yGkJLtLkv X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:9b87:b0:1a2:1c7:1c1b with SMTP id y7-20020a1709029b8700b001a201c71c1bmr8812952plp.5.1680246503444; Fri, 31 Mar 2023 00:08:23 -0700 (PDT) Date: Fri, 31 Mar 2023 07:08:16 +0000 In-Reply-To: <20230331070818.2792558-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230331070818.2792558-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331070818.2792558-2-yosryahmed@google.com> Subject: [PATCH v3 1/3] mm: vmscan: move set_task_reclaim_state() after cgroup_reclaim() From: Yosry Ahmed To: Andrew Morton , 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 , Dave Chinner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Queue-Id: 8E63F4001A X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: x8crz6pu468dgabnf1h7r3xodchwfd4y X-HE-Tag: 1680246504-489859 X-HE-Meta: U2FsdGVkX19aJceH0aWriaACqLnKFSSZUlNQsuX28/FVF44TrFRKibcHbeuZbSQQOdt57MoY2PDjRDRSHzMJMdy8DK75QyFCyt5ZHdTGjG3GS/acxKfnEWDKFd90tJZo2KEqops2W3lmqhkgJ62SeSKFUqiCWbRmCuBZ6yc7qH/bBA9IVLXDoDYnGtd2szOiRJUeYyzDaNc+9QAd8E1dgfzZ3YeZPAoNvWw7LCVaGBasQb25xdmgJkqLx5NF+goLw9o3a48mbsCAjHduJgH1dgzV2Mu5XLaR0PeKLzHzBZ8ga0V2aP7dWvepHrcC6qL34V9PkvNBsL5kvh43DoanmR551p1nn4LB9G4gde0yYSL56TFC9RfJ0JbefOl1+3Jp8N+OgBL0Nqcx8qTn2JapvOktwd8rq9Rwkl3jRz3GLZW2PEPruIz8fKcBbl2tZNwlEJ6MP10acuFDkG7DKcEktCLLsFaEuPo/ZfRJOdTTyRVcsfnFPI+cRJYCXDupKlzu4aqx2X/Q9O4/SI4B21K4XHT0HdheT0e7mXkew1EZk3lhPyKoS0BuJ+mpdRIPdPh8qESzBjQpoGs5DyUl7MNGXeLVqvwACnEyKIeyCf1Sjqze6dFENDnY2oCIq1gt0Ev0m9ijkRORJ9dbWhXxmJsx6388MgWMriSRpLfmOY3TWFwgH6Smiwpcar1aR9AEBZu0hh8qQvl0vzVchjHqPWhvgaY0U0x82dZ/fFHINXeV1qrdfVkLfM19Dobi0cLBZ7DSyQFFif2xLgG0MtO6S3DgwizMcy/aJFPxbb+i6PfF2SNdr1N7KW3+XVbZw9LGnmRJThIfYTkNt8g/ugt1cZwCRmgO+9tbYsc1apjZ1P0kceSbxDC83wC97eyXPaIAGU9SoG9sVIgfzhBaVkewII9zJvQuQEoo1juhNxt+NDqVktRCssPEa/LduoocXeiQYqOUx/S7Gxrkxskm6Lplvrv m3R9UxS5 +yJonvnZjl9x3Kv7LwqVsQ8/Vi7NA3aX58w8WylajkXGExJebwab5IvFqUO79RKucrBxgH/FScRN0TgLagDl7XdhgvFAGl9B69KBzcGHY9MY9Mb0LXmK0PCY2uFbKlsjLr27GsjbTsSAXzKxrCWEBviq6OQYkriRwyOi4Ihvb/9wZ+WWQiWiPsPT7Q+iDDhbHpd6ooKp+0LTElTEItN6n1uXRlMczx03BAvO9Bg1HjC3B6r/j63GaAsP7QstoXq9lV91t0BXixBjCoGBIOXH2WZvYul76R0LtmiRPLwBiIhADmu7gp1IngdIKMWbE4zY4oUoAQ5ErGxeeCfoFpAERHwT7CYEwjT5dPIxnEC1Hhv31BR4rtoIVIwMsuUs4m7fLB6ppmLRvfPaUk3Qe0R5RCThHKodxXyT3LBSV5zavYbqTdlh4R1Abh0Nl7A3O1Zq6HHSGBbKjO3X4eioQn6fMjwLKGVcWW/KUtDqXNYNdWIcxur1bcWcYta7CpE8BSAng4Xuy1BiCNcK6XkkUQcUdSLSilLoyKqvVxllTtlNUif6Glr19iVLmRuTnhtks2LEocr7Y/HOJmqiz0/ozhU16ewbPdcdZSQvU8OkPb9FALHspgsLq6AEl8GDru56WegZHxiiDygvPQEHTqJYVeE8OlnzbPp/XRq1/4EexyZCdIgUZxpTki7HFJgFm3taaLZ93rXHw26EfwlE8oE3P5Zcj0PzoU7X9buWhFztQxiIBocxdFnu6+n3vY/80WftIeBueucwFwM4+q4OJHMA= 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 9c1c5e8b24b8f..fef7d1c0f82b2 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 Fri Mar 31 07:08:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13195317 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 CBD49C76196 for ; Fri, 31 Mar 2023 07:08:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 583006B0078; Fri, 31 Mar 2023 03:08:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 534376B007D; Fri, 31 Mar 2023 03:08:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35E536B007E; Fri, 31 Mar 2023 03:08:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 26D876B0078 for ; Fri, 31 Mar 2023 03:08:28 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 01D981403EC for ; Fri, 31 Mar 2023 07:08:27 +0000 (UTC) X-FDA: 80628315096.26.1D03429 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 35854A0007 for ; Fri, 31 Mar 2023 07:08:26 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Qvh1jjxM; spf=pass (imf15.hostedemail.com: domain of 36YYmZAoKCLgwmqpwYfkcbemmejc.amkjglsv-kkitYai.mpe@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=36YYmZAoKCLgwmqpwYfkcbemmejc.amkjglsv-kkitYai.mpe@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=1680246506; 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=EVZwB8yF2h7dd4fmRqNpsJbSVI4UBUJ0tNYnQMZkjKk=; b=qaJqgUdODS4S6cyp3sqbp+aaLmhEMWhnHm/v7ODWgqTjV2ZfF+kIAFj2QlNnQjFT7IZ43m kQpcGVLVZvbOjinV7T1wM5LdrOdzyepmW+VyoNHwSNWki5DRUQnzfYLIMS1F7J9IpyDw/f k47GSLOcYeKzrlQhH7DzufJy1Jn+Q5Q= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Qvh1jjxM; spf=pass (imf15.hostedemail.com: domain of 36YYmZAoKCLgwmqpwYfkcbemmejc.amkjglsv-kkitYai.mpe@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=36YYmZAoKCLgwmqpwYfkcbemmejc.amkjglsv-kkitYai.mpe@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680246506; a=rsa-sha256; cv=none; b=4P21oTsvTXCg0d1aJ1z8xQDvqjdRWCrfVY/KMwxzE1O691MEj2N+I8SadNiNsZofVTMkrQ 379uAFS82atjvqE6/AIk5TiKOf+pMuYwZg/VWFO4gC6pRWBGcqd+mqoLLbwwKQ4XQE7mda Co9KwUH1PZQTchUQjGhuLmjxn9RcATo= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5463f2d3223so38248387b3.14 for ; Fri, 31 Mar 2023 00:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680246505; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EVZwB8yF2h7dd4fmRqNpsJbSVI4UBUJ0tNYnQMZkjKk=; b=Qvh1jjxMNNvin3fUDDF8N+zZ8dqqA9V78pIPC9J4eiet7qDkXN9KmmYYGJUPeJYaHs MKLH6pNXsD05xRQcVpFEEfGwpCvmj99CxoROc64tCepIXuXgVcLXkcyqrZDmsVbfc/un 7sfS8XWr9MjceXgEsPIOeI1S+8cmvT09eKc373lVeEeUsWXJ702WCHk+gyMUxa0d13mH DpL6cgiWqKJVgtXn1VwPDG4acoSGVNKXwkCh7EQWTotbaEfnfpggZPHjxNETB9GJ4f25 tJPNvYQSCiMrvuPAqeNaMz0m/mU2f6x/6ZvXVSUmCM0sHbOErJEOuuXNLHg8qMP+5e4a yxRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680246505; 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=EVZwB8yF2h7dd4fmRqNpsJbSVI4UBUJ0tNYnQMZkjKk=; b=NuRBTTA3zXEAhm8DE0FWPp74REG1keDyhviRG3Oh9UigrZR3DaN8N8uxXYM/FyZilw ypywb1AwjdXVY294ylkm60TOL3aTrue8NsDLogTsXADS1RMAgb51Wh3aWdxNzieR/Vr0 fKboIi04+OMWGQoJmSoXsyiobN82IlFOT7vLDJYYMbWeHx0jfcqr6B7HfcbQF8zU3Qdr WjNTNUdDsLg+2bJgPzUtJPUd69EvM6KKJKdWX/9j3PF/JTtJcvwzzsO4N4Y/NzBQMGdo h+pO0xIRp3eTKV9dtOhbnBAVP1Yyyip5MX/PS5EUFNuq0Sas1C8cQRLo3p1I+ZIp2fhc JEYw== X-Gm-Message-State: AAQBX9eHPCkk+Mm24fNhJdvZy0rC1Rmp50CSA8JRsWxXQvWbQJzLEOBX 38Eh2/zmDN+i+vCMnq3oIzQtF/bek0flzoja X-Google-Smtp-Source: AKy350acSxAChLfmqKO9826eoY8acajFCu3SAUOtEMLxv1trgvamSCxttKg1ftNmirCAT6DUp5LYAYXEe4TbOfrd X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:188f:b0:b78:bced:2e3d with SMTP id cj15-20020a056902188f00b00b78bced2e3dmr15320634ybb.3.1680246505338; Fri, 31 Mar 2023 00:08:25 -0700 (PDT) Date: Fri, 31 Mar 2023 07:08:17 +0000 In-Reply-To: <20230331070818.2792558-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230331070818.2792558-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331070818.2792558-3-yosryahmed@google.com> Subject: [PATCH v3 2/3] mm: vmscan: refactor updating reclaimed pages in reclaim_state From: Yosry Ahmed To: Andrew Morton , 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 , Dave Chinner 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: 35854A0007 X-Stat-Signature: p9jdojzo6w9qnkxn1umpasjmts7n4ypb X-HE-Tag: 1680246506-998104 X-HE-Meta: U2FsdGVkX1+Z5MUZrF1Bs0UoqboA4CKYfyzVsqIRASU+UkNnjdj+KRXTWuu17GOchTgQhzlblc0u5fH06mY92ZvZnY1C9imDdhGHm+dxI13KoOc4LUbVO1fgFkDZI04+9/09H1OB/ATqQgdm4YA5b5idEAMKqEWWZZS1NheLqnAE5Sq37UB7MLKqHdMoQP5mRMD1FyHtyzx0PC6BIQaL1K/MPFpVjG7c+rHkdLXO+4GCs12KN804jznUHpubaKtDeWBonmj5S602nKQqbCJWfm0ZL/ROprxqMbbFZDcPvPjl05KLDNmoXsHCLkKSaLq8Ut/hYrCHz+0txFodK8gTE8ljVn03CzZFa7CAhaRnTOyVYIlBHK8PJWzxE8OIoK21ypLfAqQD6oiEpraLwl1GVKiilh7v3peqaQ/6OWLkYztv0CXJqok17xY2P+qThcM6CMkp7Ji1nuHGhc+sJeZhTB7jVDtRATiyejaYw5GigwAzf6RQG1Z17UK7M7MOXn5NhDjh6mZk0Gnj5uxQOu6xoLQncRdkk6K9A/FnRNeh+3njNXu9t149ysagXnEsKoTUAsTvSZ0/BD7iNc8HxJhdC6xWrQCact59BS99MlEoN33kaLsVJElY9ZrdH8K/sO0DvQOZWdBaGfMtBsofsPF5jtI4JIV8OMWhm/Qk83dHyL/IqIiUM1onrIps3tiJl+NcTyYUM/Pt8HkCnMrFQEiSVWIB+2iAUl+yJE8JFoE4pX1mdVWy01NnWgR0I7xbXjzq9tjbuJ9VYlmXo309SuAvqTzGuqJE3pje34BcvqCX10zlGzCwcfVx8Y8Qfuh3WE59ZzArYvaKoSVsfnNQFYt+31PrQbHHL9goLh1h6PETTzLB5U2TdazfPkroIpxUHfDqeZ9dtSMUHLNhw65+g85PXZT2/SU2ltnYfQUzz5uGnbqBZLeolME2cT235HfzZzhy38vlv3kTtgHuzaxsTGw dx4nJvP2 0JYmOm6fhGF4R1b+a5CNe7PLB5VnddYVJUt38z6VUAU7Nky0tcbmFYnmni5JIUL7ZNWKviLXRBW37oBWP9R2c5UtOOe98eZb/cdubfZZ2MLmtUUhSTauRhvn+iWIhyp7wFnOilAoU5abAxk4A6730/r1Tbyn/FE32+p1ZY0CPQ+9b8V52T2NQf/7Jw7Gpjt53o6/THsZiby+08sHP/gXnmGubTv+ilFCV1OtkPwKW7Iu1TwARzOE4nPkKloM5LQUGKgTrjLOv1SbDhC4Da5t62QlGwqWhDgX7CiN+rEU49BIIYMIff89KE0EIbKLkls8mfFisiA4gxY0Qzn5OLYp9diQmk61Bs0qc8Rf8g0BNlI/U05pShwwF4dyQm8j+vAdU3qW94sHlW44/fed+s0SvsZQ7IFZcMnYtYBoNuJF51e1f93JyzW/FK2nxn0Jws+oyrp0B4qZp6ejIU+34hZgGMLWVvvNP2N5yU0/5K8ScCWlYhRtLWQyLv8/yQ+jlNQaihI3WcXNXXxeqV17az1N62N0/zV0o0nEJb4Vh+FMxs9HdwG0ZanOMA8WGJpISxcRXJbKIxYfKC92qciWMBoMmpUr8Cy/ehKnTbCBCUGiItdrz26ojfT3QMiihdUXov1LnUXFrXaxZsl1Q20SMOKD//9+2xBbmgqC1RsoINkWXHF+kn0/hvZt6TEewlxCg4vF6WnjniDeOQPXADfaJlNnGtxOWnp+4RnagD3NAEdDWNPHg0rpJ7h5OjS4Yoy4tUas2qzNjyoyDBbjQX6m1shHlw/GT8Q== 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 4558dc2f13557..e60fcc41faf17 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 54c774af6e1c6..15d1e5a7c2d34 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; + mm_account_reclaimed_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 209a425739a9f..589ea2731931f 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 dabc2a671fc6f..64bf1de817b24 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 fe567fcfa3a39..79cc8680c973c 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 39327e98fce34..7aa30eef82350 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 fef7d1c0f82b2..a3e38851b34ac 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 Fri Mar 31 07:08:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13195318 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 7CE61C77B62 for ; Fri, 31 Mar 2023 07:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13D9E6B007D; Fri, 31 Mar 2023 03:08:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ED926B007E; Fri, 31 Mar 2023 03:08:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E35F36B0080; Fri, 31 Mar 2023 03:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C1B1D6B007D for ; Fri, 31 Mar 2023 03:08:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8B7ED803AE for ; Fri, 31 Mar 2023 07:08:29 +0000 (UTC) X-FDA: 80628315138.13.1FB5EC7 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf13.hostedemail.com (Postfix) with ESMTP id A802C2000E for ; Fri, 31 Mar 2023 07:08:27 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I416KE3j; spf=pass (imf13.hostedemail.com: domain of 36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@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=1680246507; 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=h76ftpfDeW349+865+C5AwRuwTE+LoTxu1YkhFCOpyA=; b=R7vIK+lMnzUb0AFylqbH9EaRQ7+NDbJMGv2vfN6hs1AeLaMQ65dQBeBD+/+su85iKgWjm8 3VBCT1CuN3hbi3u+6rjT2lyj+A/4zZ4Ga6U96fYtoNWAREcpBTsIcf0kdauyofQ0WLcpT5 2irsps1csgqIXmYyUMLGfbfJNF67QEM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I416KE3j; spf=pass (imf13.hostedemail.com: domain of 36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=36oYmZAoKCLkxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680246507; a=rsa-sha256; cv=none; b=wpG4y7wlpN4rQ+q7oGNIxn5Zu7/5RUoA96MxM0Y/wwu272wQUKadalUzizVtwt3mApwWMW Y0AB8IO5ulQme8wV+CBtVNzceV8NBbL2GZ/aM3YpSOiN0qb4laiN9J1guz4kQPmExLqFqb mcvZGDv4jHHQxZVAhpEjRHLFEVG2HbQ= Received: by mail-yb1-f201.google.com with SMTP id i11-20020a256d0b000000b0086349255277so21216205ybc.8 for ; Fri, 31 Mar 2023 00:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680246507; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=h76ftpfDeW349+865+C5AwRuwTE+LoTxu1YkhFCOpyA=; b=I416KE3jHWRA3QMCGUkW1ivXoY9bfwY9Wzs6ajryoP118g2lYRPUBdBs95KIolJuD5 Ethf/48kB/t99e0lZyDxt6Gzswbs6SgDsOW6Io3pxcCrt46SeVq6PdqDGwpRXRm4mIIO 6/7VlzMrDBNDNFPKTqzatAKxYD7Ykdp+wnADaTixMb98ZnvPZpzngRlNsTbR1eAqMGin OVVTVCUinbAA7DzoMhdK0NIZtCVKH1xuFjJniN2MkWrVvFG9yuSRV9r8Ey4Yt6n+qENf XWcPXE7St5/tC16GieQD7BtKre3OtF+VNgjQao02pAU8vmXwS+dEsHk1Tc7dr9q0a6L7 3Wbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680246507; 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=h76ftpfDeW349+865+C5AwRuwTE+LoTxu1YkhFCOpyA=; b=qX/PQwsrxe022awQ9wDM6wtSyDyIzMS5KD/2d/oGUrwNZ6wD/Pr0DSMC4nsTAQ7JWG +QCtrEHlKrgg7J5nGkNrxIEyiUrf7Zcq55DGzLjb7PoD9NIkohwPhXAyepqa4mqx8YDb gKUjBtwsJWDXMrCUmnmt/FOlYcfPKondxg+J6FYD7Y67rHrA2vypvZQ54B8gPHl2p5kI ckQDuMCRIvr7Tdc72c7DRPhVvzt3ko5AmRWC7UdPu6LkGA5hbl7qOWchCIPPR1qgzn23 sQEHC+yxFMcWfVCZUulsLZriS1HhKl9WGgCCDjddin0bxhxZty+84Vh4Ofo+E7DukEPf kr0A== X-Gm-Message-State: AAQBX9et2vLUdB9HENPcjnbF5c0USF8YeV4FqF5BK9h5nsGMHfTAZX5d CUXC/Gp/x2WegqhzzX8Fw/P+WwT+T9Dhly8O X-Google-Smtp-Source: AKy350Y8WGtJv5wxaytzfKnKlxt10iAfzKZBoBbyFn4WF437gd6aXmlYDb8KK6m+3I5auaqd4e3K7Ex+rHzIvu5H X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a81:b617:0:b0:541:7f69:aa8b with SMTP id u23-20020a81b617000000b005417f69aa8bmr12492986ywh.5.1680246506838; Fri, 31 Mar 2023 00:08:26 -0700 (PDT) Date: Fri, 31 Mar 2023 07:08:18 +0000 In-Reply-To: <20230331070818.2792558-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230331070818.2792558-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331070818.2792558-4-yosryahmed@google.com> Subject: [PATCH v3 3/3] mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim From: Yosry Ahmed To: Andrew Morton , 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 , Dave Chinner 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: rspam07 X-Rspamd-Queue-Id: A802C2000E X-Rspam-User: X-Stat-Signature: ct1efwz3mm69mo53a8pphrhtuy8nxxxe X-HE-Tag: 1680246507-827211 X-HE-Meta: U2FsdGVkX1+VX2MkW7HWx+Kjd3khq+bjEEg/QkCsF4vCPhn5a0cPmCNXJusAQZTNo9wZTs1YUwBiypCSVbbx3woCBD9DUcDO47QOi9bfkCQ/OOwwPtTnE1V75KnY+m+99HRkz9DY+Fl7tMeAy9RBknbtDUFiRgyoVkQ2mk4tw97ukGkoCQ+Cc29h5xKBTbBqtLcCvrWqQfvUocAaCw4KZekOT2k9SN3oHPuXH4ORW8as1dGnx/69n+LaO17FMv2XDFMCp7BNkV4pLtl2iIchF22jJ907oGx7636E98bCNnzcMAVDo/Xvacuv0sA+X5nZYGdHxTbaZtuIaA1BMTc5MesQv7Y5xLaWFxtNz9iaZ9DYqCR7JHFIsQqvUCMqs9AU81C6ye5nPjhnNkYiu20/+vvJvdkDs/FM5O6IEL5hOTOdD1bKedmNMg48Xho46lj9Ycx/CUtm1UihgsAMniFXSJQmbdqpi8T2tZy/lgVk2kTQgbocsUa4tuTNRULJNkyz2S/R8zYI8Mh6XBK4Mfx3Qelh5NEe7GxguR3sNsjaXNvHgm/lTjvDPtnvDnmcCK6+QZ+O0HVZJOEVjzsOH/1qjh3gequLj6Gs/v30aOqEhi74mITdklpTftBlNcl+SoxeP1bFSZvPB8jElBTzF0do6G6ONVAv1ugRQYSTwUa7B8JOE9FGa0qICOl5M1U5Ft0TzjXCKO5hA7FBX436xODsK/vFRuBEL5fO89Ksx1GQyNPker1GnK4urUQAKPimN5bWMu8fH26d/57qMoxBHCISbdAsM4YVbLePjozbaxlsWfH2O6ewFKN7RPuUF74D3rMixvsE/hlwBdSGPwJC1fKS83oTSs7E44+E+mYCZgXGScvGlD34RjVZeM63g83gbQbEk2FWEwzqppqkmGUL9eDrjsKnGQ5oBlsJtIMLjAO+AAiHFo2QSVjd/MSEJLcD5EOWyA2hl21QA1812khfwSj xHzAu76d 3RMMEh9S0H5yiv2un8kUGxPRazYjNvVeKFXCsLBvXV5SIjKKTG+4zCz+k+xebz4YpCv0/SLJ4IPjrtTFE1Lidr65I2BvxKpUYD9UVD9okoRNJd5SlBfCuMmBWOlwUD/hJmjyLrl7NCDkW/SGjZdhVlj6vBPqZkBGdczzgshEX7nb7YSlZ4jTMYRK+PdAExttXCYrczotmotmdOr44krj4rBlZLyveGlAlWEknfVH9UOWHcxTepofSYzmCSfFYVSSSfT3L2XU+HWjRupOGuwQFIKJuhJyklCdd/8JeECKPxvd1EQhlZQC8KgYlYjoHT5pqGUcWABif4Ayyz6U/UwFXF3FIChmkDRsupmVwr+38HnSqblQFWdz2cpcOj1mBkpVAch9oAZ+XK0BKdcW+o/atEiplvMbt6zCw7i8dMTinnp2VOTRxutGbOmOZ4kiwklGPDWfiR5Bma/aqAJuAboe5m9l+bqug4W1myEZzbNevSWcbtAg4RGT/6hxBLV4lqiTA7dzHle+qqfqII4661oZYzR7o/LdQQ6EuFLfP02sYuc5vDxqbPj93EZdMA1pspmXuFdUOxIUAytzS3VntS85Ib1Ck6p/jzucLY7KwUDyFHzCm1FtBpQIyP4TA/+OYQeKHaF6faIZCEaOTZZy7cdjOgMj/8jIoOOK2D6HPg4NiSQY4BLPnIYJJd1RUIOxYcqU5O5IUy/ZEjaD49N98ePp+WnJKkVWn0oBjvLkk 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 a3e38851b34ac..bf9d8e175e92a 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; }