Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1569764rdb; Wed, 31 Jan 2024 02:43:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5Ydeyn2mbY6wGHgj5Tw4xyPAvRwlvhklxs7X4i5uFhL+AvvOmhNAO2E5dN+eAM/tP2rau X-Received: by 2002:ac8:5fcc:0:b0:42a:3176:6b10 with SMTP id k12-20020ac85fcc000000b0042a31766b10mr1485160qta.32.1706697804122; Wed, 31 Jan 2024 02:43:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706697804; cv=pass; d=google.com; s=arc-20160816; b=LMxRuGACHsVgh01besLC6eK41dB9AgcUG0r/y8ojmazuGTiEgmTnaK6yyD6jqHaNMx cgxOCzizDdEdwc/jM3WWdAhJGCD42cvJImzhBSAmLH3BgW+6KD2PhyFM01QcBQTcqKyZ 6KGz2q69CB/ohqA9c/2XpP8OAq5CivrENw4XhcvzlIqKDFCzMwZaIK2jlFLuYnz9H/9n S/HI9OhSgLsvUgchplKj4b+UJ0VnTs6pSl/H3O4CEsD/lng0daQbLDXQWHXpM+UYD74b fDUWuX8JAY33wXEDv8LOYFVPUe1V5dpsqPOF5aek7ir9/ML7nRMnd1Z3qtWUqAe5RZIu C2hA== 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=SHlw8k+TqYX0IO/Wrb506XALAVZ388XuzsT+3MrGA+U=; fh=qtGOaRa3qJCTKy41i6MTf6EpUbo3O4EdyrYCusWeQaw=; b=y//xnn8RbNfrFise9prmfOE7eXDbtsvOoKF5tZNlauhCZSML4IBk5Fo5tbLG6ASWZY tuCVN93293cPgSSYXtXB3S3IWrVhG5dvOzV1Ip5jUOSh9VHtayCt45qm9bCKGOGjLABe anYIRWynLdY0nREVnUDgz27xJqW/ObTrx3/Anss3tCJ2diKB3ILGf5R90T0XAcTPCFYa dnxgSLj5OQnIvlh0fWne7UzCqBFL9gZ4UUNYSc/YmZOeM4Uc8IO4AV65c1ydt8wnLEcJ bXf9GAF6Qip3XID+UgyvAWiY25lvTA06KhV3pvV7Ipohe9tf1kY/W3XcOVVAqf3pT6bY H+ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LdqKxetn; 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-46251-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCV6iuMEISgfEFrRa2NNjvJ+X3TR1NGgKXFn8QA/U+R5NJqRMHF/NGrTvtwnqXTLTILRyS64ShuaSzZsxptShaB4JNLZ4z+lZXIGQiB+Lw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f3-20020ac87f03000000b0042a3c052248si11728754qtk.314.2024.01.31.02.43.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 02:43:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46251-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=LdqKxetn; 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-46251-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46251-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 A430F1C2990D for ; Wed, 31 Jan 2024 10:43:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1B4A60888; Wed, 31 Jan 2024 10:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LdqKxetn" 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 09B8769D07 for ; Wed, 31 Jan 2024 10:43:13 +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=1706697795; cv=none; b=cnmHp2xOLKc8VqSqVABH9+dI5IHFyREUmxmM/2ZxkAv0mN4fBSDcksb4sowlxT3180qOf9yaSZVcyJqbj75R8OgJA+eyG7c2UgiM/WBzenfEsKmnXtCj7bXQYEH/klA3zFbEyaukLDY+AssldcYHGlWW7BLg9LmC2BcCYLKDTV8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706697795; c=relaxed/simple; bh=VKdh5ojB9n4H1igdsHNgzeWTEn+XBSJ7faZ2IWNWiks=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=e4t9b2K9UunYLJ1EtpQVtY36FsOBnDmA6xkZNOFHwxsFrLGRsxBrEhjdu14Z0dc365AAS/88TOy66z1IMY+EZJpqPejg8Mck5U7KBEslQVje9I/k87ANepDBmccvscUES2Lu0e6rn6sENC6tuO6DO8gdo2V7nJKxlhV1pe74gRY= 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=LdqKxetn; 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=1706697792; 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=SHlw8k+TqYX0IO/Wrb506XALAVZ388XuzsT+3MrGA+U=; b=LdqKxetnuc7W06qCR0uC850anyCtEWEpmkxqP/pF9HFIYpqHXrc+py8PIv2jJoULBAHmLP q1OFMqRtkFYeJ/NN4JILqEm2Ffk1jiKToQRMASdqT7O10dj39oGM9gZDdqC+CohpxZrrhK r6YM4cRDwzD5xTIAaGYN4UVwcbgNZlg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-YCS-MM4hM3SzydLVpS_gMg-1; Wed, 31 Jan 2024 05:43:10 -0500 X-MC-Unique: YCS-MM4hM3SzydLVpS_gMg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40fb64f802dso670325e9.1 for ; Wed, 31 Jan 2024 02:43:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706697789; x=1707302589; 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=SHlw8k+TqYX0IO/Wrb506XALAVZ388XuzsT+3MrGA+U=; b=arya1yoXGWE3Cp2Tb7AoSPaqHifL0dqwLyTsTNybLdtRneYgZ4NClJOpNV7GaWClSX qyBBkAGE2giIRPfVqqY6vV8WZxVRw14k6fP/A6c7/8DliKCnQhJ6thNDpWWUA4QTpJL0 t5W0/SSLOMQ4sWxewk11KPPFnVHyw5r6SfZWF8Fh3y7DZ/Mh+C4d5tJWTUIEKmRt41tn M9yNOpI/IcpN41CaNoFItdvuqUuWrc4/pPuzR7pVifVNhYQCThjaEJrqOIWTf1c8Ex4/ bsrEyBs4ZWnKlvif+lXS6kQ3W1JbN7RZTLrovPtYipaQXCiGNkvxZzyTrOeBgz2vV7aE wPrA== X-Gm-Message-State: AOJu0YxY8MC/uxK2BQYTFUbNeS0ySgME2iHRfz5eg/HEq7My1pXwtgF4 sKJYZ980foIdVOEPKi89VF99MLydy2eYyfOr4TXJ0bIy9SHU9PhfpU6XOPHQbDVNuuY7IpiGQCK lMa8mcXvEw633cLMi4jcSOcJosf44pCIYE2WqlyughzGCUVbPoEvNGEAVJtP11Q== X-Received: by 2002:a05:600c:3b09:b0:40e:f693:94dc with SMTP id m9-20020a05600c3b0900b0040ef69394dcmr952902wms.11.1706697789721; Wed, 31 Jan 2024 02:43:09 -0800 (PST) X-Received: by 2002:a05:600c:3b09:b0:40e:f693:94dc with SMTP id m9-20020a05600c3b0900b0040ef69394dcmr952894wms.11.1706697789373; Wed, 31 Jan 2024 02:43:09 -0800 (PST) Received: from [10.32.64.237] (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id 23-20020a05600c021700b0040efb8f7158sm1192334wmi.15.2024.01.31.02.43.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jan 2024 02:43:09 -0800 (PST) Message-ID: <3739b705-b7c7-4d1b-b97d-7e55b99f64f6@redhat.com> Date: Wed, 31 Jan 2024 11:43:07 +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 v1 0/9] mm/memory: optimize unmap/zap with PTE-mapped THP Content-Language: en-US To: Yin Fengwei , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Ryan Roberts , Catalin Marinas , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, "Huang, Ying" References: <20240129143221.263763-1-david@redhat.com> <4ef64fd1-f605-4ddf-82e6-74b5e2c43892@intel.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/zt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oUTv03iO9El5f 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: <4ef64fd1-f605-4ddf-82e6-74b5e2c43892@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 31.01.24 03:20, Yin Fengwei wrote: > On 1/29/24 22:32, David Hildenbrand wrote: >> This series is based on [1] and must be applied on top of it. >> Similar to what we did with fork(), let's implement PTE batching >> during unmap/zap when processing PTE-mapped THPs. >> >> We collect consecutive PTEs that map consecutive pages of the same large >> folio, making sure that the other PTE bits are compatible, and (a) adjust >> the refcount only once per batch, (b) call rmap handling functions only >> once per batch, (c) perform batch PTE setting/updates and (d) perform TLB >> entry removal once per batch. >> >> Ryan was previously working on this in the context of cont-pte for >> arm64, int latest iteration [2] with a focus on arm6 with cont-pte only. >> This series implements the optimization for all architectures, independent >> of such PTE bits, teaches MMU gather/TLB code to be fully aware of such >> large-folio-pages batches as well, and amkes use of our new rmap batching >> function when removing the rmap. >> >> To achieve that, we have to enlighten MMU gather / page freeing code >> (i.e., everything that consumes encoded_page) to process unmapping >> of consecutive pages that all belong to the same large folio. I'm being >> very careful to not degrade order-0 performance, and it looks like I >> managed to achieve that. > > One possible scenario: > If all the folio is 2M size folio, then one full batch could hold 510M memory. > Is it too much regarding one full batch before just can hold (2M - 4096 * 2) > memory? Good point, we do have CONFIG_INIT_ON_FREE_DEFAULT_ON. I don't remember if init_on_free or init_on_alloc was used in production systems. In tlb_batch_pages_flush(), there is a cond_resched() to limit the number of entries we process. So if that is actually problematic, we'd run into a soft-lockup and need another cond_resched() [I have some faint recollection that people are working on removing cond_resched() completely]. One could do some counting in free_pages_and_swap_cache() (where we iterate all entries already) and insert cond_resched+release_pages() for every (e.g., 512) pages. -- Cheers, David / dhildenb