Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1809165rbb; Tue, 27 Feb 2024 01:36:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWAD+WdTzpcEjoOiimb/gq4j7YoVDLKycWmHR68MoNTigi46N48WCKN9WkiNTMGmPEG9eHln3hssNyEAu+AeClveyfVGNNd//tZltg1aA== X-Google-Smtp-Source: AGHT+IHugf1L5rmOiK2/uCg1n+9pW4aI3ZXgPufRjGUgkZnLbGg+m6jYUZzU7sj6rLmLIuaggotB X-Received: by 2002:a05:620a:384c:b0:787:c780:a78c with SMTP id po12-20020a05620a384c00b00787c780a78cmr1482256qkn.52.1709026615656; Tue, 27 Feb 2024 01:36:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709026615; cv=pass; d=google.com; s=arc-20160816; b=Pu2+b2AKodwxarVRrKG91sVjtzSZ+F+DjEIzExJNEhvuR6pQ3Xbt8CiYrk7h92uQe3 nRnBY8bqoXOsoJRWPccLjYM1aShLcazzpecIqZK/HmpdzHzoktkH0ESo3XocNCyBXRe4 JfrtLie1G1a6PBy/c7Yi5muJTeb1zMK5qym7BDiu1dV1egrgTVWZ1F/K2ue9JX2RcMho +T3G8xA2MZXSOkMUFFCrSx1dBmf72+fR3s1J4FOXy78VCRHz2vz6L4spIQXfL0JTuimh MDcF9dXP1fYl3SzwzBoVH+4EMFrFOytTCVmRe3l0ON2zeKT3k66uv31FPenaspbuARzB n+yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=rFrtZB6Qy6FQZw76onOMTtbfujJrxXsMEz/j5WTBBdE=; fh=f4yrtuU99dAX6Qc9xEs+J3XUOQE9Pixph+bIjGQat9s=; b=Iu7GfHYI4hR86UMNhxguscjZysp5kxxkncWOhXdwDcDYEKyg912rdA4G0fxBzLpgvW RQRgEb1m2g79YhtxQUEws1f5580wAo5/r+3yp0sGXCzEsDp45QlRDGxZ+1Y75ht7TePK SR8wlc+1pSRqpItIWxcQl5m27Q1+gCkjfNOqw7/iMC0zq4Vben7+DyC1EVGH7ag0Rggh YZ5BkqSAdZ8bchMnhSJTWVQ01yWQiy8mayH/Gb/CUXMX9mrgc9MsXoTMSod1XVwkyAXo oxjYFD3TCwAWAdft/PkcG3O2On7Vbpzcf4mD641jupgd0I0tfQ+MDvxacGLkDzYkFWLa P3sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xu9Lb3v8; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-82968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vq17-20020a05620a559100b00787c670345bsi6386059qkn.28.2024.02.27.01.36.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:36:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xu9Lb3v8; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-82968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5AF4A1C20B63 for ; Tue, 27 Feb 2024 09:36:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53CA9136990; Tue, 27 Feb 2024 09:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xu9Lb3v8" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 0884A135A75 for ; Tue, 27 Feb 2024 09:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709026610; cv=none; b=Lxqo75GIm1KFHyv+Ydszv3w/tOgBHq4v5zuULbC6kmhoiOCUAADwMhkt3PfuF7X8PkcvQZOxz/OLu4WW/wQsBDc+MxQ9CpA4qz5kCIRUIYxYc85JPphR6Bo4w42Eqdq9HJYpd2QX25Rwu2G7APv4r/eTqE2VJIRJiOgdwgxcmEA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709026610; c=relaxed/simple; bh=IA4jXxU6MJ/W/qpXgS/1CKOVND0eKixNSN67gqPANlY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=edEGaisoia4I/8CYl4K/E3mpyM9dLqPYbGMuZ/Ksolh8QoKQua+sOQN2ot3HZsMmBZkMZ8hnpQuDsb4XS179AcaaPDQs4BwKvKXGsZhg7bSqMul19bTlN0Vc/ft71HYNupvahPbDzmY3LFJ3ddMjmkJojRXAgxOfpdOCLioYoew= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=Xu9Lb3v8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709026606; 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=rFrtZB6Qy6FQZw76onOMTtbfujJrxXsMEz/j5WTBBdE=; b=Xu9Lb3v8bvZCkRnUzFtIqhthqOLTW7z0syNH61GSTRjkm+wF5J0DfKKRIl0b20XZlG2L7k RYMRO7dXyrpyRMv6mlJb6Z3jpjR27l4kBQAStoooZ6/n3DvTd9uSCvU1psiR8BIIKE4vUz UgPPjS7294xZ9nltOG2vw5iOR3kP7+I= 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-656-Ax3rW-dKORq8Iy3HsoSYsA-1; Tue, 27 Feb 2024 04:36:45 -0500 X-MC-Unique: Ax3rW-dKORq8Iy3HsoSYsA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-33dcd5d117fso922339f8f.1 for ; Tue, 27 Feb 2024 01:36:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709026604; x=1709631404; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rFrtZB6Qy6FQZw76onOMTtbfujJrxXsMEz/j5WTBBdE=; b=k/9AfeAxpFAAHCtmRm9+KjbbLeet6YDQrg85QKo9NgX77NY2/OZ5VDgN1uAlt/npnu rFG33gj19g7QY6DVQeSRI2g6RsROLF1NWLSv3uMGg72w9meXXAeElRNlePjpUTwars98 VlzVcmtPL5EOSmJyxUBAfiNWrFfW6PfjNWfyphaFSS1GMG0+UZxahuTG57qdtx5TzCDy qjK5G8Rik2JB+rWmg+CDmMDP2C0poTqNUo6pTV3dpANRevFjV2z6mA+OMeYFANSZUoyM 5F+U7F5YaFqglsuYAlMdmYhKhR7YBD8fjUtIxfhs1KLKF9yYX4doGgt7mTvqdV0rfmyI MEkw== X-Forwarded-Encrypted: i=1; AJvYcCVzV1QBaiGDv6yuTnlBgkKlgvo6GdbFjosVu51UKF0ULQBJ9Crc6gtetrfQphpeTORtGyuM2QMvnICMCZkJ6Gl8vaTDYISUtr5La0A7 X-Gm-Message-State: AOJu0YzW95/V7mX9ZKGw/OC9xHuB1XO3EIdUFOQkBM93F5+E5dBRLDGf 7byVuu7QcZ089UtnOxKOvM1FFzYULAaSpGqCueUZX+X0GTVPzffYwHek1tAVLxPlKHGZrzJhyad N+YeucP1vWxfzb98L9u/Swrea60lPhfdrr4wfGlCmvxhyMoSdUlluZqhUSSGQh8tdqBe76Q== X-Received: by 2002:a5d:64e4:0:b0:33d:d843:ecd2 with SMTP id g4-20020a5d64e4000000b0033dd843ecd2mr6232936wri.24.1709026604293; Tue, 27 Feb 2024 01:36:44 -0800 (PST) X-Received: by 2002:a5d:64e4:0:b0:33d:d843:ecd2 with SMTP id g4-20020a5d64e4000000b0033dd843ecd2mr6232906wri.24.1709026603868; Tue, 27 Feb 2024 01:36:43 -0800 (PST) Received: from ?IPV6:2003:cb:c707:7600:5c18:5a7d:c5b7:e7a9? (p200300cbc70776005c185a7dc5b7e7a9.dip0.t-ipconnect.de. [2003:cb:c707:7600:5c18:5a7d:c5b7:e7a9]) by smtp.gmail.com with ESMTPSA id bj29-20020a0560001e1d00b0033d81d9c44esm10925634wrb.70.2024.02.27.01.36.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Feb 2024 01:36:43 -0800 (PST) Message-ID: <42ffe7cf-8371-433d-a9bf-1a23c902f3f9@redhat.com> Date: Tue, 27 Feb 2024 10:36:42 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: export folio_pte_batch as a couple of modules might need it Content-Language: en-US To: Barry Song <21cnbao@gmail.com> Cc: Ryan Roberts , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Lance Yang , Yin Fengwei References: <20240227024050.244567-1-21cnbao@gmail.com> <61b9dfc9-5522-44fd-89a4-140833ede8af@arm.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/E8M7TEwuC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ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 27.02.24 10:27, Barry Song wrote: > On Tue, Feb 27, 2024 at 10:14 PM David Hildenbrand wrote: >> >> On 27.02.24 10:07, Ryan Roberts wrote: >>> On 27/02/2024 02:40, Barry Song wrote: >>>> From: Barry Song >>>> >>>> madvise and some others might need folio_pte_batch to check if a range >>>> of PTEs are completely mapped to a large folio with contiguous physcial >>>> addresses. Let's export it for others to use. >>>> >>>> Cc: Lance Yang >>>> Cc: Ryan Roberts >>>> Cc: David Hildenbrand >>>> Cc: Yin Fengwei >>>> Signed-off-by: Barry Song >>>> --- >>>> -v1: >>>> at least two jobs madv_free and madv_pageout depend on it. To avoid >>>> conflicts and dependencies, after discussing with Lance, we prefer >>>> this one can land earlier. >>> >>> I think this will also ultimately be useful for mprotect too, though I haven't >>> looked at it properly yet. >>> >> >> Yes, I think we briefly discussed that. >> >>>> >>>> mm/internal.h | 13 +++++++++++++ >>>> mm/memory.c | 11 +---------- >>>> 2 files changed, 14 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/mm/internal.h b/mm/internal.h >>>> index 13b59d384845..8e2bc304f671 100644 >>>> --- a/mm/internal.h >>>> +++ b/mm/internal.h >>>> @@ -83,6 +83,19 @@ static inline void *folio_raw_mapping(struct folio *folio) >>>> return (void *)(mapping & ~PAGE_MAPPING_FLAGS); >>>> } >>>> >>>> +/* Flags for folio_pte_batch(). */ >>>> +typedef int __bitwise fpb_t; >>>> + >>>> +/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ >>>> +#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) >>>> + >>>> +/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */ >>>> +#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) >>>> + >>>> +extern int folio_pte_batch(struct folio *folio, unsigned long addr, >>>> + pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, >>>> + bool *any_writable); >>>> + >>>> void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio, >>>> int nr_throttled); >>>> static inline void acct_reclaim_writeback(struct folio *folio) >>>> diff --git a/mm/memory.c b/mm/memory.c >>>> index 1c45b6a42a1b..319b3be05e75 100644 >>>> --- a/mm/memory.c >>>> +++ b/mm/memory.c >>>> @@ -953,15 +953,6 @@ static __always_inline void __copy_present_ptes(struct vm_area_struct *dst_vma, >>>> set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); >>>> } >>>> >>>> -/* Flags for folio_pte_batch(). */ >>>> -typedef int __bitwise fpb_t; >>>> - >>>> -/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */ >>>> -#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0)) >>>> - >>>> -/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */ >>>> -#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1)) >>>> - >>>> static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) >>>> { >>>> if (flags & FPB_IGNORE_DIRTY) >>>> @@ -982,7 +973,7 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) >>>> * If "any_writable" is set, it will indicate if any other PTE besides the >>>> * first (given) PTE is writable. >>>> */ >>> >>> David was talking in Lance's patch thread, about improving the docs for this >>> function now that its exported. Might be worth syncing on that. >> >> Here is my take: >> >> Signed-off-by: David Hildenbrand >> --- >> mm/memory.c | 22 ++++++++++++++++++---- >> 1 file changed, 18 insertions(+), 4 deletions(-) >> >> diff --git a/mm/memory.c b/mm/memory.c >> index d0b855a1837a8..098356b8805ae 100644 >> --- a/mm/memory.c >> +++ b/mm/memory.c >> @@ -971,16 +971,28 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags) >> return pte_wrprotect(pte_mkold(pte)); >> } >> >> -/* >> +/** >> + * folio_pte_batch - detect a PTE batch for a large folio >> + * @folio: The large folio to detect a PTE batch for. >> + * @addr: The user virtual address the first page is mapped at. >> + * @start_ptep: Page table pointer for the first entry. >> + * @pte: Page table entry for the first page. >> + * @max_nr: The maximum number of table entries to consider. >> + * @flags: Flags to modify the PTE batch semantics. >> + * @any_writable: Optional pointer to indicate whether any entry except the >> + * first one is writable. >> + * >> * Detect a PTE batch: consecutive (present) PTEs that map consecutive >> - * pages of the same folio. >> + * pages of the same large folio. >> * >> * All PTEs inside a PTE batch have the same PTE bits set, excluding the PFN, >> * the accessed bit, writable bit, dirty bit (with FPB_IGNORE_DIRTY) and >> * soft-dirty bit (with FPB_IGNORE_SOFT_DIRTY). >> * >> - * If "any_writable" is set, it will indicate if any other PTE besides the >> - * first (given) PTE is writable. >> + * start_ptep must map any page of the folio. max_nr must be at least one and >> + * must be limited by the caller so scanning cannot exceed a single page table. >> + * >> + * Return: the number of table entries in the batch. >> */ >> static inline int folio_pte_batch(struct folio *folio, unsigned long addr, >> pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, >> @@ -996,6 +1008,8 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, >> *any_writable = false; >> >> VM_WARN_ON_FOLIO(!pte_present(pte), folio); >> + VM_WARN_ON_FOLIO(!folio_test_large(folio) || max_nr < 1, folio); >> + VM_WARN_ON_FOLIO(page_folio(pfn_to_page(pte_pfn(pte))) != folio, folio); >> >> nr = pte_batch_hint(start_ptep, pte); >> expected_pte = __pte_batch_clear_ignored(pte_advance_pfn(pte, nr), flags); >> -- >> 2.43.2 >> >> >>> >>>> -static inline int folio_pte_batch(struct folio *folio, unsigned long addr, >>>> +int folio_pte_batch(struct folio *folio, unsigned long addr, >>> >>> fork() is very performance sensitive. Is there a risk we are regressing >>> performance by making this out-of-line? Although its in the same compilation >>> unit so the compiler may well inline it anyway? >> >> Easy to verify by looking at the generated asm I guess? > > my aarch64-linux-gnu-gcc didn't inline it I think on x86-64 it would inline it with "gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6)" > > $ aarch64-linux-gnu-gcc --version > aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 > Copyright (C) 2021 Free Software Foundation, Inc. > > $ nm -S -s vmlinux.a | grep folio_pte_batch > 0000000000003818 0000000000000204 T folio_pte_batch > As it's only used on the folio_test_large() "slower" paths, likely optimizing out the "writable" check (and possibly the flags) might not be that important. >> >>> >>> Either way, perhaps we are better off making it inline in the header? That would >>> avoid needing to rerun David's micro-benchmarks for fork() and munmap(). > > actually tried this before trying extern, the problem is that we have to add > others into internal.h, for example __pte_batch_clear_ignored, which > seems not API. are we comfortable to move that one to internal.h too? Yes, that shouldn't stop us. -- Cheers, David / dhildenb