From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 331C635975 for ; Mon, 11 May 2026 14:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778508951; cv=none; b=RYXjKfYZS/kpkc3Jnjpd+vSoDczrCvpo/oURHx1StratYTMG59t7N4HpLYudbSxm3CENBHoOcb2lrjCQNGMeqB9tipLL+KFigk1QpncYUz6kPJwsAmYvH5CXpry2o9w1d6uUsIbp1X/cuHpAbP8qn0D8VTjsfyITfxJgzeYbBTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778508951; c=relaxed/simple; bh=wvrrfCHCNDbI4Ya03VsFIzIC+5b76qItTEXVEUMPUno=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gu9A/is/iTgh3kfqX72Z5PO7fir5U1dJwBC2T9apbaO5jsFJHlHmC67U7I78aUOhhf3BTa34g3AfCItCclSBcvFwqJEto/IXF3usJ9GUP0zS0MNlew2GwHy14n6dKWlm2mVES+ZTB0WrpSmuRfJOdryructu6n5w4kynMvQ/oEM= 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=c29iturH; arc=none smtp.client-ip=91.218.175.173 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="c29iturH" Message-ID: <5f287430-23e0-4a0b-8e5c-5cc94bc28654@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778508948; 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=4tgWK5Wl4FOGJuSNplBMEQ6ddYDQpPafYjZfvqpLPLs=; b=c29iturHuuFzztW4Ip64ftQ5H+zuwPd00Rs40Co2fpPCamyKC42BMhwcWw3EjC1JKMunVT yBBpqjAtyzfx2WH9m3WiIYNsYuSVumwpX5B9RDPpWveRmZHdCwHzPtljvMnnfE+Ia5HB8F 9+9hymIx8GnMIcEvpW1XlHFia5u1Yds= Date: Mon, 11 May 2026 15:15:42 +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> <608bef55-44d1-47f1-a201-4a6bd7be137d@linux.dev> <574fc329-bf2d-4686-9f15-b1709432326e@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: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 11/05/2026 14:44, David Hildenbrand (Arm) wrote: > On 5/11/26 15:42, David Hildenbrand (Arm) wrote: >> On 5/11/26 15:10, Usama Arif wrote: >>> >>> >>> On 11/05/2026 07:36, David Hildenbrand (Arm) wrote: >>>> >>>> >>>> >>>> Hi! >>>> >>>> >>>> Yes, but that's what the users ask for: if there is a chance to deduplicate >>>> memory, it shall be deduplicated asap. >>>> >>>> >>>> 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. >>>> >>>> >>>> Right, but that's what you get with KSM: bad performance if there is a chance to >>>> deduplicate :) >>>> >>>> (and bad performance from scanning overhead) >>>> >>>> >>>> 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. >>>> >>>> >>>> Right, and it makes KSM more THP aware. Which is something I would avoid right now. >>>> >>>> >>>> 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. >> >> IIRC, QEMU will, as default, set MADV_HUGEPAGE and MADV_MERGEABLE :) That is interesting... :) >> >> (KSM itself later has to be enabled manually on a system level) > > Digging around, RHEL documents that one might want to consider disabling THPs > for performance: > > "As KSM can reduce the occurence of transparent huge pages, you may want to > disable it before enabling THP." [1] > > But that doesn't mean that some people are using that combination. > > In the end "some THPs" is better than "no THPs" :) > > [1] > https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-memory-huge_pages > Thanks for sharing this and the link, its very useful.