From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-147.mta1.migadu.com [95.215.58.147]) (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 898F41990C7 for ; Wed, 26 Aug 2026 09:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735458; cv=none; b=J2DLXG+BhXBgSKQjepytiHdhX8jhcYIDHTkAbpX7bPXMBU3opan4E62j0V4wIsyCHbsiJPxeIKRTja2A7oMnnmWyVj9yPgKhWtuCuKEc4/OxWNd49DtpGMz+dy183CMKpgmQAcuHGVdCbhsU7FS8ezzwgvMWGE0f7tFTkK078v8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735458; c=relaxed/simple; bh=LpyoEPH8E0Gsq814oLQU/XuDIOiTR9inNMFtgsjW038=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jo1o9/tbhXmJLM1GJI5Mqd40T/uRKU5wH1YGSzIh7jDmhNl1ECF35TkJnWONmxDbkrhO2nIHDPzplBSwH9zb8v6mv6xlAG+hLVU+96uijH1C31woWwabUcCiNWRZXdnJUQfcuD4gBUXCzAXpcI9QJJfpccHfizbr49wtBlc7uUc= 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=XZSGheTd; arc=none smtp.client-ip=95.215.58.147 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="XZSGheTd" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=LpyoEPH8E0Gsq814oLQU/XuDIOiTR9inNMFtgsjW038=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787735454; v=1; x=1788340254; b=XZSGheTd7/73ZHpOCk+8l9mSbuxwGDEsVP50czQPk0YPXgLNak3Vzb9sv3P8YSYmekwivozM VQfFlQq9HjLZFwP/ijQ8Cb99zTC3GBcu1xZJLidjJbX531EXV6c7l8XJnet9Pl4eg8ODeJJ7DkF A1DAV4ILa3zoscivJApJpOAU= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost (223.70.159.239) by mta10.migadu.com with ESMTPS id e9f1f6d0c26bd38a; Wed, 26 Aug 2026 09:10:54 +0000 X-Mizu-Trace-ID: e9f1f6d0c26bd38a X-Migadu-Flow: FLOW_OUT Date: Wed, 26 Aug 2026 17:10:47 +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 2/6] mm/mglru: batch update lrugen->protected in inc_min_seq() Message-ID: References: <20260821102538.22642-1-baohua@kernel.org> <20260821102538.22642-3-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-3-baohua@kernel.org> On 08/21/26 at 06:25pm, Barry Song (Xiaomi) wrote: > Avoid updating lrugen->protected with WRITE_ONCE() for each folio, > which may prevent potential compiler optimizations. Accumulate the > updates locally and apply them in a batch instead. Wondering how much efficiency this can bring, is there a number for this standalone patch? > > Signed-off-by: Barry Song (Xiaomi) > --- > mm/vmscan.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 0d74fc00abd3..99ee3c833d54 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -3931,7 +3931,7 @@ 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 *head = &lrugen->folios[old_gen][type][zone]; > - unsigned long delta = 0; > + unsigned long protected[MAX_NR_TIERS] = {}, delta = 0; > > while (!list_empty(head)) { > struct folio *folio = lru_to_folio(head); > @@ -3953,8 +3953,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) > if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) { > int tier = lru_tier_from_refs(refs, workingset); > > - WRITE_ONCE(lrugen->protected[hist][type][tier], > - lrugen->protected[hist][type][tier] + nr_pages); > + protected[tier] += nr_pages; > } > > if (!--remaining) > @@ -3964,6 +3963,9 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) > lrugen->nr_pages[old_gen][type][zone] - delta); > WRITE_ONCE(lrugen->nr_pages[target_gen][type][zone], > lrugen->nr_pages[target_gen][type][zone] + delta); > + for (int tier = 0; tier < MAX_NR_TIERS; tier++) > + WRITE_ONCE(lrugen->protected[hist][type][tier], > + lrugen->protected[hist][type][tier] + protected[tier]); > if (!remaining) > return false; > } > -- > 2.34.1 >