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 9BFE6C02193 for ; Tue, 4 Feb 2025 20:40:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 130D76B007B; Tue, 4 Feb 2025 15:40:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E00E6B0082; Tue, 4 Feb 2025 15:40:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9AD26B0083; Tue, 4 Feb 2025 15:40:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CC2846B007B for ; Tue, 4 Feb 2025 15:40:24 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6597845C32 for ; Tue, 4 Feb 2025 20:40:24 +0000 (UTC) X-FDA: 83083429968.02.1F3E3F1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id B683B140007 for ; Tue, 4 Feb 2025 20:40:21 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RkSb+GFX; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.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=1738701622; a=rsa-sha256; cv=none; b=FHaAqvNOpagQ1fwpBWtTvmuHHQBChyr9EO14xBfuAOUdVmVMwf/yi3JU59W0WKSyFKJRtW 16sE81uS4R9uUZk9yADtqfbJCpuLvRVWwWH5h2p3kL93WJpX/xT3SnumiXQ5MGqzmXfTXQ 9ZZvpQJEua7JkF4VjHm/6MF/Xrq3itY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RkSb+GFX; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.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=1738701622; h=from:from:sender: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:dkim-signature; bh=FPB7FLsUMoKtYQcwe7BDD+w1j2u7gU12m5Hh4LuNgkM=; b=HAuamQ+grbO/6RToZX94aRZCCheb+o1DVNjyIrbohXGarbZFCjXjSyYdJqgooCcupcIwGQ FKc99YIzcf/HhL0o5F/eHHkcttqUt25ATfSgybBQs1NglVu+TwHnBq6KGJHNDuwyvNJHbO QX6faQSBpYeze6AqRdZJgXvvNH2SqXo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738701621; 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=FPB7FLsUMoKtYQcwe7BDD+w1j2u7gU12m5Hh4LuNgkM=; b=RkSb+GFX/eCTXC1fqCfx/fQw1wkiw6p/geglSMY3y2WsUGQucKiq3bc9/gfeeDjmjtAat5 2b+p74OnBpk9gsDX9YX7M+a5euwTzp3ziMDMyd2ZzdLD/F7xSnQ5utxk98IezMwxOEtmGq a4oVBU6Nyyv1xXef2ahkaqWnWQ9YMMc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-518-AD9UF50GOueGggybnvh-wg-1; Tue, 04 Feb 2025 15:40:19 -0500 X-MC-Unique: AD9UF50GOueGggybnvh-wg-1 X-Mimecast-MFC-AGG-ID: AD9UF50GOueGggybnvh-wg Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38db0144bafso325042f8f.3 for ; Tue, 04 Feb 2025 12:40:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738701618; x=1739306418; 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=FPB7FLsUMoKtYQcwe7BDD+w1j2u7gU12m5Hh4LuNgkM=; b=UncRl99U1Qv0qRxnxBv59H/oP0LG/2akCQlv/MzOKKvStJwiMdpurZCWssFUhj6Chp Yc825yginU4CKcSqOTCm2K4pwGRckZ3H8WW65zDuo9rc1OvH4L4kR5DrmqAbbTrJLA2h b1ymAab1sBT7gHQDrlsVsJVjorUnMYW4GbYCf/RLkw6jQX6t7ocwUgeajEaNUQvnq92v 3NiLJshOzxZwLw6PgY2BIYM8QKQG4m7qbDJqXoR0GFEu+zPvMjeeiLF7BxIVfY71xEbe 3yJUXwvA/CVb96VPhz1ixMngTAN8rYNh0rhyJzpIguJHDm4fsFMUXalHv4z3812sVUfn KGCw== X-Forwarded-Encrypted: i=1; AJvYcCVz0E1dBgopToaqBph13Ztpti4Ohr5QnMuSpFGZg+V2MHN9kxCmoxHTDJHK8xZTyW4vAaLM6Lj9DQ==@kvack.org X-Gm-Message-State: AOJu0Yy2pst0Kb8QxXtCAOWQTZJr6KHBwbfynSIEfZjn9saQCn3BCuO4 OUvQyH5qIPvUglV1WxZ8ZMYDmI+sVqCC+S3eHkQY1UYCYyMVErrl4qKC2FJL1wPYqG4nZCRwbos FM4+eDoya+yDyHal9bZnTmOAUHDbunzmvYnwHG1GM8ou0RXap X-Gm-Gg: ASbGncsNAyux7ZmZ9G5/K97CWuzAvynO11cCdz5ScK9OcUs8XrMaQY19STPCmFT281y LQrlNwF0NdFQtwDQ14w+R6EtPoDcCSEfBaPNynwD4U1Auj9etdn5KLS+vKDEjVnIbtA7QvJf1vc l3JnhpyEft4bsOJv/E3eIb5Kl/YIwJpC4w7d60dqe4+gWh27pmWu51nqnhDa30fZXDi0hOVGZjm JXOdUxIp5pt6f6b+JAPxvLbXpYIqa1vuDA/V/jK1dKcPMqvwHR+ehJKDVEwTGQcBmWyE/j7NtmW /m7xavpGqb7iEZTU4Lu2f64EWZoCB0Z3GuDi7CYgQ00L6uGs3tJUj2CX1QIEdm7qMFIMwF51LRa WttVay9LJjQv4LRYDLcei30sQ9cE= X-Received: by 2002:a5d:6d85:0:b0:38b:f3f4:57af with SMTP id ffacd0b85a97d-38db491f1c1mr151951f8f.35.1738701618458; Tue, 04 Feb 2025 12:40:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIrXW1TWUGPT0ASPvc+rkpOSyHrzqTN4WzrZ5plQhidhXCSvGknX66Gt9SnhDDgaYNBrat3A== X-Received: by 2002:a5d:6d85:0:b0:38b:f3f4:57af with SMTP id ffacd0b85a97d-38db491f1c1mr151933f8f.35.1738701618063; Tue, 04 Feb 2025 12:40:18 -0800 (PST) Received: from ?IPV6:2003:cb:c70a:300:3ae1:c3c0:cef:8413? (p200300cbc70a03003ae1c3c00cef8413.dip0.t-ipconnect.de. [2003:cb:c70a:300:3ae1:c3c0:cef:8413]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c5c1cf40asm16652822f8f.83.2025.02.04.12.40.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Feb 2025 12:40:17 -0800 (PST) Message-ID: <74ecaa8b-9e94-4ba8-a2f0-a312607516ba@redhat.com> Date: Tue, 4 Feb 2025 21:40:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [LSF/MM/BPF TOPIC] HugeTLB generic pagewalk To: Oscar Salvador Cc: lsf-pc@lists.linux-foundation.org, Peter Xu , Muchun Song , linux-mm@kvack.org References: <4c50a439-e2b8-4f54-ba3d-366d0e2961b2@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 WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhk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mBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7FsRx_arPeTJYVmnuGu0JPQjes9IiUFqd8YC533exAs_1738701619 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B683B140007 X-Stat-Signature: nsumx5tnm8ma8efqmea84tscxuubky8g X-HE-Tag: 1738701621-346198 X-HE-Meta: U2FsdGVkX19SMxQEaAVSsuVWvTpvauEnNgh/rfgsicP1Wy6nA8PCxz2K3VfQoSNLRxCElx1Ll01A1Tub1J6qEioVjcoCqykwCBxbwm6jJQPgc4Y+hCp/4ztLcIuBYv8rspe4KnBc6inNKUU8Re92w79uwe1lUC3DmHYB8x+IEpP7qb+y2L3WYoPGipy2pJksNXD3dPFBctsc4TyuYe3t2IDNX0JqqDmGTNvWLXFdMUpODkhR167KAENkjZ9Aeh/UlDFFIM2aiUzC4vniHY7BaN6o2T7rmlYxUWPIVBPyeMi+4NHfp+d2kY4B/5SCCG17HTvbqEpEYKeqSeTKk4hmACBJFMq1/Q88wUgDOQY6PE1aBsPJBvdFCpjm2nNhTsaRh4126O2634rFnkvaZUOecjfORMkuj9eUPUtpuQ8HWY94417XBwz8L/Few8eNQSmJAEm4fnu+lnMtrwkS1wTpCo0CstfA7yoqOcboX3cA4SppLN9+8GSSWt9RQtiXMFsDe/raukrwihVvFz+y94MmAyGCpw7YR7JQArkntbgItp+pqfeO/ElVP2d+cEJfKKC/Bm7bjbnkqE0tlGsUnPNctfazI8cGSFYx/W65HoNYKKDrGbdl3aWg4jn07SwJRcipk1AqipW4Mi5Pw46PMDaJynQp5tadCN0yLwewyAhkqJPtDNzphSB3/pHutiSAUt7YAMbEuqYVyETxMECLI31GSA9TUj7gqZWCe/DwVURjkZvZerZ6Ydx87N/V5v2vdE+SQOXMcY0D9z2W0aYhucHRAGgnC7dC+V7thuzYBIS+E2KWVwdBRi9Y/MdYDsBio19FUc2gBgi2yofrEwYqZkb6Uaw5275YhlZBvXxan2uhB4oUlUYZ6LdC+79pTmnHz0tUItX7DIhX/q6m/F+gvxH3vONZLlRDAnVJozaPE/8YzsIJtoGxlR/y/1mcnDS3cTCodQhR//ygf93TeMFnacQ AmnzQek2 sxH3qR7AKGHF4/TqztCDQMEWC1dlvoUawqT+N8z9BZqrOAPvy7w+kijbQ+mOI/LYzDggTTt2tKIiuNPR32WV3nHGkQAPRtaCX/8qDoCuDUatE5TWpY3S1u//JQAgaKqk6rkwX83EkTTBOKlhBkj549Hkbzm5knMFs6P4stT0aYJyxUAHhSt35/d6f9czSb4sZA64SPHQkSV6LhA92Sp0BeF3OaYBLwcanuqexDCTA/KcldL9mLiA/trsRTb35i1s//3msAE3KsRSOuntLuKmPoZZvIwxLQRtvwA2PDCMw3UNE0heKabPSjO+E2LDp0iInkjTNj9G5FGhnClDvRAzZBHXKPZZLedRTS5olOcEneO+Y6EtXyAuKFxC7SqxA925WLqXFXHiijnmXwiI= 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 03.02.25 11:10, Oscar Salvador wrote: > On Fri, Jan 31, 2025 at 12:19:24AM +0100, David Hildenbrand wrote: >> On 30.01.25 22:36, Oscar Salvador wrote: >> Hi Oscar, > > Hi David Hi, > >>> >>> HugeTLB has its own way of dealing with things. >>> E.g: HugeTLB interprets everything as a pte: huge_pte_uffd_wp, huge_pte_clear_uffd_wp, >>> huge_pte_dirty, huge_pte_modify, huge_pte_wrprotect etc. >>> >>> One of the challenges that this raises is that if we want pmd/pud walkers to >>> be able to make sense of hugetlb stuff, we need to implement pud/pmd >>> (maybe some pmd we already have because of THP) variants of those. >> >> that's the easy case I'm afraid. The real problem are cont-pte constructs (or worse) >> abstracted by hugetlb to be a single unit ("hugetlb pte"). > > Yes, that is a PITA to be honest. > E.g: Most of the code that lives in fs/proc/task_mmu.c works under that > assumption. > I was checking how we could make cont-{pmd,pte} work for hugetlb in that > area (just because it happens to be the first are I am trying to convert). > E.g: Let us have a look at smaps_pte_range/smaps_pte_entry. > > I came up with something like the following (completely untested, just a > PoC) to make smaps_pte_range work for cont-ptes. > We would also need to change all the references of PAGE_SIZE to the > actual size of the folio (if there are). Unfortunately not that easy. You can only have parts of a large folio mapped. It would be PAGE_SIZE * nr_ptes when batching. > > But looking closer, folio_pte_batch is only declared in mm/internal.h, > so I am not sure I can make use of that outside mm/ realm? Sure, we could export that. We'd need something similar for PMDs, and batching all other non-present stuff (e.g., migration entries) > If not, how could we work that around? > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 193dd5f91fbf..21fb122ebcac 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -802,7 +802,7 @@ static void mss_hugetlb_update(struct mem_size_stats *mss, struct folio *folio, > #endif > > static void smaps_pte_entry(pte_t *pte, unsigned long addr, > - struct mm_walk *walk) > + struct mm_walk *walk, int nr_batch_entries) > { > struct mem_size_stats *mss = walk->private; > struct vm_area_struct *vma = walk->vma; > @@ -813,8 +813,19 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, > > if (pte_present(ptent)) { > page = vm_normal_page(vma, addr, ptent); > - young = pte_young(ptent); > - dirty = pte_dirty(ptent); > + if (nr_batch_entries) { > + int nr; > + nr = folio_pte_batch(folio_page(page, 0), addr, pte, > + ptent, max_nr, 0, NULL, &young, > + &dirty); > + if (nr != nr_batch_entries) { > + walk->action = ACTION_AGAIN; > + return; > + } > + } else { > + young = pte_young(ptent); > + dirty = pte_dirty(ptent); > + } > present = true;> } else if (is_swap_pte(ptent)) { > swp_entry_t swpent = pte_to_swp_entry(ptent); > @@ -935,7 +946,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, > struct mm_walk *walk) > { > struct vm_area_struct *vma = walk->vma; > - pte_t *pte; > + pte_t *pte, ptent; > spinlock_t *ptl; > > ptl = pmd_huge_lock(pmd, vma); > @@ -950,8 +961,21 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, > walk->action = ACTION_AGAIN; > return 0; > } > + > + ptent = ptep_get(pte); > + if (pte_present(ptent)) { > + struct folio *folio = vm_normal_folio(vma, addr, ptent); > + if (folio_test_large(folio)) { > + /* Let us use pte batching */ > + smaps_pte_entry(pte, addr, walk, (end - addr) / PAGE_SIZE); > + pte_unmap_unlock(pte - 1, ptl); > + > + return 0; > + } > + } > + > for (; addr != end; pte++, addr += PAGE_SIZE) > - smaps_pte_entry(pte, addr, walk); > + smaps_pte_entry(pte, addr, walk, 0); > pte_unmap_unlock(pte - 1, ptl); > out: > cond_resched(); > I think this is the wrong approach. We should replace that pagewalk API usage by something better that hides all the batching. The interface would look similar to folio_walk (no callbacks, handling of locking), but (a) work on ranges; (b) work also on non-folio entries; and (c) batch all suitable entries in the range. Something like a pt_range_walk_start() that returns a "type" (folio range, migration entries, swap range, ...) + stores other details (range, level, ptep, ...) in a structure like folio_walk, to then provide mechanisms to continue (pt_walk_continue()) to walk or abort (pt_walk_done()) it. Similar to page_vma_mapped_walk(), but not specific to a given page/folio. Then, we would simply process the output of that. With the hope that, for hugetlb it will just batch all cont-pte / cont-pmd entries into a single return value. That will make the R/O walking as in task_mmu.c easier, hopefully. Not so much with PTE/PMD modifications, like damon_mkold_ops ... :( But maybe that just has to be special-cased for hugetlb, somehow ... > > >> For "ordinary" pages, the cont-pte bit (as on arm64) is nowadays transparently >> managed: you can modify any PTE part of the cont-gang and it will just >> work as expected, transparently. > > But that is because AFAIU, on arm64 it knows if it's dealing with a > cont-pte and it queries the status of the whole "gang", right? Yes, that's how I remember it works on arm64. Note that, though, that non-present PTEs don't use the cont bit. So one must "batch" these always manually. > > I see that huge_ptep_get/set_huge_pte_at checks whether it's dealing > with cont-ptes and modifies/queries all sub-ptes. > How is that done for non-hugetlb pages? Similarly, at least on arm64. When setting individual PTEs, it automatically sets the cont-pte bit once it detects that the applicable PTEs are all "cont-compatible" (e.g., belong to same folio, same protection bits). Other architectures might require more work (powrpc). -- Cheers, David / dhildenb