From patchwork Thu Mar 16 09:23:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 13177255 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 77362C7618A for ; Thu, 16 Mar 2023 09:23:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A72A1900003; Thu, 16 Mar 2023 05:23:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A22D9900002; Thu, 16 Mar 2023 05:23:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91329900003; Thu, 16 Mar 2023 05:23:20 -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 82282900002 for ; Thu, 16 Mar 2023 05:23:20 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4A15DAADC4 for ; Thu, 16 Mar 2023 09:23:20 +0000 (UTC) X-FDA: 80574222960.04.A9CA63F Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by imf12.hostedemail.com (Postfix) with ESMTP id 4417F40019 for ; Thu, 16 Mar 2023 09:23:16 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf12.hostedemail.com: domain of yang.yang29@zte.com.cn designates 63.216.63.40 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=1678958598; 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=D70TNtp3zkCOreFcACvQARKTqLnmJNLIKtdpW2Sixow=; b=zGzcTftvR7jOJ0lV6p/qGPzt4uZjTeXVPr1ldPOZQMIu1pk1LsRe3jRHlarWwUXEgtP911 g21F/wdz31QHVNLJYj8By9ECI7p7o99iFCsV7VJFWJ18M4GQL8rP/AuSXdjL+DIcxAEhlB F5Q8zjsKWeMJwcTn0kANJNcCzAhdgb8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf12.hostedemail.com: domain of yang.yang29@zte.com.cn designates 63.216.63.40 as permitted sender) smtp.mailfrom=yang.yang29@zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678958598; a=rsa-sha256; cv=none; b=GfRpEiNX0WBB4LPQ+NAsar+o4ur4r9xML22CFtlWawYPXh1Je2yq/UeoRwME8Ijvsmwbb4 64nIqzjQc7bnXCQDGcT1pCXfC4exsnJENjebOvmI++IhlhcZ4EKLuRZV0dsAZT2Sl9wl9e O7Bl00vEy78j8QWmCqv2bBeCKwfrFY8= Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (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 4PchdC38z4z8R039; Thu, 16 Mar 2023 17:23:11 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl2.zte.com.cn with SMTP id 32G9N3Ew025512; Thu, 16 Mar 2023 17:23:03 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp03[null]) by mapi (Zmail) with MAPI id mid14; Thu, 16 Mar 2023 17:23:05 +0800 (CST) Date: Thu, 16 Mar 2023 17:23:05 +0800 (CST) X-Zmail-TransId: 2b056412dff932c-66bf9 X-Mailer: Zmail v1.0 Message-ID: <202303161723055514455@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , Subject: =?utf-8?q?=C2=A0=5BPATCH_linux-next=5D_mm=3A_workingset=3A_simplify?= =?utf-8?q?_the=C2=A0calculation_of_workingset_size?= X-MAIL: mse-fl2.zte.com.cn 32G9N3Ew025512 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 6412DFFF.001 by FangMail milter! X-FangMail-Envelope: 1678958591/4PchdC38z4z8R039/6412DFFF.001/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6412DFFF.001/4PchdC38z4z8R039 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4417F40019 X-Stat-Signature: 8wkh11jqgqndd8nhtwwgqjezc3qteeor X-Rspam-User: X-HE-Tag: 1678958596-994695 X-HE-Meta: U2FsdGVkX1/RLdteoX6n8oXvOcEv0sAXpQ1VFqD1Ph6qMMoUnmBS/QFS2cB43ye4lHKU6vFW2RBxpFskiHFVuyrVR7c7LA2nYrapTAiXETXJyTG+CTKdM1KbFEbBzgY3TooHKsDx3h/pA3b5sq1xhym57L/32NOmXuFaPV8VdDfoTbUesF+3OKR/An4IsOjdynwxXUMeUz4+VGgkz+SzX6ymf+vsmOPjtw/vWLBqT5Vck/W2X0vKc9EDkyzjju5TCOeRBhbLvqvz35gXD5xhNIi62W2BDpmuNXNPX+Gg6Hl7ZnzUASm5tT1MQdLvMYjSfxIeRGLn/Cq1LJq0dVV5tkKRkPEM4BWt0AAGbYz2uF37O8wWpzyozfxbiBVmpcPNj+3OpAKL8nxtGPZQecbykGH7U/NN/UtE8Nm6H31ODDeSZFgS8KLhy7KhMWyS8HCeyqOFsI//SpWa52h+/rNPBEuSz3Tom7O2YB//WEfXN2jNtJ6SgAMWibehVz2e+3ivgEmoZFSiXQP77j/Ti43KSNEG6Fzcdgtpow9xidPI5c6zvytPVcw7WNS2sdjdatMDZWgUMFtZh3/Hpl16uXdMhZnQc/vG7+KHRUyAz477cXtm2V2ocS39XNU5c796y4XW8yS8aDfcgCdTdaxvYIl66AqOu++/4G7ucRFB+3G1+UrE76ppn8PZmIc0nRXfDT1HFvI3NPcu+5Bvola7MQeXUiVGIsN02Ivce9lPX7eHwbugz1UPsrpD+pkuuxBY4IBA2n2/pilX/Ex7QR2rZSrLITigkbOoE788IasUsVJ4CFpIuuA8SgAoUTq2Hsa5iEiLiYi3rgoPU9+ewbArtLKC0ANOP/AQRtUClhXPTXUMxRvQHPgLuYyzfjjNwTMHXc2EV9HWtGX8DnKTmZIsPgq3dpJs48dWwFYaKXr7Zo1EmYgvrImSgyeV5I44RN3M0NQ5CQJTLOhv4qUZrdaEzPw jS38wY/C nz6Ang+p7PWP6CjwgTOaQCgh1X+Jknsy32TGGRpKRkys1JH4Yuu4ih+TN9CFraoGPl1Pz6PhrcZgb/jJNz3LjgzjJq/cei31vXB+uLn0cz9RcnPidkaDWWZ/fOoCMASU5T0s8rxOyHi3aaellFWXAWhHh/ThQCRpRFNQZN3AQzOEhjS+dsMSVQGpAqDKB+adTJyAP 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 After we implemented workingset detection for anonymous LRU[1], the calculation of workingset size is a little complex. Actually there is no need to call mem_cgroup_get_nr_swap_pages() if refault page is anonymous page, since we are doing swapping then should always give pressure to NR_ACTIVE_ANON. So avoid using mem_cgroup_get_nr_swap_pages() when handling swapin in workingset_refault(). This also give us a chance to refactor the code to make it simpler and more understandable. [1] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") Signed-off-by: Yang Yang Reviewed-by: Wang Yong Reviewed-by: Xiaokai Ran --- mm/workingset.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index 00c6f4d9d9be..a304e8571d54 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -466,22 +466,23 @@ void workingset_refault(struct folio *folio, void *shadow) /* * Compare the distance to the existing workingset size. We * don't activate pages that couldn't stay resident even if - * all the memory was available to the workingset. Whether - * workingset competition needs to consider anon or not depends - * on having swap. + * all the memory was available to the workingset. For page + * cache whether workingset competition needs to consider + * anon or not depends on having swap. */ workingset_size = lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE); + /* For anonymous page */ if (!file) { + workingset_size += lruvec_page_state(eviction_lruvec, + NR_ACTIVE_ANON); workingset_size += lruvec_page_state(eviction_lruvec, NR_INACTIVE_FILE); - } - if (mem_cgroup_get_nr_swap_pages(eviction_memcg) > 0) { + /* For page cache */ + } else if (mem_cgroup_get_nr_swap_pages(eviction_memcg) > 0) { workingset_size += lruvec_page_state(eviction_lruvec, NR_ACTIVE_ANON); - if (file) { - workingset_size += lruvec_page_state(eviction_lruvec, + workingset_size += lruvec_page_state(eviction_lruvec, NR_INACTIVE_ANON); - } } if (refault_distance > workingset_size) goto out;