From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 EDFCE1BEF8C for ; Thu, 31 Jul 2025 16:15:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753978557; cv=none; b=s5zdxr8upn9rBGJZrZoZZvWtKY6Sgs3Xw8tDtIfPw6i22OvuljQv/6U6F3r5eorh650kv1Mw6G1DkS5yisCSS27pAz+S3LJnbz/O+enjunnf/aHqMRLhflOrQcYXv8sgFTNVtWOodKHBG0VZqFZfRcteqKziW4FvkBAW2PgCmQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753978557; c=relaxed/simple; bh=NmK9mpCX/2zw5F1BJI2dwZwnnUGC/SRcSDSLx0fItOM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QJUWKabTyVIkIpNO2GxE5q66GSuzgY6vEg8lDboVYjGdjp6L8t8GoFFEcHHqbXK9ZfO4c4lcoSFpfjf5oPcSt82bzecT2KQoevZLch93mtJeSs7jqlOIUK0DDreVptOYFoajb+/LtIqR32Jp6tcUPJ39DpSzbmjcSqhdmWG03j4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LneAwPwI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LneAwPwI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753978554; 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:autocrypt:autocrypt; bh=hCFMEvUPyBLrGC/oYDfyk4mKEAk9olU5xdsqV7nWMUs=; b=LneAwPwISKHlP6XJAWgFp+eWDM1nPzKdcFwAahaBGb57ef74fsEyKimiZjS5qQUDAXGDSJ uE745rtun9Xs5uQr4Av+MKJdz5LgBTmLd/U+xb93YoEpuFWzKAwVSN1m8WYQC0S6NOLPu6 pUbPUbF6MM5bXwaFljylIQ/XdkQxVHs= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-acNwzezIN8mbtg3rLkVnnA-1; Thu, 31 Jul 2025 12:15:40 -0400 X-MC-Unique: acNwzezIN8mbtg3rLkVnnA-1 X-Mimecast-MFC-AGG-ID: acNwzezIN8mbtg3rLkVnnA_1753978539 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3b79629bd88so328545f8f.0 for ; Thu, 31 Jul 2025 09:15:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753978539; x=1754583339; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=hCFMEvUPyBLrGC/oYDfyk4mKEAk9olU5xdsqV7nWMUs=; b=KQYnH1FtPjeyQVl3xIwxpkeJCbE/telpC9CuBR34EkGcJzJAMZ9/bs7ueLmp4xa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a4:fbaf:749e with SMTP id ffacd0b85a97d-3b7950065fdmr6170028f8f.49.1753978538685; Thu, 31 Jul 2025 09:15:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGytZULQmZ/hDajIkM/Htt7MthdICmHyxaaQPthRUhPkwjUZgExKSH13cnPbk4HyFbkpq+P8Q== X-Received: by 2002:a5d:5f90:0:b0:3a4:fbaf:749e with SMTP id ffacd0b85a97d-3b7950065fdmr6169988f8f.49.1753978538121; Thu, 31 Jul 2025 09:15:38 -0700 (PDT) Received: from ?IPV6:2003:d8:2f44:3700:be07:9a67:67f7:24e6? (p200300d82f443700be079a6767f724e6.dip0.t-ipconnect.de. [2003:d8:2f44:3700:be07:9a67:67f7:24e6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c4a6f62sm2778077f8f.73.2025.07.31.09.15.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Jul 2025 09:15:37 -0700 (PDT) Message-ID: <09acd558-19b9-4964-823b-502b9044f954@redhat.com> Date: Thu, 31 Jul 2025 18:15:35 +0200 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/5] mm/huge_memory: convert "tva_flags" to "enum tva_type" for thp_vma_allowable_order*() To: Lorenzo Stoakes , Usama Arif Cc: Andrew Morton , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, corbet@lwn.net, rppt@kernel.org, surenb@google.com, mhocko@suse.com, hannes@cmpxchg.org, baohua@kernel.org, shakeel.butt@linux.dev, riel@surriel.com, ziy@nvidia.com, laoar.shao@gmail.com, dev.jain@arm.com, baolin.wang@linux.alibaba.com, npache@redhat.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, vbabka@suse.cz, jannh@google.com, Arnd Bergmann , sj@kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kernel-team@meta.com References: <20250731122825.2102184-1-usamaarif642@gmail.com> <20250731122825.2102184-3-usamaarif642@gmail.com> From: David Hildenbrand Content-Language: en-US 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 WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAmgsLPQFCRvGjuMACgkQTd4Q 9wD/g1o0bxAAqYC7gTyGj5rZwvy1VesF6YoQncH0yI79lvXUYOX+Nngko4v4dTlOQvrd/vhb 02e9FtpA1CxgwdgIPFKIuXvdSyXAp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HZiaeYtFOujp5n+pjBaQK7wUUjDilPQ5QMzIuCL4YjVoylWiBNknvQWBXS lQCWmavOT9sttGQXdPCC5ynI+1ymZC1ORZKANLnRAb0NH/UCzcsstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCaCwtJQUJG8aPFAAKCRBN3hD3AP+DWlDnD/4k2TW+HyOOOePVm23F5HOhNNd7nNv3 Vq2cLcW1DteHUdxMO0X+zqrKDHI5hgnE/E2QH9jyV8mB8l/ndElobciaJcbl1cM43vVzPIWn 01vW62oxUNtEvzLLxGLPTrnMxWdZgxr7ACCWKUnMGE2E8eca0cT2pnIJoQRz242xqe/nYxBB /BAK+dsxHIfcQzl88G83oaO7vb7s/cWMYRKOg+WIgp0MJ8DO2IU5JmUtyJB+V3YzzM4cMic3 bNn8nHjTWw/9+QQ5vg3TXHZ5XMu9mtfw2La3bHJ6AybL0DvEkdGxk6YHqJVEukciLMWDWqQQ RtbBhqcprgUxipNvdn9KwNpGciM+hNtM9kf9gt0fjv79l/FiSw6KbCPX9b636GzgNy0Ev2UV m00EtcpRXXMlEpbP4V947ufWVK2Mz7RFUfU4+ETDd1scMQDHzrXItryHLZWhopPI4Z+ps0rB CQHfSpl+wG4XbJJu1D8/Ww3FsO42TMFrNr2/cmqwuUZ0a0uxrpkNYrsGjkEu7a+9MheyTzcm vyU2knz5/stkTN2LKz5REqOe24oRnypjpAfaoxRYXs+F8wml519InWlwCra49IUSxD1hXPxO WBe5lqcozu9LpNDH/brVSzHCSb7vjNGvvSVESDuoiHK8gNlf0v+epy5WYd7CGAgODPvDShGN g3eXuA== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 31.07.25 16:00, Lorenzo Stoakes wrote: > On Thu, Jul 31, 2025 at 01:27:19PM +0100, Usama Arif wrote: >> From: David Hildenbrand >> >> Describing the context through a type is much clearer, and good enough >> for our case. Just for the other patch, I'll let Usama take it from here, just a bunch of comments. > > This is pretty bare bones. What context, what type? Under what > circumstances? > > This also is missing detail on the key difference here - that actually it > turns out we _don't_ need these to be flags, rather we can have _distinct_ > modes which are clearer. > > I'd say something like: > > when determining which THP orders are eligiible for a VMA mapping, > we have previously specified tva_flags, however it turns out it is > really not necessary to treat these as flags. > > Rather, we distinguish between distinct modes. > > The only case where we previously combined flags was with > TVA_ENFORCE_SYSFS, but we can avoid this by observing that this is > the default, except for MADV_COLLAPSE or an edge cases in > collapse_pte_mapped_thp() and hugepage_vma_revalidate(), and adding > a mode specifically for this case - TVA_FORCED_COLLAPSE. > > ... stuff about the different modes... > >> >> We have: >> * smaps handling for showing "THPeligible" >> * Pagefault handling >> * khugepaged handling >> * Forced collapse handling: primarily MADV_COLLAPSE, but one other odd case > > Can we actually state what this case is? I mean I guess a handwave in the > form of 'an edge case in collapse_pte_mapped_thp()' will do also. Yeah, something like that. I think we also call it when we previously checked that there is a THP and that we might be allowed to collapse. E.g., collapse_pte_mapped_thp() is also called from khugepaged code where we already checked the allowed order. > > Hmm actually we do weird stuff with this so maybe just handwave. > > Like uprobes calls collapse_pte_mapped_thp()... :/ I'm not sure this 'If we > are here, we've succeeded in replacing all the native pages in the page > cache with a single hugepage.' comment is even correct. I think in all these cases we already have a THP and want to force that collapse in the page table. [...] >> >> Really, we want to ignore sysfs only when we are forcing a collapse >> through MADV_COLLAPSE, otherwise we want to enforce. > > I'd say 'ignoring this edge case, ...' > > I think the clearest thing might be to literally list the before/after > like: > > * TVA_SMAPS | TVA_ENFORCE_SYSFS -> TVA_SMAPS > * TVA_IN_PF | TVA_ENFORCE_SYSFS -> TVA_PAGEFAULT > * TVA_ENFORCE_SYSFS -> TVA_KHUGEPAGED > * 0 -> TVA_FORCED_COLLAPSE > That makes sense. >> >> With this change, we immediately know if we are in the forced collapse >> case, which will be valuable next. >> >> Signed-off-by: David Hildenbrand >> Acked-by: Usama Arif >> Signed-off-by: Usama Arif > > Overall this is a great cleanup, some various nits however. > >> --- >> fs/proc/task_mmu.c | 4 ++-- >> include/linux/huge_mm.h | 30 ++++++++++++++++++------------ >> mm/huge_memory.c | 8 ++++---- >> mm/khugepaged.c | 18 +++++++++--------- >> mm/memory.c | 14 ++++++-------- >> 5 files changed, 39 insertions(+), 35 deletions(-) >> >> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c >> index 3d6d8a9f13fc..d440df7b3d59 100644 >> --- a/fs/proc/task_mmu.c >> +++ b/fs/proc/task_mmu.c >> @@ -1293,8 +1293,8 @@ static int show_smap(struct seq_file *m, void *v) >> __show_smap(m, &mss, false); >> >> seq_printf(m, "THPeligible: %8u\n", >> - !!thp_vma_allowable_orders(vma, vma->vm_flags, >> - TVA_SMAPS | TVA_ENFORCE_SYSFS, THP_ORDERS_ALL)); >> + !!thp_vma_allowable_orders(vma, vma->vm_flags, TVA_SMAPS, >> + THP_ORDERS_ALL)); > > This !! is so gross, wonder if we could have a bool wrapper. But not a big > deal. > > I also sort of _hate_ the smaps flag anyway, invoking this 'allowable > orders' thing just for smaps reporting with maybe some minor delta is just > odd. > > Something like `bool vma_has_thp_allowed_orders(struct vm_area_struct > *vma);` would be nicer. > > Anyway thoughts for another time... :) Yeah, that's not the only nasty bit here ... :) > >> >> if (arch_pkeys_enabled()) >> seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); >> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >> index 71db243a002e..b0ff54eee81c 100644 >> --- a/include/linux/huge_mm.h >> +++ b/include/linux/huge_mm.h >> @@ -94,12 +94,15 @@ extern struct kobj_attribute thpsize_shmem_enabled_attr; >> #define THP_ORDERS_ALL \ >> (THP_ORDERS_ALL_ANON | THP_ORDERS_ALL_SPECIAL | THP_ORDERS_ALL_FILE_DEFAULT) >> >> -#define TVA_SMAPS (1 << 0) /* Will be used for procfs */ > > Dumb question, but what does 'TVA' stand for? :P Whoever came up with that probably used the function name where this is passed in thp_vma_allowable_orders() > >> -#define TVA_IN_PF (1 << 1) /* Page fault handler */ >> -#define TVA_ENFORCE_SYSFS (1 << 2) /* Obey sysfs configuration */ >> +enum tva_type { >> + TVA_SMAPS, /* Exposing "THPeligible:" in smaps. */ > > How I hate this flag (just an observation...) > >> + TVA_PAGEFAULT, /* Serving a page fault. */ >> + TVA_KHUGEPAGED, /* Khugepaged collapse. */ > > This is equivalent to the TVA_ENFORCE_SYSFS case before, sort of a default > I guess, but actually quite nice to add the context that it's sourced from > khugepaged - I assume this will always be the case when specified? > >> + TVA_FORCED_COLLAPSE, /* Forced collapse (i.e., MADV_COLLAPSE). */ > > Would put 'e.g.' here, then that allows 'space' for the edge case... Makes sense. > >> +}; >> >> -#define thp_vma_allowable_order(vma, vm_flags, tva_flags, order) \ >> - (!!thp_vma_allowable_orders(vma, vm_flags, tva_flags, BIT(order))) >> +#define thp_vma_allowable_order(vma, vm_flags, type, order) \ >> + (!!thp_vma_allowable_orders(vma, vm_flags, type, BIT(order))) > > Nit, but maybe worth keeping tva_ prefix - tva_type - here just so it's > clear what type it refers to. > > But not end of the world. > > Same comment goes for param names below etc. No strong opinion, but I prefer to drop the prefix when it can be deduced from the type and we are inside of the very function that essentially defines these types (tva prefix is implicit, no other type applies). These should probably just be inline functions at some point with proper types and doc (separate patch uin the future, of course). [...] >> +++ b/mm/khugepaged.c >> @@ -474,8 +474,7 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, >> { >> if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && >> hugepage_pmd_enabled()) { >> - if (thp_vma_allowable_order(vma, vm_flags, TVA_ENFORCE_SYSFS, >> - PMD_ORDER)) >> + if (thp_vma_allowable_order(vma, vm_flags, TVA_KHUGEPAGED, PMD_ORDER)) >> __khugepaged_enter(vma->vm_mm); >> } >> } >> @@ -921,7 +920,8 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, >> struct collapse_control *cc) >> { >> struct vm_area_struct *vma; >> - unsigned long tva_flags = cc->is_khugepaged ? TVA_ENFORCE_SYSFS : 0; >> + enum tva_type tva_type = cc->is_khugepaged ? TVA_KHUGEPAGED : >> + TVA_FORCED_COLLAPSE; > > This is great, this is so much clearer. > > A nit though, I mean I come back to my 'type' vs 'tva_type' nit above, this > is inconsistent, so we should choose one approach and stick with it. This is outside of the function, so I would prefer to keep it here, but no stong opinion. > >> >> if (unlikely(hpage_collapse_test_exit_or_disable(mm))) >> return SCAN_ANY_PROCESS; >> @@ -932,7 +932,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, >> >> if (!thp_vma_suitable_order(vma, address, PMD_ORDER)) >> return SCAN_ADDRESS_RANGE; >> - if (!thp_vma_allowable_order(vma, vma->vm_flags, tva_flags, PMD_ORDER)) >> + if (!thp_vma_allowable_order(vma, vma->vm_flags, tva_type, PMD_ORDER)) >> return SCAN_VMA_CHECK; >> /* >> * Anon VMA expected, the address may be unmapped then >> @@ -1532,9 +1532,10 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, >> * in the page cache with a single hugepage. If a mm were to fault-in >> * this memory (mapped by a suitably aligned VMA), we'd get the hugepage >> * and map it by a PMD, regardless of sysfs THP settings. As such, let's >> - * analogously elide sysfs THP settings here. >> + * analogously elide sysfs THP settings here and pretend we are >> + * collapsing. > > I think saying pretending here is potentially confusing, maybe worth saying > 'force collapse'? Makes sense. -- Cheers, David / dhildenb