From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21C2BC4829B for ; Mon, 12 Feb 2024 10:56:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A02956B007B; Mon, 12 Feb 2024 05:56:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B25D6B0080; Mon, 12 Feb 2024 05:56:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8529F6B0081; Mon, 12 Feb 2024 05:56:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 744BB6B007B for ; Mon, 12 Feb 2024 05:56:19 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 45D571C11B7 for ; Mon, 12 Feb 2024 10:56:19 +0000 (UTC) X-FDA: 81782847678.18.90A36B6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id F258C18000B for ; Mon, 12 Feb 2024 10:56:16 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h7KIR9Rz; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707735377; h=from:from:sender: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:dkim-signature; bh=UV8bdgpmsnr14qmRHmP9LgSt0o7Rd0LaIu3KD5rWrF0=; b=iZKtT61kWbIIoxCqMRLEoHLoqnjNyHMtx5BoDZo2ugjiyk8EeTquJFK84rpXaMlIilTaww d0g2Dog0npCZqV9X7N9kfxChtMlEaUrdM5iEq6odFvQnVIGDKBNp6vpDOajmF3zdyykpyh yfWFz2Wwlwu1Bt9qNi5y6bAOtR3Fz80= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h7KIR9Rz; spf=pass (imf16.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707735377; a=rsa-sha256; cv=none; b=wD+ePeUSOKwKgGm3rM8DNJm7/xoEp+Jysq0qHBQpCABlSg415Y7OuSvk/hFtFxUuyqVW/V ZI0WMyPL0NNmAtF7GxiHsEiRdOuQvUSqpfS5cGvCy+X97w9pAB77Eqho7bJT+zY5jDQWT2 5nTwRblm6MaCP7scQbQmYimtSQ40f/g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707735376; 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=UV8bdgpmsnr14qmRHmP9LgSt0o7Rd0LaIu3KD5rWrF0=; b=h7KIR9Rz4a3igceraR+ptNBnjhQuJA3AL3aL/mm7J2zrc3/BdMuYgB4fdZ+4cLuVVuZ/j+ MJyI0af9nxC6YHmCkRscbewixz6xmPxP18ZQBR4FHlWDCAbktRlPEGlWk59bRcDVW6j6sS 4IlVb1JzlHYwVHw1y7iLg5jO7eD9vGU= 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-12-gVDyfe9_Miuw0xc-E3wBUQ-1; Mon, 12 Feb 2024 05:56:14 -0500 X-MC-Unique: gVDyfe9_Miuw0xc-E3wBUQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-33b844448dfso266450f8f.0 for ; Mon, 12 Feb 2024 02:56:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707735373; x=1708340173; 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=UV8bdgpmsnr14qmRHmP9LgSt0o7Rd0LaIu3KD5rWrF0=; b=ki58+y9MBoSPUp8caCF0Wl68NN1YghDozB/hJHf24JrdEUSLShO/3MIh41JpzpVPdY CnJW17/mW3nXb9QHp4Ze6jEUsUjakTZu8FAg23pW/M5h2yg57BVpxJvJ6r6tzVnsHT9j Y+R3x9W21uMyC/vCquW9I5AjWiynnAw+eMod0K1cP8B2vDzaX1Y02SAB5wSm1xICslBN omI2pHRACrwP4v8w/+5CrEKLzMcxWYFvCtgdwnGR2SrIxWqRmxLCOkv7GFK83m3DAvFs ENgD+nyKx4dQZuSYZ8CoF1r+OrV6RCwqoZFtxgdlZArijei/Hg2+B50d2d8b2hFWgER/ m4dQ== X-Gm-Message-State: AOJu0YyAnvZUsDPSHKpUyQdR0QN2VD7PMbSnUXd/ajfQO4PRbbbZ4NaJ z0+VFKyaXc1WzwjCo+dYL/Hx95ce75z0P9qtoSlH8//NpuJmLdkjG9iiZFCEuSy7mOQLn/PgpYq XarXXx8abyPU+k2FQkcVl6ya1cHwl9/OokJSrVH1QkQsJh6G2 X-Received: by 2002:adf:f783:0:b0:33b:6d36:de48 with SMTP id q3-20020adff783000000b0033b6d36de48mr4787409wrp.26.1707735373492; Mon, 12 Feb 2024 02:56:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/IczVnpqG7OkL74qqeEO8Efr3rPNiI2sLLGfEI45Sntu72wIYKx9fA7rHUuSCnjIuJqb7rg== X-Received: by 2002:adf:f783:0:b0:33b:6d36:de48 with SMTP id q3-20020adff783000000b0033b6d36de48mr4787383wrp.26.1707735373053; Mon, 12 Feb 2024 02:56:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXjROoncsMS9ff/iccqKfqz0fi4PCC42VOc6vvwHBjhJXjzTpJlaTL/AcE4wlksfudxTI8Nufs1TaBw9FXcJAvIGseizwGfpxHdXA91AMi85HfqCVcWrZmAhA3vZkmt2Apb8EUGV7dsVepCozjNuALNAFILi4S1lEWPFA2EpYHWGbnq+al1ucIyDhLO6GYlvPt6CH52fPmJ6WZpvf6zSbVQ5BKD2Kux+GliB5ikYPH4IeWitD+J94+wHP/34NkYzOoGAVf5cDaKG2D+z8Tcj90Jllx2pQr/4FEJcvOX/r0uaPpwRIphvNTZrwlCMR/ofGFaNaFBcrakwcc6oCnzK4UH1GTnXGyqA3ct2TtXIGbXz5SgvPmcheBpCfmU3JBbtYjYJVOq/Cu9kPFBq+iV7BynOkk+LoYeavXAsKrJUEoxNqk7gJl1hVxmdbaHNRJ8GH/Xrep1FcL7ndv35Ff16lr+2y+KVyZcjp3vcFmekmjm1fP3DsAUD1AaCsrZ8ui/QWYnR8UJrHN1i4j0VP2kvQx3aAjFGQAhbf0rpwA914ul/9WCChdJIzh0+GSYZiRdVIOwT3amXD4KZNjOzHEfzMFG927T7BqZceLrfF6cUarIizPaeuFRSVL84WFcql7Rw3wC+P9g9pTa3pJGcQ+4RTKA649h0MJBUEeEzta0LzDdHl4QDvtp6+86jFU39Hh8luio0tRTYoC9rHDbADrYT6bGtiodX2nkZeYloJipmlKST9qoRl8= 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 bq26-20020a5d5a1a000000b0033b4335dce5sm6603003wrb.85.2024.02.12.02.56.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 02:56:12 -0800 (PST) Message-ID: Date: Mon, 12 Feb 2024 11:56:11 +0100 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 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> <6c66f7ca-4b14-4bbb-bf06-e81b3481b03f@redhat.com> <590946ad-a538-4c99-947f-93455c2d96c6@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+ag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8h+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: <590946ad-a538-4c99-947f-93455c2d96c6@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F258C18000B X-Rspam-User: X-Stat-Signature: mr9rhx553iiyqy81ep5suup8etc7uu63 X-Rspamd-Server: rspam01 X-HE-Tag: 1707735376-616717 X-HE-Meta: U2FsdGVkX18qKinvl/ZD2KuSi4lW4Q9ngfFQKSWgA3MZYVZ/1Jgg5JuJKRTUMq+wGhKu/F4LOmls036zogqw3AjOyr2mdnVqfWfKVb4HGRN2/re2W4MZlRIXrVjdsgXxDvntiZ5radbvG6u/RKClXNGSs1YarzPpeE6v6Z7pGDaEmAyWCfZqVReFOB2hV0Yk1S45vjVzLuGqY5Vn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PFeqIpWHkNxHgZnSR/3evS50Kbo+Ml6UWkYm/MWJtV2ulqqK8oHslZ9bd0IYpse+unDy/d2GQKpLKr0bhUi6qb5zaqXPHlT0HaaAByXaAMg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 12.02.24 11:32, Ryan Roberts wrote: > On 12/02/2024 10:11, David Hildenbrand wrote: >> 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. > > Yeah, I understand all that. But given this is all coming from an array, (so > easy to prefetch?) and will presumably all fit in the cache for the common case, > at least, so its hot for (a) and (b), does separating this out really make a > measurable performance difference? If yes then absolutely this optimizaiton > makes sense. But if not, I think its a bit questionable. I primarily added it because (a) we learned that each cycle counts during mmap() just like it does during fork(). (b) Linus was similarly concerned about optimizing out another batching walk in c47454823bd4 ("mm: mmu_gather: allow more than one batch of delayed rmaps"): "it needs to walk that array of pages while still holding the page table lock, and our mmu_gather infrastructure allows for batching quite a lot of pages. We may have thousands on pages queued up for freeing, and we wanted to walk only the last batch if we then added a dirty page to the queue." So if it matters enough for reducing the time we hold the page table lock, it surely adds "some" overhead in general. > > You're the boss though, so if your experience tells you this is neccessary, then > I'm ok with that. I did not do any measurements myself, I just did that intuitively as above. After all, it's all pretty straight forward (keeping the existing logic, we need a new one either way) and not that much code. So unless there are strong opinions, I'd just leave the common case as it was, and the odd case be special. > > By the way, Matthew had an RFC a while back that was doing some clever things > with batches further down the call chain (I think; be memory). Might be worth > taking a look at that if you are planning a follow up change to (a). > Do you have a pointer? >> >>> >>>>           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. > > Yep; agreed. > >> >> Which exact optimization do you have in mind and would it really make a difference? > > No I don't think it would make any difference, performance-wise. I'm just > pointing out that in pathalogical cases you could end up with half the number of > pages being freed at a time. Yes, I'll extend the patch description! > >> >>> >>> 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? > > MAX_NR_FOLIOS_PER_BATCH? > MAX_NR_FOLIOS_PER_FREE? > > I don't think the name has to be perfect, because its private to the c file; but > it ensures the 2 usages remain in sync if someone wants to change it in future. Makes sense, I'll use something along those lines. > >> >>> >>>>                 /* >>>>                * 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. >> > > Yep ok, I understand the argument better now - thanks. > I'll further extend the patch description. Thanks! -- Cheers, David / dhildenb