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 38A00224C6 for ; Fri, 26 Jan 2024 19:11:24 +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=1706296287; cv=none; b=YoXXdYrAh8oBRmS6FUSAhtYyEo05osb2b95jvzdirYqC1Dzq+S+qon+/+UJCjZyLjGbqa6lCD35swsf9JIKm6rB9ilHVDgpYBocFsANnyt4UlDKq6YnVZW0etosPjXP0UNWDZB45qSXUYaQuP0X4EovzQp0+clTCoygvOs9mmxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706296287; c=relaxed/simple; bh=taq9MRcHQZPGoD+oxR/jZ6ymaVRJzNqx14jm8Jqa3BY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ficF5RlMR4oQi/J0/xDZaPJJyN9s4lAxxWhlyavoiBgwvkgT+O9fL+jj7wbv8B5ek/qd4wSfEZfleEleHNug8xzuWiA2VLs7z+SnvhigllwF3dRrmoq/ito9ItCBjMC32YjZ/ux7Imabf8X91lGNq3kTC8ZOVw1Y8GwtnAzBvmA= 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=hkRALx7D; arc=none smtp.client-ip=170.10.129.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hkRALx7D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706296284; 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=4g8K7l28tbM/mldWkR+pvjoSC5Y71b2XjVOt+98pFVU=; b=hkRALx7DRadyyFtZYHWweWw1ou80cjuK7z+H0EZFpEo40h7umGQK78zV2fgCv/D5n1XYFf AKHNbc2BMlg4I5marHix7kpmhdwpMlhFSCc4B5LWVBIJ13LM/oiQzUlyxokNzmRqtx65aI hN/1yxDmTWQcjt/FfTXqVKUVY0K4jE0= 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-611-rBgJKGcAORWjUcHkoOVcQQ-1; Fri, 26 Jan 2024 14:11:22 -0500 X-MC-Unique: rBgJKGcAORWjUcHkoOVcQQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3392d419c7dso546113f8f.1 for ; Fri, 26 Jan 2024 11:11:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706296282; x=1706901082; 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=4g8K7l28tbM/mldWkR+pvjoSC5Y71b2XjVOt+98pFVU=; b=GfH0Z/HPozB5LCT1Z8aB0ZqQKImXale/eV7X274vJPpG1yNKCCfXCjEpebe97BPf2k LBkUQg9o34rb32hMEAFo+0ScZ2DiyM2aURmzrHMVhNsN+cbgsf27Ns0544LP4uI+V5tA 9yNlmm8Wbtm/V+BqbLADiUm/BiFMmNPU75F5ev3tXlEAmvUqebzFVeov4y9Mbl5mJg03 JFcqT9CzSjKacNj4se4hHDM7inp6wzN+pExT22k8ZAJNESzrLQbDVUvEsVgZZEd67Zp1 e2OQ5jou4RENGqjOKaaDISksI+Vm6xXd9pNpKQ5RuwA23JijJaMv8c2X42zY+baq71M/ VxqA== X-Gm-Message-State: AOJu0YwQXAsYiMMjBgq85bf42mR4VFm1Owwj37HDXgjX+R6N3XJH6Sin wWVL1de/1Fgywq0JJvtp0vdJvVQI6pQ5oZidwR7XotHD3pkGiVEFJRLZjlIbyT8Ls8JP5ZCKy7p VwZbpprdJZDEN9g6vkla8CTS0vVXaa/s0WE0Lx94xEkPT51/3CXgI6fEVXNE= X-Received: by 2002:adf:e34e:0:b0:337:a81a:a92 with SMTP id n14-20020adfe34e000000b00337a81a0a92mr93410wrj.16.1706296281742; Fri, 26 Jan 2024 11:11:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2W4KZitVtEWtyaZogLu/njgh6vBkydyWO+lquJ8xT0VP90E3HBBntnlOQm8GtijC18P28qA== X-Received: by 2002:adf:e34e:0:b0:337:a81a:a92 with SMTP id n14-20020adfe34e000000b00337a81a0a92mr93386wrj.16.1706296281267; Fri, 26 Jan 2024 11:11:21 -0800 (PST) Received: from ?IPV6:2003:cb:c70a:5100:7e95:22ff:3f9b:1e92? (p200300cbc70a51007e9522ff3f9b1e92.dip0.t-ipconnect.de. [2003:cb:c70a:5100:7e95:22ff:3f9b:1e92]) by smtp.gmail.com with ESMTPSA id h5-20020adfe985000000b00337d67a85c1sm1811358wrm.62.2024.01.26.11.11.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 11:11:20 -0800 (PST) Message-ID: <5b5b2ceb-9099-4acc-a995-d979ad414c6a@redhat.com> Date: Fri, 26 Jan 2024 20:11:19 +0100 Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 13/15] mm/memory: optimize fork() with PTE-mapped THP Content-Language: en-US To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Ryan Roberts , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org References: <20240125193227.444072-1-david@redhat.com> <20240125193227.444072-14-david@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/pT4w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q 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: <20240125193227.444072-14-david@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 25.01.24 20:32, David Hildenbrand wrote: > Let's implement PTE batching when consecutive (present) PTEs map > consecutive pages of the same large folio, and all other PTE bits besides > the PFNs are equal. > > We will optimize folio_pte_batch() separately, to ignore selected > PTE bits. This patch is based on work by Ryan Roberts. > > Use __always_inline for __copy_present_ptes() and keep the handling for > single PTEs completely separate from the multi-PTE case: we really want > the compiler to optimize for the single-PTE case with small folios, to > not degrade performance. > > Note that PTE batching will never exceed a single page table and will > always stay within VMA boundaries. > > Further, processing PTE-mapped THP that maybe pinned and have > PageAnonExclusive set on at least one subpage should work as expected, > but there is room for improvement: We will repeatedly (1) detect a PTE > batch (2) detect that we have to copy a page (3) fall back and allocate a > single page to copy a single page. For now we won't care as pinned pages > are a corner case, and we should rather look into maintaining only a > single PageAnonExclusive bit for large folios. > > Signed-off-by: David Hildenbrand > --- > include/linux/pgtable.h | 31 +++++++++++ > mm/memory.c | 112 +++++++++++++++++++++++++++++++++------- > 2 files changed, 124 insertions(+), 19 deletions(-) > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index 351cd9dc7194f..891ed246978a4 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -650,6 +650,37 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres > } > #endif > > +#ifndef wrprotect_ptes > +/** > + * wrprotect_ptes - Write-protect consecutive pages that are mapped to a > + * contiguous range of addresses. > + * @mm: Address space to map the pages into. > + * @addr: Address the first page is mapped at. > + * @ptep: Page table pointer for the first entry. > + * @nr: Number of pages to write-protect. > + * > + * May be overridden by the architecture; otherwise, implemented as a simple > + * loop over ptep_set_wrprotect(). > + * > + * Note that PTE bits in the PTE range besides the PFN can differ. For example, > + * some PTEs might already be write-protected. > + * > + * Context: The caller holds the page table lock. The pages all belong > + * to the same folio. The PTEs are all in the same PMD. > + */ After writing documentation for another two such functions, I'll change this to: /** * wrprotect_ptes - Write-protect PTEs that map consecutive pages of the same * folio. * @mm: Address space the pages are mapped into. * @addr: Address the first page is mapped at. * @ptep: Page table pointer for the first entry. * @nr: Number of entries to write-protect. * * May be overridden by the architecture; otherwise, implemented as a simple * loop over ptep_set_wrprotect(). * * Note that PTE bits in the PTE range besides the PFN can differ. For example, * some PTEs might be write-protected. * * Context: The caller holds the page table lock. The PTEs map consecutive * pages that belong to the same folio. The PTEs are all in the same PMD. */ -- Cheers, David / dhildenb