From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 61C2620E702 for ; Sun, 5 Apr 2026 21:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775422893; cv=none; b=egvEY3De8LcJxxGjuMMdSmRjR1GYqmOCkyD3j56HupTe30WcUOGzTEhCCKqPBzaB/CsIFzsKxDTYPepv2SVGzclflZyY+mxxpt5PlC/8hLRkLb54yuaDyxqI6W3mx+/GLkZQR8wAK/h+QCDqgFNZMhOo+ZPGhN0HjP44p18qlw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775422893; c=relaxed/simple; bh=oFxLOMzSfEmFuQzpbU2wJsRXZ/L4FJB5kjwFD8u82vI=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=djFfPsznbNuDATMSlINq7IJgXVdJG5MKMevkAXqaSjAdSvYN7YUZEJPvexMRCekSGYufiCWwBsz5YTlWDq3gzdifdH1tek4fS9SWVajgXaYMjNPttixmBlPl+FDfBjsbMJHU2DbNEK3ek6NmmMQb4YRcqNcVqw59vao8YVR8bsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=WAiib2j4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="WAiib2j4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE279C116C6; Sun, 5 Apr 2026 21:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1775422893; bh=oFxLOMzSfEmFuQzpbU2wJsRXZ/L4FJB5kjwFD8u82vI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WAiib2j4dceJ0uQ6xwL4ELoWHNM3mk0p6lKI3lcYW3qRukS3sgrwt4wlrfBcwN6m+ P/uk3Ur9qCeFo29pVB5J9R7WvkGxVPrT6hI/BzSTeXbDNEsvRr+QY5uPinFM5OOaFi uKp6uh+6wiYXfB1ptl0Mr/ddZSHIb1si9yBC9/rs= Date: Sun, 5 Apr 2026 14:01:32 -0700 From: Andrew Morton To: Hugh Dickins Cc: xu.xin16@zte.com.cn, david@kernel.org, chengming.zhou@linux.dev, wang.yaxin@zte.com.cn, yang.yang29@zte.com.cn, Michel Lespinasse , Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] ksm: Optimize rmap_walk_ksm by passing a suitable address range Message-Id: <20260405140132.3a518740c6c1d68843f44aaf@linux-foundation.org> In-Reply-To: <02e1b8df-d568-8cbb-b8f6-46d5476d9d75@google.com> References: <20260212193045556CbzCX8p9gDu73tQ2nvHEI@zte.com.cn> <02e1b8df-d568-8cbb-b8f6-46d5476d9d75@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Sat, 4 Apr 2026 21:44:14 -0700 (PDT) Hugh Dickins wrote: > This is a very attractive speedup, but I believe it's flawed: in the > special case when a range has been mremap-moved, when its anon folio > indexes and anon_vma pgoff correspond to the original user address, > not to the current user address. > > In which case, rmap_walk_ksm() will be unable to find all the PTEs > for that KSM folio, which will consequently be pinned in memory - > unable to be reclaimed, unable to be migrated, unable to be hotremoved, > until it's finally unmapped or KSM disabled. > > But it's years since I worked on KSM or on anon_vma, so I may be confused > and my belief wrong. I have tried to test it, and my testcase did appear > to show 7.0-rc6 successfully swapping out even mremap-moved KSM folios, > but mm.git failing to do so. However, I say "appear to show" because I > found swapping out any KSM pages harder than I'd been expecting: so have > some doubts about my testing. Let me give more detail on that at the > bottom of this mail: it's a tangent which had better not distract from > your speedup. > > If I'm right that your patch is flawed, what to do? Thanks, Hugh. Administreevia: I've removed this patch from the mm-stable branch and I reworked its [1/2] "ksm: initialize the addr only once in rmap_walk_ksm" to be presented as a singleton patch. For now I've restaged this patch ("ksm: optimize rmap_walk_ksm by passing a suitable address range") at the tail of the mm-unstable branch and I'll enter wait-and-see mode.