Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2365562rdb; Mon, 12 Feb 2024 02:20:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnUA2zZeofGbocRZoj+q2hALDOyl5Df1xzSwG5Iztuvrb6h1lFVeRnCOvZtrJSnfo8cvZu X-Received: by 2002:a17:90a:ea86:b0:296:dfd7:ed20 with SMTP id h6-20020a17090aea8600b00296dfd7ed20mr3067127pjz.31.1707733233467; Mon, 12 Feb 2024 02:20:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707733233; cv=pass; d=google.com; s=arc-20160816; b=k4/UBGrwZ7IMFilc/ABkfG7B9q36LDfn6Yspl6Bgf4LixlHH3bA5kvGODfwaupGEhQ jezUe4aPZ4YmIJoWkqfsufLN4SzVwaNzKYkhIIa2VqOtKIyY42r4tomSgVUn6Ng1gdpQ OHqazb5yF+juvWS7obcNVyIbD72hQbnkCdACvRHNKrMOa7qcbDLC2TkBu2TDwPy/sq1E YZaX0GKrC9orqc4t+Ods3Zj/h5RkJhvWWFF59+hqodbZ8dV1tWTUohvPnwtU6cTLB30j jdzdEaHCMLknVMqJ8Xsj5JBQwEHRpTWZNnUwEeYSLX4DLlDSsykS4EpNcZPXTzi2dv2x Nugw== 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=+2pRSCdMqyAZN8/VuuYCHaUNoBN7lwTPUXnd9XEGQ+w=; fh=f/9QAltWHoqtqeE6v4gZ08fqKqhBcnicrdHczpl9EFs=; b=d/cV02TQEqgddNFjz8M1CIilrcVaxZ6r9CNSSU7FS07yPRLv/7xOA8uYkbOmnqceKf zJjfbVxxre/Ut2gOWq3cIfagszvjRwvWampOTiUrpYLOK3Ta5RW9pshQR5WdaF/vW1/h OpXBuFDlaT5PeZ3hufewJYJr2rtyOhe/GfnXCAsyFl8Cg6aCx04s9YBVLrdf1yrkTk9Z bFBpnE3j1KPELZP1cu8oI7YMYFMkHfqYcDJh8qvuuhZA+xWOCYaRRmMizW0rIlyEMcqv aa9uSPcW49GRqqAD1bEcT6zzyno+gzK1z9aYnjL/Yrk66/aQgRxOqmO1NzTc/QumDwl2 j4+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cn+lP0go; 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-61285-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCU1kLN8Ire5Bc7CmHYi/0xopkBwTPgl1njALbvvFyjXBXgjVXwP9Ml5tL3G4/wvktp8QlC3o333xlrUR1WWJ+hBm1WDZKgZZUYghkmiGw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id st3-20020a17090b1fc300b00295bc517280si71280pjb.136.2024.02.12.02.20.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 02:20:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61285-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=cn+lP0go; 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-61285-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61285-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 CFB4528695A for ; Mon, 12 Feb 2024 10:12:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 507F717C72; Mon, 12 Feb 2024 10:11:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cn+lP0go" 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 69C8F17BD5 for ; Mon, 12 Feb 2024 10:11:51 +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=1707732714; cv=none; b=gvlbD6PKEYZ716KIvgHp9XvdvNH9Pg++Vr2R1cja+iMfwvgbhnTbU+7Dk6OskzLSGi66AbrT4l4lw008VcsOXTBkOKrlSSCt/TyVcYIoEkBMgDYWZfOfTc2LKf53deX+xlO91L8Fy1Xg0L6JdoarPGAfzl+odBrXvF3W7yu2zUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707732714; c=relaxed/simple; bh=EsDLRCNgBBkHpMvWo3dkQLR5TLheexE1oSgsf7G0GBQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CpjwPbdbyf1ZCfNVn86z8S40WhiaEZinkPVws556lKB9lIN9bPFL60kgaMQ7pw47PzhygIgvyr/OBQ5pI0fEEDFI+2HiByDYKMYZk2swgZSQ7l2TcCNVacbfLUfTCd4jfd6SjrQxLJjaRelf9UMwiDXginEXUx/KSIbFvLqawLE= 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=cn+lP0go; 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=1707732710; 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=+2pRSCdMqyAZN8/VuuYCHaUNoBN7lwTPUXnd9XEGQ+w=; b=cn+lP0goCPBVtsDhdpAR8yvB98CoHTvJlcValHa3p0dZl0mRvkUqZB7mbvsAOcvg9bW4r3 9YHTN1CCBjoUnY9IRLi7cARWyKJy9pJtDbBuuPcV8HIuHmhIuRifFA0o6Q3CdxVuNLSJoV inKSjpx8JMC1kRTXf3cTa0ICgNkFMWM= 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-453-uZjpWf5kM7eMIzqFkTXQ_g-1; Mon, 12 Feb 2024 05:11:48 -0500 X-MC-Unique: uZjpWf5kM7eMIzqFkTXQ_g-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40ef9e08fffso15893815e9.0 for ; Mon, 12 Feb 2024 02:11:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707732707; x=1708337507; 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=+2pRSCdMqyAZN8/VuuYCHaUNoBN7lwTPUXnd9XEGQ+w=; b=n2CYj5qxG7qnePxiV9G0gRyXNnaY2/jpVRfZ30lttfrodZ9s+LY/fr980tOXmBYoYh 2649xEatsLbCH29i1YcomRZAcBMk5JiWlmy4mOBOaKJbT8xwn32S251T3bzHpB99eQAV t5V27JZmgfY18WdJOCgjSC2h7lqoVi32RjOkLX376oaUrmRLJwx6hFMjPBRNF2hrlCT3 CTfJ0Km2DqwIt/ltpt29RXbHceYotMRyg2KqU1773H3zp/Ss9u8FNb4RaWswPmbyMmuT pYwxT6B2Nlf4QZWpKLGTMKMgSSK/+GhYLpbaciEAPc1kkeRBK72+mnYqofEthsWWYGQV EmfQ== X-Gm-Message-State: AOJu0YxzvQ0MsfXKr6DHtiubNvDdRFBjXX4ZygY1AQ9QPuA4HXQEreNW vj1oj+7RuPaNKmYLkewrWLof2hcNbozZzdmaIr4AazflM3D36SXaIhvwIAB03Xbzi4YBx9J3OiY entFUCCxvVrAXY4h0sn3mPZ8kgUX/8l1UKK9sa9oVa71KR1BLyAuQKjRPUzaCEQ== X-Received: by 2002:a05:600c:600e:b0:410:be25:12bf with SMTP id az14-20020a05600c600e00b00410be2512bfmr2510586wmb.38.1707732707073; Mon, 12 Feb 2024 02:11:47 -0800 (PST) X-Received: by 2002:a05:600c:600e:b0:410:be25:12bf with SMTP id az14-20020a05600c600e00b00410be2512bfmr2510563wmb.38.1707732706666; Mon, 12 Feb 2024 02:11:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVwkAeAYQR7Gfoxupr5qBG9m0EFbv7DDI7aCfZtMNyIROIXA/SOrjkaJ59sr8xsqiaVCkCmlEIRjxy3J0wXfxX4p/V/LReolwctKJtaf6B3xBn7OrP0bc+txI9JVmFNAWwZNO6OMGWo3IXumCONO6uNSMmNTfbFmAY4pOA1lJgpDYGCD7L+3n273ujqqyssnrkBYDPGUmeZCNVHvSm6nOQmhOiwdAGGkbh9s4spMdJMjZUHweVEwDvqzZu+WY2iXCqg6PvKFOcrzgEd0inHm2VWhnlxmT+IxhcswK98pkwM1pdbqKpMZ8Ajk1JT4NE78LQt/mXy49lkqHahYzz6hjzT+dfzIx4V3DXSeAokKyb1gnl/iSmZRlqLUCcOgsmg3+wwBBOuVupln+MiH6egoWuOb0D3bdc75Mj8jQ3mkZXn+noa+I0RKgGk58qf9AmfYfgmoUeVxAHFDz6H2fGJSuPdxMMemhULInkfywbgcL4XDyX9Z53mEt7zOhan4AtbDYaknEn4fCZ/1MCYlw3aWeqpmwzPFZmOAeLuSio1iOcsGub9eXKx0M2nKuxJ4n1jPEP1oNBvLg89cxTfdtPQA43Yj+xKlc5QfNDyXl6bRRX286HkHyWSz/FRQYbEwdh7nAxD+scmPiWtw4qBIOUM0qZ0NG8OHtJi963eUHH1Om8YBT7l+DoZEuPwB1JBihSLrOPpnPqsDQCQDEYMqPRaoFdAtOdGG27xai7PTo0pl2W0EdZROwY= Received: from ?IPV6:2003:cb:c730:2200:7229:83b1:524e:283a? (p200300cbc7302200722983b1524e283a.dip0.t-ipconnect.de. [2003:cb:c730:2200:7229:83b1:524e:283a]) by smtp.gmail.com with ESMTPSA id bd27-20020a05600c1f1b00b00410d3b8c4c1sm2565365wmb.31.2024.02.12.02.11.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 02:11:46 -0800 (PST) Message-ID: <6c66f7ca-4b14-4bbb-bf06-e81b3481b03f@redhat.com> Date: Mon, 12 Feb 2024 11:11:44 +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 v2 09/10] mm/mmu_gather: improve cond_resched() handling with large folios and expensive page freeing Content-Language: en-US To: Ryan Roberts , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Catalin Marinas , Yin Fengwei , Michal Hocko , 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 References: <20240209221509.585251-1-david@redhat.com> <20240209221509.585251-10-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/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYq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jdng+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: 7bit Hi Ryan, >> -static void tlb_batch_pages_flush(struct mmu_gather *tlb) >> +static void __tlb_batch_free_encoded_pages(struct mmu_gather_batch *batch) >> { >> - struct mmu_gather_batch *batch; >> - >> - for (batch = &tlb->local; batch && batch->nr; batch = batch->next) { >> - struct encoded_page **pages = batch->encoded_pages; >> + struct encoded_page **pages = batch->encoded_pages; >> + unsigned int nr, nr_pages; >> >> + /* >> + * We might end up freeing a lot of pages. Reschedule on a regular >> + * basis to avoid soft lockups in configurations without full >> + * preemption enabled. The magic number of 512 folios seems to work. >> + */ >> + if (!page_poisoning_enabled_static() && !want_init_on_free()) { > > Is the performance win really worth 2 separate implementations keyed off this? > It seems a bit fragile, in case any other operations get added to free which are > proportional to size in future. Why not just always do the conservative version? I really don't want to iterate over all entries on the "sane" common case. We already do that two times: a) free_pages_and_swap_cache() b) release_pages() Only the latter really is required, and I'm planning on removing the one in (a) to move it into (b) as well. So I keep it separate to keep any unnecessary overhead to the setups that are already terribly slow. No need to iterate a page full of entries if it can be easily avoided. Especially, no need to degrade the common order-0 case. > >> while (batch->nr) { >> - /* >> - * limit free batch count when PAGE_SIZE > 4K >> - */ >> - unsigned int nr = min(512U, batch->nr); >> + nr = min(512, batch->nr); > > If any entries are for more than 1 page, nr_pages will also be encoded in the > batch, so effectively this could be limiting to 256 actual folios (half of 512). Right, in the patch description I state "256 folio fragments". It's up to 512 folios (order-0). > Is it worth checking for ENCODED_PAGE_BIT_NR_PAGES_NEXT and limiting accordingly? At least with 4k page size, we never have more than 510 (IIRC) entries per batch page. So any such optimization would only matter for large page sizes, which I don't think is worth it. Which exact optimization do you have in mind and would it really make a difference? > > nit: You're using 512 magic number in 2 places now; perhaps make a macro? I played 3 times with macro names (including just using something "intuitive" like MAX_ORDER_NR_PAGES) but returned to just using 512. That cond_resched() handling is just absolutely disgusting, one way or the other. Do you have a good idea for a macro name? > >> >> /* >> * Make sure we cover page + nr_pages, and don't leave >> @@ -119,6 +120,37 @@ static void tlb_batch_pages_flush(struct mmu_gather *tlb) >> cond_resched(); >> } >> } >> + >> + /* >> + * With page poisoning and init_on_free, the time it takes to free >> + * memory grows proportionally with the actual memory size. Therefore, >> + * limit based on the actual memory size and not the number of involved >> + * folios. >> + */ >> + while (batch->nr) { >> + for (nr = 0, nr_pages = 0; >> + nr < batch->nr && nr_pages < 512; nr++) { >> + if (unlikely(encoded_page_flags(pages[nr]) & >> + ENCODED_PAGE_BIT_NR_PAGES_NEXT)) >> + nr_pages += encoded_nr_pages(pages[++nr]); >> + else >> + nr_pages++; >> + } > > I guess worst case here is freeing (511 + 8192) * 64K pages = ~544M. That's up > from the old limit of 512 * 64K = 32M, and 511 pages bigger than your statement > in the commit log. Are you comfortable with this? I guess the only alternative > is to start splitting a batch which would be really messy. I agree your approach > is preferable if 544M is acceptable. Right, I have in the description: "if we cannot even free a single MAX_ORDER page on a system without running into soft lockups, something else is already completely bogus.". That would be 8192 pages on arm64. Anybody freeing a PMD-mapped THP would be in trouble already and should just reconsider life choices running such a machine. We could have 511 more pages, yes. If 8192 don't trigger a soft-lockup, I am confident that 511 more pages won't make a difference. But, if that ever is a problem, we can butcher this code as much as we want, because performance with poisoning/zeroing is already down the drain. As you say, splitting even further is messy, so I rather avoid that unless really required. -- Cheers, David / dhildenb