From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-27.mta0.migadu.com [91.218.175.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D1E3353A61 for ; Wed, 26 Aug 2026 09:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.27 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787736876; cv=none; b=vAKqdL0xx3pf3hohCSAjUZ1taKAeix3rKHGZYk8AoYqn83P5OxEvcHMtvT+aZO2MAE68jwgFxl6b8CIRbhIa47XIBugfj8cYCEl8tMOWyYOVnJWP+7J0Rhv7La0H4NiSDBMUaoFaW+gEBVYIOgXX2ph0FBdxYcVdxInFBeucjlQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787736876; c=relaxed/simple; bh=RH8kD9SovqtyuZbKMI9LVB6g/2XlQNy9bg+wJMXI7ns=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A/M8bQuFnqKEWqZuNwZlqK26DT3JcG52FRQ7DODg2xal0leALkGFF728P4wI3Q/iWLY8nF+4TVUByoNr0/Pp5Csd1CvypQpZ8GJtaNZyVhPJzq5tfFNNJ/pM5o2P4rimMIcY3ajbtG61i2SjsdD16POi1BoIxe8UAYEvAvRw/q8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=l0n6JPAk; arc=none smtp.client-ip=91.218.175.27 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="l0n6JPAk" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=RH8kD9SovqtyuZbKMI9LVB6g/2XlQNy9bg+wJMXI7ns=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787736871; v=1; x=1788341671; b=l0n6JPAktzJzKMuZ2ZU9bZvzXYAD9ECGkWED/146X1K2JQ/Ws+e8Wmyb8VsRjZ71kQWI80Ut HbyBjg8Ee9YR5p8pxEkfpIBzNDXAGkiLIvRcyffnorWQ2hSjg0SpAvROXG87TMCAf/a22jSCowR 6lQVoclRkuk+xMGw0CJlE+tU= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost (223.70.160.239) by mta11.migadu.com with ESMTPS id 0c766ee9554d6e2c; Wed, 26 Aug 2026 09:34:21 +0000 X-Mizu-Trace-ID: 0c766ee9554d6e2c X-Migadu-Flow: FLOW_OUT Date: Wed, 26 Aug 2026 17:34:13 +0800 From: Baoquan He To: "Barry Song (Xiaomi)" Cc: akpm@linux-foundation.org, linux-mm@kvack.org, axelrasmussen@google.com, baolin.wang@linux.alibaba.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 Subject: Re: [PATCH 6/6] mm/mglru: batch move folios to the second-oldest gen's LRU Message-ID: References: <20260821102538.22642-1-baohua@kernel.org> <20260821102538.22642-7-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260821102538.22642-7-baohua@kernel.org> On 08/21/26 at 06:25pm, Barry Song (Xiaomi) wrote: > 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 2fd82b2ca4d1..996b48344ed0 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -3923,6 +3923,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; > @@ -3942,9 +3955,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); > @@ -3963,7 +3978,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); > @@ -3971,11 +3987,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); How about this? then you only have "struct list_head *batch_end" in 2nd parameter. And explicit resetting batch_end makes code more readable? flush_lru_batch(head, batch_end, target_list); batch_end = NULL; Anyway, personal preference, not strong opinion. Other than the nit, Reviewed-by: Baoquan He > 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 >