From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 836F937B027 for ; Mon, 11 May 2026 13:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778505047; cv=none; b=f7fWckpKRVLbsZmGDQ0bmXzHAFTiIAmcLz3wvSRCI7LS2J8WHEn+CWHd/iFBp4otdaBCwgFqVjqCctBYUMGhYOm7RJ9jBw3KDMpCbbyd/H3Js4sEY1gdSAUc6lONYyCil9ciakLqooIPL2Ygu/rLyfSHmICeMt+dzBGIZaeOTZ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778505047; c=relaxed/simple; bh=jiB82wqFQavCdB0M+kxK5ONrboC9lUFZYNSOmE8OQkk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EWAhOOf7udN8Psk2a6ggj08wS8jdasNqHsC5wmPd+4QnzXB4U5lkJPuBvQzH+tWx3WI3KitX1QOzJRgPgH0GyjBUnaN+BfAZnOraXGZuEhPsaZvTqLPmJvA2xxEaxep5u6bwQitzbXVEOsir0Okp6Ps8TkKeW0mdusZwExL2Ets= 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=ZY1pwzch; arc=none smtp.client-ip=95.215.58.188 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="ZY1pwzch" Message-ID: <608bef55-44d1-47f1-a201-4a6bd7be137d@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778505042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C0vj1B2qhWjl7qdvd6qJ1lPZrCOqEZMovr4s8JyrlRQ=; b=ZY1pwzch3L3vJXvoGmjSkcSpbjheRUvps3yGipce8MPxDZtjdD+UHs01TPn/IYSOMcVRgI IyXvBv3zu/Dv9ChCjLZ8ZB1CJAhMmLF5TXeCZPdzb9ikA5kG2f6n90dw7R/goyDG+35qXe G22Ax3ci2z+5YkbToX8B0ezgY0lQpBY= Date: Mon, 11 May 2026 14:10:35 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC] mm: restrict zero-page remapping to underused THP splits To: "David Hildenbrand (Arm)" Cc: Nico Pache , linux-mm@kvack.org, linux-kernel@vger.kernel.org, yuzhao@google.com, usamaarif642@gmail.com, lance.yang@linux.dev, baohua@kernel.org, dev.jain@arm.com, ryan.roberts@arm.com, liam@infradead.org, baolin.wang@linux.alibaba.com, ziy@nvidia.com, ljs@kernel.org, akpm@linux-foundation.org References: <20260510114001.600681-1-usama.arif@linux.dev> <8838114e-5b6a-4f3d-932c-9e97e51216ae@kernel.org> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: <8838114e-5b6a-4f3d-932c-9e97e51216ae@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 11/05/2026 07:36, David Hildenbrand (Arm) wrote: > >>> >>> I tend to like (2), and maybe (3) on top. Opinions? >>> >> >> Hello! > > > Hi! > >> >> I think (3) definitely makes sense. >> >> I have not had a deep look at KSM up until just now, so might be dumb >> to say all of below.. :) >> >> What I see is that KSM scans THPs as 512 individual 4K subpages and splits the >> THP whenever it actually wants to merge a single 4K chunk. That seems like a >> lot of work for a single 4K? > > Yes, but that's what the users ask for: if there is a chance to deduplicate > memory, it shall be deduplicated asap. > >> >> One thing that came to my mind is to have a separate tree for THPs and only >> merge the THPs that have the same content, but the possibility of encoutering >> 2M pages with same content is extremely low? so this is probably a bad idea. > > Right, the probability is low, and it would change existing semantics, breaking > existing users. > > In addition, we would have to add large folio support for KSM, which I rather > would avoid. > >> >> An alternative is, does it even make sense to process and split THPs by KSM >> in the way it works now? IMO this is a lot of work for a single 4K merge. >> Shrinker is designed to release memory when its needed, i.e. reclaim, at >> which point IMO free memory is more important than performance. But KSM runs >> all the time.. so constantly splitting THPs everytime a single 4K can be >> merged just hurts performance all the time. > > Right, but that's what you get with KSM: bad performance if there is a chance to > deduplicate :) > > (and bad performance from scanning overhead) > >> If someone cares about memory, >> they should be running the shrinker. > > It's not just the zero page, but really any page content. The zero page is > currently only "special" after we added conditional support to deduplicate to > the shared zeropage in KSM. The shrinker doesn't help for any other page content > besides zero-filled. > > Further, the shrinker is something system-wide, whereby KSM is usually only > enabled for selected VMAs (with some exceptions nowadays). > > Also note that KSM deduplicates independent of the folio size: not just THPs, > but really any (large) folio. Yes, it splits large folios, but that's really > just to keep the T in THP. > >> Is a better alternative that KSM skips >> THPs, THP shrinker splits THPs into 4K subpages when memory is needed, and >> only then KSM gets those 4K subpages? >> >> Above sounds like reworking KSM, but just wanted to put it out there. > > Right, and it makes KSM more THP aware. Which is something I would avoid right now. > >> >> (2) + (3) sounds like a good solution, but I wonder if above alternative >> of KSM just skipping THPs might be better? > > That would change the semantics where, for example, where we expect that memory > was deduplicated after a KSM run. > > VMs (where KSM is usually employed) are expected to be mostly backed by THPs: > except where we can deduplicate memory. Skipping THPs would essentially break > the main use case for KSM :) > > Does that make sense? > Yes, all of above makes sense. But I feel like this means someone should not set THP policy to always and enable KSM together. In general I feel like KSM is not something that should be run on big servers, as hopefully you are not managing memory as 4K chunks for big machines and using a lot of THPs.