From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F657C282EC for ; Tue, 18 Mar 2025 19:13:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3322280002; Tue, 18 Mar 2025 15:13:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBBF5280001; Tue, 18 Mar 2025 15:13:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE650280002; Tue, 18 Mar 2025 15:13:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 97B55280001 for ; Tue, 18 Mar 2025 15:13:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AAEB11CA072 for ; Tue, 18 Mar 2025 19:13:13 +0000 (UTC) X-FDA: 83235619866.21.DDEFDA5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 150961C0017 for ; Tue, 18 Mar 2025 19:13:10 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Jtn9atfJ; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742325191; a=rsa-sha256; cv=none; b=IT5Bskm29vhapjXJ1Dy04rTgm5D8KHORu4rcgYUFOMs/KWKnU7tlkaZJRA4Qj6qUQOzBWv 5pme+E7mQWayu0hrQEYFGPl57qE2BnypUdSLW63QsBWVQ11bWVANfdp+7D0yOoEcbFHxGS TULU8ubaYPsqhDspgJNI5JRGuk1RUc8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Jtn9atfJ; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742325191; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4U0PC1ZqWLnd1as/CRjWt1nsYHzHAjrFR54RXgAiwy4=; b=q2kwrofKgsD4lvlcttY227HPAxgYcXXtC8us4o2tiqfb/9kthjamRvI5ZxBndkz3iMPf50 C9eGJYzLKg4BU9soeEQHeihwu44TDuOqUiOxf2c9Il07pPwOgjqvIgCisi2DFsh3zV0AjF JZg381aiBEbuYIivBYnn7eCBLMRp4kw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742325190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=4U0PC1ZqWLnd1as/CRjWt1nsYHzHAjrFR54RXgAiwy4=; b=Jtn9atfJzate9izF+MYmSldYf5cUxo8bBAbSv9vxxC1ysp/YxtZkrpmQmvGieD0GekBidw JG5HwcNqtdQ0kvMpDJ8qWfkeponoM3V1obyO3X7zD01O+3N+tQtonI0bt+dzmsYIL+btR4 BScXZUP7T8WOgmy/HDjZ+QFcpqXvIUQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-WCnfBmrOMa6resp5HYDamw-1; Tue, 18 Mar 2025 15:13:09 -0400 X-MC-Unique: WCnfBmrOMa6resp5HYDamw-1 X-Mimecast-MFC-AGG-ID: WCnfBmrOMa6resp5HYDamw_1742325188 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43cf172ff63so23408955e9.3 for ; Tue, 18 Mar 2025 12:13:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742325188; x=1742929988; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4U0PC1ZqWLnd1as/CRjWt1nsYHzHAjrFR54RXgAiwy4=; b=JG/xtk2iHA7uA0X9DWRBqNLP8ygYOqUqTv3DU8/asUAA1pTZYtrmM57dMnSP717YBz HocX0Uhl4O74radu/UTxZKi6v4ZoRzmWbESn5m7+E/j4g6tDkkaKq46YUmsx8jMN7Ys7 G7yU2KqImkg/tEL8NNk3z4GWrej4E7zXSIlvpTDxA/zNtyel2YGURTp+nWJGpMF+mL/Z NfZRuPv4LX91KPhqWY8LgMR1FeSYgbH0gX9Miv2+PpOy/d58uBxcDUZf17VBs7Dsf7WO b9HKIMsdxSY7NVfydy5eiBztr7cj0SbUfWSHSNTPQbf2ME2Ymg4ZfEXDsd3ublMg0hl7 1GpQ== X-Forwarded-Encrypted: i=1; AJvYcCX3UfI9/S9cNGtcUOAxxLR6PhZXoP+h9KKTF5JwOvIgEL+FUMZn/fVx7jtMwGx3AaletiyB6/qSaw==@kvack.org X-Gm-Message-State: AOJu0YxlWvp+6mHryKsl3MYDalAME5Om3X49uM12D8Dd9NxtHeg8THmp nC6drk4OXjBSh+YwJjU5qLA9F+i90y9szuWsuGfydHJ0+5dAS0c8TFqV0fwS3KBeGTuIWUgFVC6 oZgOClEvFzFVO2QZdu636gXMEmBmGdoyMXoBTsCI6i4ZOjSp1 X-Gm-Gg: ASbGnculgy4Hemeho+nzsdcXfpn6M1yMBcrmzsd+5R+EP2r+ljds2fvejrs4MYZ3ftm +bNoFWjJfG31bpFfENGOxmVj+oVtGiPaZfOrObOV/Kcjyrf7pWXoB6mSvpGiliNneMyr5XwPltC og8p85KfGcUBz7lNU0OU6Fq/1MgX1dkWmq8DskT8BXJ5B2ltr3CO7A/UM1XncmG0GwUqrlbSSdx uhvLaRXV+NNUZQaGKnhC3zbDDSSxe71YB0RazQHjKA32vVlc/I934Ec4dQIYBF3fX49sExlK7FR ShdzNV6a494Ce0OdTvHTGZrYEsZ3Hh2hkHmemTlINqpLlQ3HzppWa+4KefTV+Ao5wuzNoXzJUk9 4uY1XNU9rW4LjGX+R6OJzPJsrR0DgdWo9WBkPLkp8H/w= X-Received: by 2002:a05:600c:4687:b0:43b:cc42:c54f with SMTP id 5b1f17b1804b1-43d3b98e60dmr37177925e9.14.1742325187762; Tue, 18 Mar 2025 12:13:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4Gap2yhS3UBNY8mODOlsiGBVyg/wtOuAtDubOQetvtdbroh57+tstnim13R32dNyYOUaPdg== X-Received: by 2002:a05:600c:4687:b0:43b:cc42:c54f with SMTP id 5b1f17b1804b1-43d3b98e60dmr37177585e9.14.1742325187278; Tue, 18 Mar 2025 12:13:07 -0700 (PDT) Received: from ?IPV6:2003:cb:c72d:2500:94b5:4b7d:ad4a:fd0b? (p200300cbc72d250094b54b7dad4afd0b.dip0.t-ipconnect.de. [2003:cb:c72d:2500:94b5:4b7d:ad4a:fd0b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1ffb62c1sm142728765e9.4.2025.03.18.12.13.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Mar 2025 12:13:06 -0700 (PDT) Message-ID: <7c86c45c-17e4-4e9b-8d80-44fdfd37f38b@redhat.com> Date: Tue, 18 Mar 2025 20:13:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v1 0/5] KVM: gmem: 2MB THP support and preparedness tracking changes To: Yan Zhao , "Shah, Amit" , "kvm@vger.kernel.org" , "Roth, Michael" , "liam.merwick@oracle.com" , "seanjc@google.com" , "jroedel@suse.de" , "linux-mm@kvack.org" , "Sampat, Pratik Rajesh" , "linux-kernel@vger.kernel.org" , "Lendacky, Thomas" , "vbabka@suse.cz" , "pbonzini@redhat.com" , "linux-coco@lists.linux.dev" , "quic_eberman@quicinc.com" , "Kalra, Ashish" , "ackerleytng@google.com" , "vannapurve@google.com" References: <20241212063635.712877-1-michael.roth@amd.com> <11280705-bcb1-4a5e-a689-b8a5f8a0a9a6@redhat.com> <3bd7936624b11f755608b1c51cc1376ebf2c3a4f.camel@amd.com> <6e55db63-debf-41e6-941e-04690024d591@redhat.com> <18db10a0-bd40-4c6a-b099-236f4dcaf0cf@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB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T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ynLRzuFlGzIbbp7b4vdFfwvWtIsNR0ezUlQVlsFVU1k_1742325188 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspam-User: X-Stat-Signature: 775i4dznu53mkg3zgfn63qhcekehmap3 X-Rspamd-Queue-Id: 150961C0017 X-HE-Tag: 1742325190-890929 X-HE-Meta: U2FsdGVkX18uzv7eCDPAeayGbK/2ewn+bWmpOulVoYLOibIXob7g4WPFy2cRlBvQGbeJOhAvyxx5gbx6SfupVKOXkdiaPOtZVYftOwqqQDiZrBpSBUjgC3hD6M/OYf5u6sU9UQRWdC/7qzuenPQ2+bHACY7N/qlvgQQI7wf1B0sDCcG/5VafVBX67g4kvLLQObCgS9mnDmBbokq/q5rXsgRqmR3EfdiTv/d4EJ/f2kxkxxRM/yyfuLeZCHRxK8AKlclz4vqrop9U1cigbC2AGQqJesCO7SOoAIXkXXiuEtu64P1f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JsV4a4GxyJ6mO+qEvIZRoGTU6h1qx/DNyhKQyvPywV/wB55qBJ+m6qNvf3KOT6nS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 18.03.25 03:24, Yan Zhao wrote: > On Fri, Mar 14, 2025 at 07:19:33PM +0800, Yan Zhao wrote: >> On Fri, Mar 14, 2025 at 10:33:07AM +0100, David Hildenbrand wrote: >>> On 14.03.25 10:09, Yan Zhao wrote: >>>> On Wed, Jan 22, 2025 at 03:25:29PM +0100, David Hildenbrand wrote: >>>>> (split is possible if there are no unexpected folio references; private >>>>> pages cannot be GUP'ed, so it is feasible) >>>> ... >>>>>>> Note that I'm not quite sure about the "2MB" interface, should it be >>>>>>> a >>>>>>> "PMD-size" interface? >>>>>> >>>>>> I think Mike and I touched upon this aspect too - and I may be >>>>>> misremembering - Mike suggested getting 1M, 2M, and bigger page sizes >>>>>> in increments -- and then fitting in PMD sizes when we've had enough of >>>>>> those. That is to say he didn't want to preclude it, or gate the PMD >>>>>> work on enabling all sizes first. >>>>> >>>>> Starting with 2M is reasonable for now. The real question is how we want to >>>>> deal with >>>> Hi David, >>>> >>> >>> Hi! >>> >>>> I'm just trying to understand the background of in-place conversion. >>>> >>>> Regarding to the two issues you mentioned with THP and non-in-place-conversion, >>>> I have some questions (still based on starting with 2M): >>>> >>>>> (a) Not being able to allocate a 2M folio reliably >>>> If we start with fault in private pages from guest_memfd (not in page pool way) >>>> and shared pages anonymously, is it correct to say that this is only a concern >>>> when memory is under pressure? >>> >>> Usually, fragmentation starts being a problem under memory pressure, and >>> memory pressure can show up simply because the page cache makes us of as >>> much memory as it wants. >>> >>> As soon as we start allocating a 2 MB page for guest_memfd, to then split it >>> up + free only some parts back to the buddy (on private->shared conversion), >>> we create fragmentation that cannot get resolved as long as the remaining >>> private pages are not freed. A new conversion from shared->private on the >>> previously freed parts will allocate other unmovable pages (not the freed >>> ones) and make fragmentation worse. >> Ah, I see. The problem of fragmentation is because memory allocated by >> guest_memfd is unmovable. So after freeing part of a 2MB folio, the whole 2MB is >> still unmovable. >> >> I previously thought fragmentation would only impact the guest by providing no >> new huge pages. So if a confidential VM does not support merging small PTEs into >> a huge PMD entry in its private page table, even if the new huge memory range is >> physically contiguous after a private->shared->private conversion, the guest >> still cannot bring back huge pages. >> >>> In-place conversion improves that quite a lot, because guest_memfd tself >>> will not cause unmovable fragmentation. Of course, under memory pressure, >>> when and cannot allocate a 2M page for guest_memfd, it's unavoidable. But >>> then, we already had fragmentation (and did not really cause any new one). >>> >>> We discussed in the upstream call, that if guest_memfd (primarily) only >>> allocates 2M pages and frees 2M pages, it will not cause fragmentation >>> itself, which is pretty nice. >> Makes sense. >> >>>> >>>>> (b) Partial discarding >>>> For shared pages, page migration and folio split are possible for shared THP? >>> >>> I assume by "shared" you mean "not guest_memfd, but some other memory we use >> Yes, not guest_memfd, in the case of non-in-place conversion. >> >>> as an overlay" -- so no in-place conversion. >>> >>> Yes, that should be possible as long as nothing else prevents >>> migration/split (e.g., longterm pinning) >>> >>>> >>>> For private pages, as you pointed out earlier, if we can ensure there are no >>>> unexpected folio references for private memory, splitting a private huge folio >>>> should succeed. >>> >>> Yes, and maybe (hopefully) we'll reach a point where private parts will not >>> have a refcount at all (initially, frozen refcount, discussed during the >>> last upstream call). >> Yes, I also tested in TDX by not acquiring folio ref count in TDX specific code >> and found that partial splitting could work. >> >>> Are you concerned about the memory fragmentation after repeated >>>> partial conversions of private pages to and from shared? >>> >>> Not only repeated, even just a single partial conversion. But of course, >>> repeated partial conversions will make it worse (e.g., never getting a >>> private huge page back when there was a partial conversion). >> Thanks for the explanation! >> >> Do you think there's any chance for guest_memfd to support non-in-place >> conversion first? > e.g. we can have private pages allocated from guest_memfd and allows the > private pages to be THP. > > Meanwhile, shared pages are not allocated from guest_memfd, and let it only > fault in 4K granularity. (specify it by a flag?) > > When we want to convert a 4K from a 2M private folio to shared, we can just > split the 2M private folio as there's no extra ref count of private pages; Yes, IIRC that's precisely what this series is doing, because the ftruncate() will try splitting the folio (which might still fail on speculative references, see my comment as rely to this series) In essence: yes, splitting to 4k should work (although speculative reference might require us to retry). But the "4k hole punch" is the ugly it. So you really want in-place conversion where the private->shared will split (but not punch) and the shared->private will collapse again if possible. > > when we do shared to private conversion, no split is required as shared pages > are in 4K granularity. And even if user fails to specify the shared pages as > small pages only, the worst thing is that a 2M shared folio cannot be split, and > more memory is consumed. > > Of couse, memory fragmentation is still an issue as the private pages are > allocated unmovable. Yes, and that you will never ever get a "THP" back when there was a conversion from private->shared of a single page that split the THP and discarded that page. But do you think it's a good simpler start before in-place > conversion is ready? There was a discussion on that on the bi-weekly upstream meeting on February the 6. The recording has more details, I summarized it as "David: Probably a good idea to focus on the long-term use case where we have in-place conversion support, and only allow truncation in hugepage (e.g., 2 MiB) size; conversion shared<->private could still be done on 4 KiB granularity as for hugetlb." In general, I think our time is better spent working on the real deal than on interim solutions that should not be called "THP support". -- Cheers, David / dhildenb