From patchwork Fri Jan 13 07:50:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 43051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp140008wrt; Thu, 12 Jan 2023 23:54:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXvr3ojnfMETngat/qUlAWn4br/I8+f94LwzO+lr4PrRrKxoqZ5rtfgmg64tvTDAtgQ2dga0 X-Received: by 2002:a05:6402:c44:b0:48e:ac4e:7bfa with SMTP id cs4-20020a0564020c4400b0048eac4e7bfamr16697631edb.2.1673596466264; Thu, 12 Jan 2023 23:54:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673596466; cv=none; d=google.com; s=arc-20160816; b=s2QwqQlHCmICbH15eIWxHzElswZ5LOhM557IiOGc7SRZ9ETGB+DearVejre04X7mu6 fsBzTaVJKPqk7BzalKzJMKnVb85goqnruAaQy8lquvbARvjEQwOHc0mA74XcOyDrG1Nr qDNebWp8zqq6yaHRdBNXt1fl+BI0Vomy73JTZrYzY3vHPkv8MdeMpfNTiwDwRA1we4q8 wBQoYpKzcojS48hzRfDfyhymVGplBAODXvuvK2Gn35JWIxdRQTXeLTcLrFPYC/KaG9PP nHJfNcvuCgJb9oX2xCN+w2B13P8EzKEMACjGAvijpMJlwlDiAeB+slmaL6vv2O99+sVt XNCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=0W2UT7XekmPW2Ch/Mfx+ufxNEaWobtcBJn2NfrwjzuQ=; b=E3iydrAFGPmqwEFq/pLcdBhefyKMKdLJ0p40VY1ivVD+FcOEDtvXldZ01yoHvYp6wP nbWkprIj6HWFt4waAYSbBa5w+ergtgbcjB5MDP7OKR16EctrU/wrEqroiyqZREwWoGQc yVvngIozXZRGrZxZgWyOq+XFp11B1WGEoR+qyNuZtc8tKu9dqr99R/IN7/tRbHUMO5K4 wRC1MZk7ZC7j3tQNxE9cJK5iAKYmN25i4bHijfdjsRSN7c9AsTp20Weno2Xoj+Yg4A33 NXmaJCdCSCL9h4Q/SBXpALrgycTf52vlJlit4LpYZSwPmFDwb/AFuRB3BNzCVfvzxC06 U0JQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s22-20020a50ab16000000b0048eafc90734si18649701edc.544.2023.01.12.23.54.02; Thu, 12 Jan 2023 23:54:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232182AbjAMHvG (ORCPT + 99 others); Fri, 13 Jan 2023 02:51:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbjAMHvA (ORCPT ); Fri, 13 Jan 2023 02:51:00 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC0575F75; Thu, 12 Jan 2023 23:50:55 -0800 (PST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NtYWL1bQDz6FK2T; Fri, 13 Jan 2023 15:50:54 +0800 (CST) Received: from szxlzmapp06.zte.com.cn ([10.5.230.252]) by mse-fl1.zte.com.cn with SMTP id 30D7ohY7091613; Fri, 13 Jan 2023 15:50:43 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Fri, 13 Jan 2023 15:50:45 +0800 (CST) Date: Fri, 13 Jan 2023 15:50:45 +0800 (CST) X-Zmail-TransId: 2b0363c10d55ffffffffcfca5f18 X-Mailer: Zmail v1.0 Message-ID: <202301131550455361823@zte.com.cn> Mime-Version: 1.0 From: To: , , Cc: , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next_v2=5D_swap=5Fstate=3A_update_shadow?= =?utf-8?q?=5Fnodes_for_anonymous_page?= X-MAIL: mse-fl1.zte.com.cn 30D7ohY7091613 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63C10D5E.000 by FangMail milter! X-FangMail-Envelope: 1673596254/4NtYWL1bQDz6FK2T/63C10D5E.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63C10D5E.000/4NtYWL1bQDz6FK2T X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754893088262765655?= X-GMAIL-MSGID: =?utf-8?q?1754893088262765655?= From: Yang Yang Shadow_nodes is for shadow nodes reclaiming of workingset handling, it is updated when page cache add or delete since long time ago workingset only supported page cache. But when workingset supports anonymous page detection, we missied updating shadow nodes for it. This caused that shadow nodes of anonymous page will never be reclaimd by scan_shadow_nodes() even they use much memory and system memory is tense. This patch updates shadow_nodes of anonymous page when swap cache is add or delete. Fixes: aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") Signed-off-by: Yang Yang Reviewed-by: Ran Xiaokai --- change for v2 - Include a description of the user-visible effect. Add fixes tag. Modify comments. Also call workingset_update_node() in clear_shadow_from_swap_cache(). Thanks to Matthew Wilcox. --- include/linux/xarray.h | 3 ++- mm/swap_state.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 44dd6d6e01bc..5cc1f718fec9 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1643,7 +1643,8 @@ static inline void xas_set_order(struct xa_state *xas, unsigned long index, * @update: Function to call when updating a node. * * The XArray can notify a caller after it has updated an xa_node. - * This is advanced functionality and is only needed by the page cache. + * This is advanced functionality and is only needed by the page cache + * and swap cache. */ static inline void xas_set_update(struct xa_state *xas, xa_update_node_t update) { diff --git a/mm/swap_state.c b/mm/swap_state.c index cb9aaa00951d..7a003d8abb37 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -94,6 +94,8 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, unsigned long i, nr = folio_nr_pages(folio); void *old; + xas_set_update(&xas, workingset_update_node); + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio); VM_BUG_ON_FOLIO(!folio_test_swapbacked(folio), folio); @@ -145,6 +147,8 @@ void __delete_from_swap_cache(struct folio *folio, pgoff_t idx = swp_offset(entry); XA_STATE(xas, &address_space->i_pages, idx); + xas_set_update(&xas, workingset_update_node); + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio); VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); @@ -252,6 +256,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin, struct address_space *address_space = swap_address_space(entry); XA_STATE(xas, &address_space->i_pages, curr); + xas_set_update(&xas, workingset_update_node); + xa_lock_irq(&address_space->i_pages); xas_for_each(&xas, old, end) { if (!xa_is_value(old))