From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7018843B3FF for ; Wed, 12 Aug 2026 12:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537125; cv=none; b=GO2nVVa5BR1+QgVoMJ6yyUQ2RVBc/HgGICwCvF8g8j9I5RTLKhHp/svtE3Tce5NpQgPbHgTWkifY/zfoTD2c+hwJYjCH3+mMF8jN0FnTpkFmHoN1b+4+s51ir29A6ET/iJN/iYKGeC5+wOXFUU6jccHKiRbopiwFmPVa/GsgqMY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537125; c=relaxed/simple; bh=ZXzzA4BA5h7s6CyPi5Vt5iioNBmHdY3MGLTqW7AGs7o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=osLHzB/3rimSb+JaJuenL3AemDEMV6PSkkmDqJPM8hKwAI7ztPY3QuDSWSxKYmZ0fBuLkiHdc5HB2nkDeD1Td2HWOx4kE7RmrDCE/H/QHPlVo+BOpAcUmKX3dA/pkht5ZUiK+OGVICzsA/WYLxy0JnwuMxwGJomdink+XCtIx6Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CSCdLo2l; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CSCdLo2l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC4DB1F00A3D; Wed, 12 Aug 2026 12:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786537124; bh=emxjHhjwy8XERbEMKSGImjrtQvsEUGjXFQEU42dLbqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CSCdLo2lMszB+gAPNugQg54MeL7QysW31P6OWjRQq9cOcOyMtBbRENzoISFusdZC7 yDbqUl23M4nN3rsQXMg1HlY1eOjDdTYed9qr3wScscQGuILuFPQCKxPxqXMP9qS97/ iTgfwTji37orfI88Ay+z0i7yO8mIvkzIomW5YymLrAoBoFrSI3aGuc2oz78TQNLOEl ceKJWs5rwxF/f6hYcsc6oWXnt/tqZa0taIiPfxKUvQEdfasL5hBWCKBs0cqgiCQWAW LdNa0w/m0X6lIDnkn7pxyWmwxbxon3NBjm6FMAybMzYbawnfwnL3Ij/B/mXIAx5aFb 5I1i6WbT/ICQw== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, chenridong@xiaomi.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, lianux.mm@gmail.com, linux-kernel@vger.kernel.org, ljs@kernel.org, lyugaofei@xiaomi.com, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, stevensd@chromium.org, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com, zhangbo56@xiaomi.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, "Barry Song (Xiaomi)" Subject: [RFC PATCH v4 10/16] mm/mglru: batch move folios to the second-oldest gen's LRU Date: Wed, 12 Aug 2026 20:16:52 +0800 Message-Id: <20260812121658.69965-11-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260812121658.69965-1-baohua@kernel.org> References: <20260812121658.69965-1-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Detect folios that need to move from the oldest generation to the second-oldest generation, and batch-move them together. This can significantly reduce the sys time of inc_min_seq(), especially when the other type is significantly behind the preferred type. Assisted-by: gemini:gemini-3.6-flash Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 17357b16d1a7..b6c17ece3b3f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3922,6 +3922,19 @@ static void clear_mm_walk(void) kfree(walk); } +static inline void flush_lru_batch(struct list_head *head, struct list_head **batch_end, + struct list_head *dst) +{ + LIST_HEAD(movable); + + if (!*batch_end) + return; + + list_cut_position(&movable, head, *batch_end); + list_splice_tail_init(&movable, dst); + *batch_end = NULL; +} + static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) { int zone; @@ -3941,9 +3954,11 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) /* prevent cold/hot inversion if the type is evictable */ for (zone = 0; zone < MAX_NR_ZONES; zone++) { + struct list_head *target_list = &lrugen->folios[target_gen][type][zone]; struct list_head *head = &lrugen->folios[old_gen][type][zone]; unsigned long protected[MAX_NR_TIERS] = {}, delta = 0; struct list_head *pos = head->next; + struct list_head *batch_end = NULL; while (pos != head) { struct folio *folio = list_entry(pos, struct folio, lru); @@ -3962,7 +3977,8 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) new_gen = __folio_inc_gen(folio, old_gen, &gen_increased); if (gen_increased) { delta += nr_pages; - list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]); + batch_end = &folio->lru; + /* don't count the workingset being lazily promoted */ if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) { int tier = lru_tier_from_refs(refs, workingset); @@ -3970,11 +3986,14 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) protected[tier] += nr_pages; } } else { + flush_lru_batch(head, &batch_end, target_list); list_move(&folio->lru, &lrugen->folios[new_gen][type][zone]); } if (!--remaining) break; } + flush_lru_batch(head, &batch_end, target_list); + WRITE_ONCE(lrugen->nr_pages[old_gen][type][zone], lrugen->nr_pages[old_gen][type][zone] - delta); WRITE_ONCE(lrugen->nr_pages[target_gen][type][zone], -- 2.34.1