From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mxct.zte.com.cn (mxct.zte.com.cn [58.251.27.85]) (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 2DBDD32A3F5 for ; Mon, 12 Jan 2026 14:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=58.251.27.85 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768226801; cv=none; b=qmTBdk2lw+qS9T+g8kdCdmMrosWq3La/feXDt5dQ0hBV+5eVfouhDEwdE3hvrgI8COZdOYA5gEPipWvHrEyrhrzXSz1sZLLGzoosjlsl9l26aes/rrTy5Smx0YisK+7BLM6nItXAz7iwHvA3bWVhhJ9R7wqPt9WZ+LJWmGkRXUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768226801; c=relaxed/simple; bh=xRZyn5GiHvqoJ7gnsR/uka8qWEMUPQeWy7tokQvP9cM=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=YFcQwVnkjbi3A8OGzHc77+zpKTsTWZ9W1N56HTVTxTdDz0abnGLoPz7irOkxDseDHimALfXgyJfdsqYXTiIBfAL/DpBfIWkS5MISGk1yO1asIrJ9KB5BsBmnY9UVOHDejzd/PeSDN8hKMC0msvYyd5f61wnoYI+9wDjuMD1cIwA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=58.251.27.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mxde.zte.com.cn (unknown [10.35.20.121]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4dqYsf6yVQzdYJ for ; Mon, 12 Jan 2026 21:59:50 +0800 (CST) Received: from mxhk.zte.com.cn (unknown [192.168.250.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxde.zte.com.cn (FangMail) with ESMTPS id 4dqYsV4K07zBfcWH for ; Mon, 12 Jan 2026 21:59:42 +0800 (CST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4dqYsK1BS8z6Fy68; Mon, 12 Jan 2026 21:59:33 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl1.zte.com.cn with SMTP id 60CDxN6Q091867; Mon, 12 Jan 2026 21:59:23 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp05[null]) by mapi (Zmail) with MAPI id mid32; Mon, 12 Jan 2026 21:59:26 +0800 (CST) X-Zmail-TransId: 2afc6964fe3e1af-29690 X-Mailer: Zmail v1.0 Message-ID: <20260112215926745u6X5PObjPFC-IXAXj0BU-@zte.com.cn> In-Reply-To: <20260112215315996jocrkFSqeYfhABkZxqs4T@zte.com.cn> References: 20260112215315996jocrkFSqeYfhABkZxqs4T@zte.com.cn Date: Mon, 12 Jan 2026 21:59:26 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIDEvMl0ga3NtOiBJbml0aWFsIHRoZSBhZGRyIG9ubHkgb25jZSBpbiBybWFwX3dhbGtfa3Nt?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 60CDxN6Q091867 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SPF: None X-SOURCE-IP: 10.35.20.121 unknown Mon, 12 Jan 2026 21:59:51 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6964FE55.000/4dqYsf6yVQzdYJ From: xu xin This is a minor performance optimization, especially when there are many for-loop iterations, because the addr variable doesn’t change across iterations. Therefore, it only needs to be initialized once before the loop. Signed-off-by: xu xin --- mm/ksm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index cfc182255c7b..335e7151e4a1 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3171,6 +3171,7 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) struct anon_vma *anon_vma = rmap_item->anon_vma; struct anon_vma_chain *vmac; struct vm_area_struct *vma; + unsigned long addr; cond_resched(); if (!anon_vma_trylock_read(anon_vma)) { @@ -3180,16 +3181,16 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) } anon_vma_lock_read(anon_vma); } + + /* Ignore the stable/unstable/sqnr flags */ + addr = rmap_item->address & PAGE_MASK; + anon_vma_interval_tree_foreach(vmac, &anon_vma->rb_root, 0, ULONG_MAX) { - unsigned long addr; cond_resched(); vma = vmac->vma; - /* Ignore the stable/unstable/sqnr flags */ - addr = rmap_item->address & PAGE_MASK; - if (addr < vma->vm_start || addr >= vma->vm_end) continue; /* -- 2.25.1