From patchwork Mon Jun 24 17:53:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13709936 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 8FE5BC2BD09 for ; Mon, 24 Jun 2024 17:53:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A1856B0186; Mon, 24 Jun 2024 13:53:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 156EB6B013D; Mon, 24 Jun 2024 13:53:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E98646B0397; Mon, 24 Jun 2024 13:53:29 -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 C8EFB6B0393 for ; Mon, 24 Jun 2024 13:53:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0FB25140F69 for ; Mon, 24 Jun 2024 17:53:29 +0000 (UTC) X-FDA: 82266529338.13.A0D6B0E Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf06.hostedemail.com (Postfix) with ESMTP id 3A689180007 for ; Mon, 24 Jun 2024 17:53:27 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BpCBqMeQ; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719251588; h=from:from:sender:reply-to: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:in-reply-to:references:references:dkim-signature; bh=FCnimar8H+lPv/3bct6eyTo5OROr2uJMk5cUxjITOfs=; b=cBQ+wv2erDFOdsoFY8n9ouovtkc6wIut+b4uBcAxEnlbtJe/MIhkGJI3UFLN/WRuIOh1Ro FtTv5LdjZI9xJXHNdw4vTcsai8Y5qEC7GQwgehT/kylJF/DYTuMSWDUCfct1issxqh0Rh8 FbBPzvjepfCc6z5oFiSRnyMUBtqB1r8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BpCBqMeQ; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719251588; a=rsa-sha256; cv=none; b=QCoDSpw4cZNyX+yLdK9LQhWsNPEjSR/Du8rCPgnu9ZsYtvymuFGCRkhiYT67ALQxMYkMSW N3F7HiTboPQDbIJVO6UcnDTubFy/GCs3XdnquluPCm8hm7QA+qpp1o7Gl0JOZoA76aFBRo wwfew1oFQtOV74ieqkBAzBfSMEjfJuc= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-706738c209bso1130196b3a.3 for ; Mon, 24 Jun 2024 10:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719251606; x=1719856406; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=FCnimar8H+lPv/3bct6eyTo5OROr2uJMk5cUxjITOfs=; b=BpCBqMeQf3Yjc0X0lW04K6j0fQArxU+DFl4O6j/mEZ3JDQ2387co9OCF9NlAI22CLI 8thztPVuXWcxc7at3CKuN3UtB+rRdEQ0xEZuk6oox1MRlkwF/4oRFYrCji4ibkJ+YBsz TyaIlsBU7BoW1PhtIDa9aPsuAdIMrYmn/eFi4NHlpru3l0McyZ9z9JjTIP1jyGbl/rjy lCYd/nkuj4hQRStuFYqS3hHSYp0DsIaNr42glozKuKXJFnwPhIRV3odPBS7amWQba7h1 FK/xYu1vwj5rCbqkMRVSiUsu2WvfrZx+Vt4Rd54GKRZxAFP+m9qLvsoEZYzS+i6Fc/QN yA5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719251606; x=1719856406; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FCnimar8H+lPv/3bct6eyTo5OROr2uJMk5cUxjITOfs=; b=uHqIjew+pqEiWJzowu4w3l1eEZcdjQx3m4dgYE8izC5Dtq8YKOoHca7L/vNUoMwDdy 4S0KY5NLpOzdgY3iIdlOpp9f3ys5hQbKzvPRqfw/tQPiHooIvVTwEvKrZFuKayupEqiv X+LLs8YkdufD2alMcw/QrVdfA/OdrlEA7FqWTpBizrUBmJHD/9w6oEOf8/as/+qIJKAY /P9ZeDFC9ygoddP9JcGAJ318WVscW8fNtIgY1CqONNdwHyCN892Ar6I3VZGmudb+8J0d 8YS1JIjmInBumEy1uoP+kGvbC6LtJJonp15BshMEtr/xdK4tdhYMQ6fsc3uScUEGfXnG oTzg== X-Gm-Message-State: AOJu0YygBTlCN6faocu8cygbUMIf9Cy3vD+Z30xO/p3QTdBys6sOlUuB VnhNRyitOcVsaDOA0zLj1tDeZgkvWYLJV0ex5ZF6xN/lQsVb7J9f4z4s+qxyBo4= X-Google-Smtp-Source: AGHT+IEXa6w9Ip9ReBGq8x5dsnMI+cJXnCy3v637ZPx4cWpeOl4Ipm7HxoNNRLQwhSPHnWl7OES9xA== X-Received: by 2002:a05:6a20:ba29:b0:1b8:4216:14a2 with SMTP id adf61e73a8af0-1bcf7fcb5fdmr3988725637.40.1719251605533; Mon, 24 Jun 2024 10:53:25 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70662ee117asm5008049b3a.211.2024.06.24.10.53.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 10:53:25 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Waiman Long , Shakeel Butt , Nhat Pham , Michal Hocko , Chengming Zhou , Qi Zheng , Muchun Song , Chris Li , Yosry Ahmed , "Huang, Ying" , Kairui Song Subject: [PATCH 1/7] mm/swap, workingset: make anon workingset nodes memcg aware Date: Tue, 25 Jun 2024 01:53:07 +0800 Message-ID: <20240624175313.47329-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240624175313.47329-1-ryncsn@gmail.com> References: <20240624175313.47329-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3A689180007 X-Stat-Signature: 4epoce1ngwy4cn5jkm1ws5fagsxrbzpr X-Rspam-User: X-HE-Tag: 1719251607-910409 X-HE-Meta: U2FsdGVkX1/ax+CPu8iKyAKnvqVYihZvdug5bg5AYpziiTJY2nQegRC1WcGP+722tdwMybFn/b/AvwUxumvvR3/3qFK6Qd1lVouVBzfKeoTZKBEGq2REQBA4BE04jGEPStRMBYKTIC/dw5i+FiMcaqnYPFVe682W7DQFoce850CyD5hXOBE51N8vwh5lmw/Pa9UvqCUlJjet1WyLNhd9OBXwoT6N4r5n1N39Vb1xLEMc2gJ3nwhpT0EwKKUtUF8fmCKgrYBw4QOtcsMlq372BYrXaJWcg1pMxzu/D+ieuFSt1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xDbqTPAgZ0EmzUDMIxCZ3w/h62kMvnabjwPNqqLv9LubCN+uOTPdwPz4dGgq0oGeNfFXwUcRFkgNfJ1TZxzWRMeuunZR5hMAIJXOcPGoM0rEs+rlA/04z2DaK8wMUraQKUrxZim6ac1GGzQHraRc/1wnRr/7q2zRf8xTbRqDxIUT3k3iHtlYpKj 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: List-Subscribe: List-Unsubscribe: From: Kairui Song Currently, the (shadow) nodes of the swap cache are not accounted to their corresponding memory cgroup, instead, they are all accounted to the root cgroup. This leads to inaccurate accounting and ineffective reclaiming. This issue is similar to commit 7b785645e8f1 ("mm: fix page cache convergence regression"), where page cache shadow nodes were incorrectly accounted. That was due to the accidental dropping of the accounting flag during the XArray conversion in commit a28334862993 ("page cache: Finish XArray conversion"). However, this fix has a different cause. Swap cache shadow nodes were never accounted even before the XArray conversion, since they did not exist until commit 3852f6768ede ("mm/swapcache: support to handle the shadow entries"), which was years after the XArray conversion. Without shadow nodes, swap cache nodes can only use a very small amount of memory and so reclaiming is not very important. But now with shadow nodes, if a cgroup swaps out a large amount of memory, it could take up a lot of memory. This can be easily fixed by adding proper flags and LRU setters. Signed-off-by: Kairui Song --- mm/swap_state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 642c30d8376c..68afaaf1c09b 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -95,6 +95,7 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, void *old; xas_set_update(&xas, workingset_update_node); + xas_set_lru(&xas, &shadow_nodes); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio); @@ -714,7 +715,7 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages) return -ENOMEM; for (i = 0; i < nr; i++) { space = spaces + i; - xa_init_flags(&space->i_pages, XA_FLAGS_LOCK_IRQ); + xa_init_flags(&space->i_pages, XA_FLAGS_LOCK_IRQ | XA_FLAGS_ACCOUNT); atomic_set(&space->i_mmap_writable, 0); space->a_ops = &swap_aops; /* swap cache doesn't use writeback related tags */