Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp412677lqg; Thu, 11 Apr 2024 06:55:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxsziRZuiTwqGFLMgE87Iu5jgak3yzVwt+M82egorJAIzFFEVfTLzCDVnvCqEmx4mYqFDvZfaP6uwkiR0EBZxosuJDROoEDmgvRqoBnQ== X-Google-Smtp-Source: AGHT+IFOYfycTyeG4VDn8k0Opzdr09s5sJ/qaB1BjU9mdeNnTZRLYcv5IbBbJ5wrKXyaImhrvkPS X-Received: by 2002:a17:902:d587:b0:1e4:8eb3:26f5 with SMTP id k7-20020a170902d58700b001e48eb326f5mr6485367plh.38.1712843750576; Thu, 11 Apr 2024 06:55:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712843750; cv=pass; d=google.com; s=arc-20160816; b=RDkhtUP++ItNWMLJ38YIA+c/TdYcdYSipZKRr4gkfCPIfFkw80pCB8QjAZiJUPmuk7 WCd8GYJs0Xq2n1xrmeOtPYkSr+dyvZAddyxUEXeuKHAz0XsFjhw1p2vSHJmFd68A7PDj z8duuBUvi0kVaEZJ0BXduquOvhclMzsXefuiR6PqT4C5OiFTKY6SMuBFv3DqsJ3segJ6 qs1v+utlQW4gXN+B02R7mKnzBjLNBxAiBQlJRtbP5vR9LCnIIJtL+geBakn1WckqIe98 YlDsGGggAH8JSzWI6GCDLUFEnqy19uoW+/tiZN2PeOC7YUoICaifjIP1x7LsCMMs0bsI R5Jw== 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 :content-language:from:references:cc:to:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=Q4rQfc9RC+GxIPpSYuDb9Zohke1bO5Mw3DCJlzz/elI=; fh=QypW+eaLYSb0us51AloASDwIQYcL2Im1cJfE8iQYHiI=; b=08NqJ4sAIkK4etb2Ir/oOTRRwIIvAFSqU1OLDR2PGoTgroUL4aLe/yn99TlUzfjD3x YDFLjhWHaEnDa7ngZSRk4iNfUzLxGvoH0efSNfojqA2C+QwHNc1NhDyWQr9/hXR7VPYN 9eOccpueTydSqGudWGQ+7oj1hphlr36CY9fIQ+H1104P06FaCg1W3lpAclqbLumPAU/X AEQTCeeXSvFbgxuh02ZCROSGGzyEHOtIyz752IrhKXUEgoixo7bFhJMHs+arZM69B39B fufKJruT5BdnAGaGr3Ha57cDW3yIyv6NFdP8k86+Hy87hS+PCW1HHKxm095w19G2lMHk oPLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FHuIqJ+U; 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-140574-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140574-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b2-20020a170903228200b001e0aca12f4dsi1371755plh.454.2024.04.11.06.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 06:55:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140574-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FHuIqJ+U; 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-140574-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140574-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EA791285A62 for ; Thu, 11 Apr 2024 13:55:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06AB714D707; Thu, 11 Apr 2024 13:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FHuIqJ+U" 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 3ABB81EB26 for ; Thu, 11 Apr 2024 13:55:14 +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=1712843716; cv=none; b=gIdWtlFKIFII86cAVPfo2Ri/31SsWQg2e0HnqvUfWHF7JVENFowMjYpmhgy11ARBEcnezIw2J1Vd4ZRkwS0XRIf0brNguvkZVuCIEVoHYaakH57HNtzP5mXedjhlfUctVVKQJsb9kAUdH5TNGoGul7YusaicqcG7eLUTARA8E6o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712843716; c=relaxed/simple; bh=FnqCp3oLSzyZRxDlKxUOLxebMPK/bCBJJvh62VIdg64=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UpYQmmKujB6CNf8q+uyRDzHWezvy9hSd/kg3gz8/K8Dh9/McWh2aFKCEA6CCiouAkOfRh1ZkFvdUxATpuP3Ex23OIO+07G0D90t7G0492vvQCKdg9Auq6vw1kZnmoWjAYnVQCYCbErGAQbyZ2bCx/xLhmXRzeuN+idR1KBZkXcM= 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=FHuIqJ+U; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712843714; 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=Q4rQfc9RC+GxIPpSYuDb9Zohke1bO5Mw3DCJlzz/elI=; b=FHuIqJ+UQ4+wR/VgAiO/hmm4nSVzlIQdQMOzAgDR+AAfjF3UQa+fgaqHwqZ3lCKp8jd/zM 10PvG93TUYpg4sLx+fxBrmTJNWFo4u0ve25SIxdDBzqse5ZGBWPbUzlh8Fpy1itkCYE/f7 NiOV47SL3hJJlWGE2m/P8PT8Die9bf4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-rbRhs3UBOjy7Vsl7QcTlNA-1; Thu, 11 Apr 2024 09:55:12 -0400 X-MC-Unique: rbRhs3UBOjy7Vsl7QcTlNA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-416e58bdc1eso9705885e9.3 for ; Thu, 11 Apr 2024 06:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712843710; x=1713448510; 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=Q4rQfc9RC+GxIPpSYuDb9Zohke1bO5Mw3DCJlzz/elI=; b=Di2s3qIhlNRnu5SDZoRFYPUnY6b5vzZciB3H8DI6nvEhWbjda4DH8AP9RwdWBpwwsz SxS/60y3xUgNeuPau2x9mJXR60vWK2cWuL7sc5E6vMRAiks992PLGE6CsaaWerrA9lZX o3ZaSoBRpNWiEzCFgymrvpA742yJka/KEOMtauARllQpCbYcgVTxJh33Zih8aKO2g4Ic EOrh3Rveo/cDUaw+QB8MW+6957NPwdG5Y6QgShEn4aSbZCRnifYDxWMvnPDYMs2lk4V3 O58QOLs512ID1E/gY4I62yUISccw/1CHeAFbgDGwIc3o8P4rgX+sHQ3YYBAGKTYsuLya XvHQ== X-Forwarded-Encrypted: i=1; AJvYcCViqFydXLbR0eMSyWNJWZ+sZ7GlvIrliLa8wySKqXpZ43J13oLsIFWGstsLh3Q1DW1eAMMHcAR5C5rcHLw2WE9ki9yL79zpaTC1mxXf X-Gm-Message-State: AOJu0YxOZl8+Gp84ckmKUkKZcPsvcbLJzbPmaLBYHZHA8Er9ClQJTPzq Oemh9ipqj+Hin+dCXv1NcYw+C9FhSqhkyV6NZH+Fz82Bm6PHl0bJxwVxnhG3ywd0x1tgtE00INI TJ/m4ok3X8uzpwLl2qXxUZ9d8OSHxwAYrqPBANpiOMb34fQrCSGZHlc6ZqsmSbA== X-Received: by 2002:a05:600c:350b:b0:414:868d:1cbe with SMTP id h11-20020a05600c350b00b00414868d1cbemr4187125wmq.9.1712843710565; Thu, 11 Apr 2024 06:55:10 -0700 (PDT) X-Received: by 2002:a05:600c:350b:b0:414:868d:1cbe with SMTP id h11-20020a05600c350b00b00414868d1cbemr4187111wmq.9.1712843710113; Thu, 11 Apr 2024 06:55:10 -0700 (PDT) Received: from ?IPV6:2003:cb:c724:4300:430f:1c83:1abc:1d66? (p200300cbc7244300430f1c831abc1d66.dip0.t-ipconnect.de. [2003:cb:c724:4300:430f:1c83:1abc:1d66]) by smtp.gmail.com with ESMTPSA id h18-20020a5d4312000000b003455e5d2569sm1900594wrq.0.2024.04.11.06.55.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Apr 2024 06:55:09 -0700 (PDT) Message-ID: Date: Thu, 11 Apr 2024 15:55:08 +0200 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 v5 1/2] mm/madvise: optimize lazyfreeing with mTHP in madvise_free To: Ryan Roberts , Lance Yang Cc: akpm@linux-foundation.org, 21cnbao@gmail.com, mhocko@suse.com, fengwei.yin@intel.com, zokeefe@google.com, shy828301@gmail.com, xiehuan09@gmail.com, wangkefeng.wang@huawei.com, songmuchun@bytedance.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240408042437.10951-1-ioworker0@gmail.com> <20240408042437.10951-2-ioworker0@gmail.com> <38c4add8-53a2-49ca-9f1b-f62c2ee3e764@arm.com> <013334d5-62d2-4256-8045-168893a0a0cf@redhat.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+5qaSr0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HIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+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 11.04.24 15:51, Ryan Roberts wrote: > On 11/04/2024 13:23, Lance Yang wrote: >> On Thu, Apr 11, 2024 at 7:27 PM Ryan Roberts wrote: >>> >>> On 11/04/2024 12:20, David Hildenbrand wrote: >>>> On 11.04.24 13:11, Ryan Roberts wrote: >>>>> On 08/04/2024 05:24, Lance Yang wrote: >>>>>> This patch optimizes lazyfreeing with PTE-mapped mTHP[1] >>>>>> (Inspired by David Hildenbrand[2]). We aim to avoid unnecessary folio >>>>>> splitting if the large folio is fully mapped within the target range. >>>>>> >>>>>> If a large folio is locked or shared, or if we fail to split it, we just >>>>>> leave it in place and advance to the next PTE in the range. But note that >>>>>> the behavior is changed; previously, any failure of this sort would cause >>>>>> the entire operation to give up. As large folios become more common, >>>>>> sticking to the old way could result in wasted opportunities. >>>>>> >>>>>> On an Intel I5 CPU, lazyfreeing a 1GiB VMA backed by PTE-mapped folios of >>>>>> the same size results in the following runtimes for madvise(MADV_FREE) in >>>>>> seconds (shorter is better): >>>>>> >>>>>> Folio Size | Old | New | Change >>>>>> ------------------------------------------ >>>>>> 4KiB | 0.590251 | 0.590259 | 0% >>>>>> 16KiB | 2.990447 | 0.185655 | -94% >>>>>> 32KiB | 2.547831 | 0.104870 | -95% >>>>>> 64KiB | 2.457796 | 0.052812 | -97% >>>>>> 128KiB | 2.281034 | 0.032777 | -99% >>>>>> 256KiB | 2.230387 | 0.017496 | -99% >>>>>> 512KiB | 2.189106 | 0.010781 | -99% >>>>>> 1024KiB | 2.183949 | 0.007753 | -99% >>>>>> 2048KiB | 0.002799 | 0.002804 | 0% >>>>>> >>>>>> [1] https://lkml.kernel.org/r/20231207161211.2374093-5-ryan.roberts@arm.com >>>>>> [2] https://lore.kernel.org/linux-mm/20240214204435.167852-1-david@redhat.com >>>>>> >>>>>> Signed-off-by: Lance Yang >>>>>> --- >>>>>> include/linux/pgtable.h | 34 +++++++++ >>>>>> mm/internal.h | 12 +++- >>>>>> mm/madvise.c | 149 ++++++++++++++++++++++------------------ >>>>>> mm/memory.c | 4 +- >>>>>> 4 files changed, 129 insertions(+), 70 deletions(-) >>>>>> >>>>>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >>>>>> index 0f4b2faa1d71..4dd442787420 100644 >>>>>> --- a/include/linux/pgtable.h >>>>>> +++ b/include/linux/pgtable.h >>>>>> @@ -489,6 +489,40 @@ static inline pte_t ptep_get_and_clear(struct mm_struct >>>>>> *mm, >>>>>> } >>>>>> #endif >>>>>> +#ifndef mkold_clean_ptes >>>>>> +/** >>>>>> + * mkold_clean_ptes - Mark PTEs that map consecutive pages of the same folio >>>>>> + * as old and clean. >>>>>> + * @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 mark old and clean. >>>>>> + * >>>>>> + * May be overridden by the architecture; otherwise, implemented by >>>>>> + * get_and_clear/modify/set for each pte in the range. >>>>>> + * >>>>>> + * 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. >>>>>> + */ >>>>>> +static inline void mkold_clean_ptes(struct mm_struct *mm, unsigned long addr, >>>>>> + pte_t *ptep, unsigned int nr) >>>>> >> >> Thanks for the suggestions, Ryan, David! >> >>>>> Just thinking out loud, I wonder if it would be cleaner to convert mkold_ptes() >>>>> (which I added as part of swap-out) to something like: >> >> Yeah, this is definitely cleaner than before. >> >>>>> >>>>> clear_young_dirty_ptes(struct mm_struct *mm, unsigned long addr, >>>>> pte_t *ptep, unsigned int nr, >>>>> bool clear_young, bool clear_dirty); >>>>> >>>>> Then we can use the same function for both use cases and also have the ability >>>>> to only clear dirty in future if we ever need it. The other advantage is that we >>>>> only need to plumb a single function down the arm64 arch code. As it currently >>>>> stands, those 2 functions would be duplicating most of their code. >> >> Agreed. It's indeed a good idea to use a single function for both use cases. >> >>>> >>>> Yes. Maybe better use proper __bitwise flags, the compiler should be smart >>>> enough to optimize either way. >> >> Nice. I'll use the __bitwise flags as the input. >> >>> >>> Agreed. I was also thinking perhaps it makes sense to start using output bitwise >>> flags for folio_pte_batch() since this patch set takes us up to 3 optional bool >>> pointers for different things. Might be cleaner to have input flags to tell it >>> what we care about and output flags to highlight those things. I guess the >>> compiler should be able to optimize in the same way. >>> >> >> Should I start using output bitwise flags for folio_pte_batch() in >> this patch set? > > I don't think its crucial (yet). I'd leave it as you have done it for now, > unless David shouts. Let's do that separately, and investigate if the compiler actually is smart enough ... :) -- Cheers, David / dhildenb