From patchwork Mon Sep 30 06:39:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13815441 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 D2BA1CF6491 for ; Mon, 30 Sep 2024 06:39:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06E726B00F1; Mon, 30 Sep 2024 02:39:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01DA06B00F3; Mon, 30 Sep 2024 02:39:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4E3F6B00F5; Mon, 30 Sep 2024 02:39:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C6E0B6B00F1 for ; Mon, 30 Sep 2024 02:39:51 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 59E251A1D42 for ; Mon, 30 Sep 2024 06:39:51 +0000 (UTC) X-FDA: 82620454182.22.D269A15 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf03.hostedemail.com (Postfix) with ESMTP id 9CB7D20005 for ; Mon, 30 Sep 2024 06:39:48 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727678287; a=rsa-sha256; cv=none; b=Ra3Xei78YFGkXGSRfk7U3W0GPyILyZ4i6lb0Jv6x8stWFjxHo2N0LvJsne4yOqxyNCE88H 17zlAVe4oy33MZNx2ANAl4XaY5ZJLjngennJHoq0jgrjfqN1XHWTN344qkEfVxja+Ap2gE yjkEQMX3J82sdOGjMa0xV2hLu7zpB00= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727678287; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=t6zrld4PXtjoe4ZfTdBO1MzFSqeEnm1vWDfbPd0RZd8=; b=xSROlYhAHYIECagAccG+iplp1jcwWRO0NyeMz39TxkTx4UDPrKvQ7wI4woW1UBdh0bIqMG /iw4k5f4qfy6Jiav8jr/HwDdlt+JqK20nPqukubCrJv0wZeNC1EpB7fw+LJAMTsLAUKQY/ hhi3sZTxuBROoLg9OJJYj9hF5E9+n+I= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 48U6dVJK069882; Mon, 30 Sep 2024 14:39:31 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4XHB6w6F09z2R6KXB; Mon, 30 Sep 2024 14:31:36 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 30 Sep 2024 14:39:29 +0800 From: "zhaoyang.huang" To: Andrew Morton , David Hildenbrand , Matthew Wilcox , Yu Zhao , , , Zhaoyang Huang , Subject: [PATCH] mm: deal with active/inactive inversion in lru_gen_is_active Date: Mon, 30 Sep 2024 14:39:12 +0800 Message-ID: <20240930063912.196526-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.40] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 48U6dVJK069882 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9CB7D20005 X-Stat-Signature: br8xu7qo4gni4t97chsh3cz5nuuy6ns4 X-Rspam-User: X-HE-Tag: 1727678388-212532 X-HE-Meta: U2FsdGVkX1+FKuGCsew8s9rNV5SbAv0CWoEQsIllle+3s//92Ly7SsB+zUXjsMD7CKhHWc9w1pjanz2ekSI/DExmlaoRfYQGLpQ2hPEWdE5VURoxJB9o1vaLXUyg5T0ksXxmN08lnHfKy4v3HOKc3B9jSQB6eiOFv/Sjh5GIXv9RrsudCZZQyuMwhuZlIUizJplrXlnd0gA5pmdHPg8XLin2XrTlzHlN3ynOwCjrn9zQH7W+t2/iNSc86b5GCazw/QoEhO37+ujKiFVYtjbRJLd6YU8pDqRNCMD5Mku3XD7AIKO2lkinBAWhESAdOjj+02+CTOKU+SmMfda4zzmNs6nisscWswKEX1doQf/UPnIv+N2BavcVem+TOOS2fRxcLrRI5DvzyR1ImCea1OEQEnzqnubKamd3McwQqhQl6z0Ymw50MklclfFTGyTolz8RFn8OJsUThZ/sCHDC2uBNv/fwZg+Q7EfXyPyYjuPtJkdB2JzzwIovP4dut5+YXvtFA/zl5lCDSXvxBX6z18Ed1Vkysod8SWqfe5uPrbXxipOB4kl31ZRMI2aeeH+qsvNLlWPovu9V0q3/qw7nlCRVO5BdYmQq7o27X4U30A2FbCs93z4id0B3TqbcXoQ6xofN94kIb9S99NS1MzhmdQcY/z9XkNEUZl2jUs1FFyydGEZqNTdhIzAfUO1V2gWpC2mqPFAz5NzOGXmRqypRAZ1YVEVFEPzQuP8RbgNjHXZL+L6KArGveDMwWoarXEP5SHLaM7UMjPcO8tViFYqJtl6hrHH9TIJXQ2BDgxOZSkOH1jIbvfAsYyOZkNsaMvL/xZIxrM7nvPmRhcishLAbgP3G1p1oeV+gR8hP352EJIYrSFwzPwY+Sx1qFjgtdm43PPjWMwUdlxgmfVmHLTnCWPunHTg7Pg+pJ2YkSVej4+jKF5QB/S5SaBikFE8S0+eKLCENfa9dv1B4mCYcRrCQ9lU CkOmQTFr XhGccIZNnWDPihCe4o5fgpuJqMJscvgk070GB0Xt4NEQ0lq07dq27pMVej3rY2YDdimgFbYWZDVklxCWeRZb0rdRw5MfA7EqL/D1GzQjb2gWYF6frgmiLP/9RYCxxB3puWwzsNZgUea8gA5E2rVzQpB2ktY7N1QIIF7kAsRM4bVhOEekzb31QGDuR/58WtzP1imlguuh1erAk8fuoCW6i/L51o4tuj57G2fSDvDEIKZQOG8pDrbwmEpcXdA== 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: Zhaoyang Huang All gens will be deemed as active by lru_gen_is_active when there are only two generations within the node, which could have the folios to be active in the belowing scenarios. This commit would like to solve this by judging if numbers of file type gens greater than two since anon gens could be remains as 3 when swap is constrained and file type seq advanced by 1. 1. New folios after migration done. 2. Dropped folios from none-reclaiming context(drop_cache, madvise) when they are failed of being reclaimed and go back to lru. Signed-off-by: Zhaoyang Huang --- include/linux/mm_inline.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 6f801c7b36e2..5e4017dbec96 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -165,11 +165,16 @@ static inline int folio_lru_gen(struct folio *folio) static inline bool lru_gen_is_active(struct lruvec *lruvec, int gen) { unsigned long max_seq = lruvec->lrugen.max_seq; + unsigned long min_seq = lruvec->lrugen.min_seq[LRU_GEN_FILE]; VM_WARN_ON_ONCE(gen >= MAX_NR_GENS); - /* see the comment on MIN_NR_GENS */ - return gen == lru_gen_from_seq(max_seq) || gen == lru_gen_from_seq(max_seq - 1); + /* see the comment on MIN_NR_GENS + * judge if there is active/inactive inversion by the number of file + * type gens. + */ + return gen == lru_gen_from_seq(max_seq) || + max_seq - min_seq >= 2 ? gen == lru_gen_from_seq(max_seq - 1) : 0; } static inline void lru_gen_update_size(struct lruvec *lruvec, struct folio *folio,