From mboxrd@z Thu Jan 1 00:00:00 1970 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 3C638C77B6C for ; Thu, 13 Apr 2023 08:35:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76C5F900004; Thu, 13 Apr 2023 04:35:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71C68900002; Thu, 13 Apr 2023 04:35:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60B69900004; Thu, 13 Apr 2023 04:35:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 51693900002 for ; Thu, 13 Apr 2023 04:35:01 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1165E4024E for ; Thu, 13 Apr 2023 08:35:01 +0000 (UTC) X-FDA: 80675707602.05.0859BBF Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by imf21.hostedemail.com (Postfix) with ESMTP id 52F3D1C0002 for ; Thu, 13 Apr 2023 08:34:56 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf21.hostedemail.com: domain of yang.yang29@zte.com.cn designates 183.62.165.209 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681374898; 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: references; bh=mndH+zBXOCKgkqvOxkqD3di69S65TBk+ZoyVARpnXDo=; b=1TiweZp//kr24oQ2cfPHctwrktgyBKKVmTD//YTvP/wWO3ZikoHJ08fVR5sgpRtDG4YB2o yyVICXYktirpMzyX6T+Y4OqHqBoy6Gnhq/kUaSvTJp3BlQid6cOLLIgSlkbfgN4FPJB7Fa i9oihLZcfZQ48fN7VdvaRbtIw2x5taU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf21.hostedemail.com: domain of yang.yang29@zte.com.cn designates 183.62.165.209 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681374898; a=rsa-sha256; cv=none; b=MOhBhXiLrGQ438igIlFimPfEISSSr04DUWP9EIH0EmYomB/vO2E90hvWooX0S5bkqAtBRM 8BjVDqtEZhDjPWMZv1TW1buwceZDjKkjlNRLIsfEK5bgYSHitvxtGa4iGgOVdgI247xb0T IVhq4JVuSTDlZHhsCrp9Qf8JYU7HDgo= 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 mxct.zte.com.cn (FangMail) with ESMTPS id 4PxtDY0lZhz50FXF; Thu, 13 Apr 2023 16:34:53 +0800 (CST) Received: from szxlzmapp07.zte.com.cn ([10.5.230.251]) by mse-fl1.zte.com.cn with SMTP id 33D8Ykbp007431; Thu, 13 Apr 2023 16:34:46 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Thu, 13 Apr 2023 16:34:49 +0800 (CST) Date: Thu, 13 Apr 2023 16:34:49 +0800 (CST) X-Zmail-TransId: 2b036437bea9356-74909 X-Mailer: Zmail v1.0 Message-ID: <202304131634494948454@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHQgdjJdIG1tOiB3b3JraW5nc2V0OiB1cGRhdGUgZGVzY3JpcHRpb24gb2YgdGhlIHNvdXJjZSBmaWxl?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 33D8Ykbp007431 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6437BEAD.000/4PxtDY0lZhz50FXF X-Rspamd-Queue-Id: 52F3D1C0002 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: hk4qp13ozh4usrsqhkjnqer9j3f9njnq X-HE-Tag: 1681374896-901974 X-HE-Meta: U2FsdGVkX18cYjW2CS+bXDkMnyXJx8VDexOdUAaRYX46wwEM9i91qcOTWdwftvtkF1aGwrRWL9pcNOzdVwSOyY6VLxDDpvn115TAp6JyjbMKeHNl+UyhDYSO7wXvwUgBrc4Kc8Lewm/58bQyIKAqYzrawjulhG6gEFYMbgCPbGq01tFLQmpME+U6u4wpOzaxMTmwPdWGC+lRJOc0pDWw+aMpUAkKOLghLGKZPRRpgCLJ8ck4TQD/r34QpwpFbr1+ipc1wfermDgEWejwwqZxWoKnsiZ214TAVMN18WLrMKND5rd1cloG1qZ57PIzTBET2swx0KWCmR7kJPkjMIWmhIMaXTmb76kzba+093t7eRzqmRL+7/CtYxc1TMhNeQVP9N4zGLWc8WFUFZTyLfbeJFrZICtT2Rt+jubsveNNRPCJYMeEnP5HnllDcepb5/kO8F3vqwLz5o6+OO7MigIf+V5QyG+g+ar7jCdn8RfRE0jPXop8qLemIieO6T0ZNJaKrPC2FbnD+jYFeVMNB836XYtxzF4unLjLN1njDdvR3YXn6XVU4jgUfWsIgK9t8PTFdW3L6+HMmteBCrrn+nFEvW4lThEwHlJeIzd1B1hB4gj9ajrBOsD4pzrcx6xn8+AfgF2DCP6XZtc2aC21wCUNhTxEqV87THxOxrORwnKRGsG9DE+C9oSgL2IUx2boO09uYE++hRRyAIWNR7/wxafcqRAKJs+5NQY6YIBQvjEkyEV1sCralA7TRaaqkSnIfeoD67d/ibchILTlXFKgZ2/sBXnQ/opv25/P2zbffxio6D5DgW3P+c7ZBKVzMtDKW+4ihLGB0jVCtfGvdQmnxbRZbeoj3Fusa8w/QRIS43jlW/AXK5klFNMGEPw6Yj4UJH/ceELHtCzMjWHzSsl7d2goy1c6N/n6Q2bpH9jvp7kB2jhur+iXUqzA08ec8dc4npPmnMhlKvNYw4syHPO0Ee3 gzm2i0Kk xK0B3z5eYDOhk/bHH2royN/C3di8Gj7HCericbFsTsJlcvLl5MeSUUEc7t09RUfDXDYuVQy1jt1H5GLX85AogA3Vf4hjov936zZGvCrPFihUpfKEO6UEny+aUUkwtUVwBMs+FMZYyoP526izh59UwHNuy/IINdYcgllzM870CNM5gEWDbyOS8UwVFPgkdQg5ItzzL3mt7v6h1MjwqW0MGwNsNl1LaChz75REb/5shBmSb1gjhO29ji3PvlKwSZxmq/JtGlVp1hpi/Wg59GhhV2B/OsLSL4Jr4PdBKTzKHMVnLALPGhrPsAtZb5Wy9N9OH9JMx4qpDfN/x1pp/UjLo7jacnLBYswV070pT 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: Yang Yang The calculation of workingset size is the core logic of handling refault, it had been updated several times[1][2] after workingset.c was created[3]. But the description hadn't been updated accordingly, this mismatch may confuse the readers. So we update the description to make it consistent to the code. [1] commit 34e58cac6d8f ("mm: workingset: let cache workingset challenge anon") [2] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") [3] commit a528910e12ec ("mm: thrash detection-based file cache sizing") Signed-off-by: Yang Yang --- change for v2 - Update commit of workingset_refault() suggested Johannes Weiner. See https://lore.kernel.org/all/20230316143007.GC116016@cmpxchg.org/ --- mm/workingset.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index a304e8571d54..b864eec49ddd 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -111,9 +111,20 @@ * * NR_inactive + (R - E) <= NR_inactive + NR_active * - * which can be further simplified to + * If we have swap we should consider about NR_inactive_anon and + * NR_active_anon, so for page cache and anonymous respectively: * - * (R - E) <= NR_active + * NR_inactive_file + (R - E) <= NR_inactive_file + NR_active_file + * + NR_inactive_anon + NR_active_anon + * + * NR_inactive_anon + (R - E) <= NR_inactive_anon + NR_active_anon + * + NR_inactive_file + NR_active_file + * + * Which can be further simplified to: + * + * (R - E) <= NR_active_file + NR_inactive_anon + NR_active_anon + * + * (R - E) <= NR_active_anon + NR_inactive_file + NR_active_file * * Put into words, the refault distance (out-of-cache) can be seen as * a deficit in inactive list space (in-cache). If the inactive list @@ -130,14 +141,14 @@ * are no longer in active use. * * So when a refault distance of (R - E) is observed and there are at - * least (R - E) active pages, the refaulting page is activated - * optimistically in the hope that (R - E) active pages are actually + * least (R - E) pages in the userspace workingset, the refaulting page + * is activated optimistically in the hope that (R - E) pages are actually * used less frequently than the refaulting page - or even not used at * all anymore. * * That means if inactive cache is refaulting with a suitable refault * distance, we assume the cache workingset is transitioning and put - * pressure on the current active list. + * pressure on the current workingset. * * If this is wrong and demotion kicks in, the pages which are truly * used more frequently will be reactivated while the less frequently @@ -468,7 +479,7 @@ void workingset_refault(struct folio *folio, void *shadow) * don't activate pages that couldn't stay resident even if * all the memory was available to the workingset. For page * cache whether workingset competition needs to consider - * anon or not depends on having swap. + * anon or not depends on having free swap sapce. */ workingset_size = lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE); /* For anonymous page */ -- 2.25.1