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 E198FC4345F for ; Fri, 26 Apr 2024 06:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24A226B0087; Fri, 26 Apr 2024 02:57:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D2F76B0088; Fri, 26 Apr 2024 02:57:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3F4B6B0089; Fri, 26 Apr 2024 02:57:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D10146B0087 for ; Fri, 26 Apr 2024 02:57:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5B390A07E7 for ; Fri, 26 Apr 2024 06:57:44 +0000 (UTC) X-FDA: 82050777648.21.ECB6D19 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 1EFC5A001D for ; Fri, 26 Apr 2024 06:57:41 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aqAUpGWz; spf=pass (imf15.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=1714114662; 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=S9YgOSSzhWQrtdlbF1hJCE17T/mb2rDP4iaqnDMJfb0=; b=dpk3sVMfwMi+uo3bDt1kp7h926hkvvHVnc56Yg3NGAsBTl0eqprv5x0uBRFp74wDZdhRXo wvlp9b2T4DqQrkNe/qPFanbHs1Q33CtR7LiaOsT6Llt/d2eYN9/VGAeSihqm45YNZxHCTo ePO+Fu0FC13Bhq9BawF189D2CA3hHwQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aqAUpGWz; spf=pass (imf15.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=1714114662; a=rsa-sha256; cv=none; b=gnCq1Wx8x08e5ozmrcGbnoafIlEZD3idC2P0QEdlOb4iQH8NQzzzthcZZeNGY5izbgcJZa GfEtXyXGh3DF5hZCN1P6tnJONz/nxnT8Qb2tAuCI+pSYQAIyPKB0iYueupT3NpwSXTmJ9c S0F3JXlI8dY7eCxKYKPwQya5GRRGT8k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714114661; 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=S9YgOSSzhWQrtdlbF1hJCE17T/mb2rDP4iaqnDMJfb0=; b=aqAUpGWztkzeux0sJ5wr5cotkQALl5ZgCcQ0nVOq2SjqqvJpeekFzQGaiWU5zSudzbbk9S KnqmykC63DqGa8NjJxSOilTQnbac1UPp2/KtddE6/jPWRoVoJFG/89940WyURe3SJozUNh G571aCZ+bgItOQmDBhNLE1mVxwa+KTY= 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-54-p_EGi9tjM-ibU5GYKF8nDg-1; Fri, 26 Apr 2024 02:57:39 -0400 X-MC-Unique: p_EGi9tjM-ibU5GYKF8nDg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-34c68b0d27eso50177f8f.0 for ; Thu, 25 Apr 2024 23:57:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714114658; x=1714719458; 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=S9YgOSSzhWQrtdlbF1hJCE17T/mb2rDP4iaqnDMJfb0=; b=FbA43NR5Etiwki5CqqUTMEFWiucrDg0fol1ibPfy4UFZwiFa7SxLHPgNqAre0Qz85v 4CiEa2RL94XGYJ+xJC9/LaJHKiqmPV8IPY6h0tatFrYKVN3FYK7VfvKf1VUB5IG2Jqf8 cEXxgoDHnmFk6+zQfKxaHtrq644DHnrnuqY6aXgwS/6NUv1lwn3xTxRL9xUYB4WbyXun efdVjp7WVSmJb61KDeUqihteDh3BskpBE7CR77U9I25KG8Ve7bfzZZF8fwjfW7ABDQm0 xJftflKqnzZWlbUopdawK4WsZ5lNltIKAhbBQWxvb+2qLxjofEHKaT0M8FKDvQuqLSpk EPjw== X-Forwarded-Encrypted: i=1; AJvYcCXk6ywWP7/3KUIlZwpQKaWBlrX/+bE/P5Cavo88/ApgDN0cOTZcbQBa+koCHDbeQ5YlpJF4/ULVpAGYWk/N3mkuIrc= X-Gm-Message-State: AOJu0YzC4YpjD9HQcdzV6uflqcmBskWUuMwG6L2HuotlVbGUZDrV9NZ2 s1O9JPt/seW2a5FL6A7hrDiquawVswwQNOB91vx86wKedqw+mtZY+jC66mrs9Uo4saRC3VNB7V9 Rp6n8ciVMlv7cNcT7Vv+30CmUdhdQcFii1NhUxfJH54SV//A8 X-Received: by 2002:a5d:4dc1:0:b0:349:ffed:792d with SMTP id f1-20020a5d4dc1000000b00349ffed792dmr1495853wru.30.1714114658402; Thu, 25 Apr 2024 23:57:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiGcMtO3pvrqLzxCKrJCX59NpN1TNY/wPfeqt9MvGmQf29twl4GqizB6+lEhzfbJ8yP/FB2w== X-Received: by 2002:a5d:4dc1:0:b0:349:ffed:792d with SMTP id f1-20020a5d4dc1000000b00349ffed792dmr1495838wru.30.1714114657964; Thu, 25 Apr 2024 23:57:37 -0700 (PDT) Received: from ?IPV6:2003:cb:c726:6100:20f2:6848:5b74:ca82? (p200300cbc726610020f268485b74ca82.dip0.t-ipconnect.de. [2003:cb:c726:6100:20f2:6848:5b74:ca82]) by smtp.gmail.com with ESMTPSA id e24-20020a5d5958000000b0034c0fefd7d2sm3255775wri.23.2024.04.25.23.57.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Apr 2024 23:57:37 -0700 (PDT) Message-ID: Date: Fri, 26 Apr 2024 08:57:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] mm/khugepaged: replace page_mapcount() check by folio_likely_mapped_shared() To: John Hubbard , Matthew Wilcox Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Andrew Morton , Jonathan Corbet , "Kirill A . Shutemov" , Zi Yan , Yang Shi , Ryan Roberts References: <20240424122630.495788-1-david@redhat.com> <73de5556-e574-4ed7-a7fb-c4648e46206b@nvidia.com> <18b9acc9-9dc8-4857-83d1-952c94b69e01@nvidia.com> <7273b0d6-06e7-4741-b77b-b49949c46d63@redhat.com> <1a406a5f-1336-4051-a722-04b9ea2f54df@nvidia.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata=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Ab0NH/UCzcsstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB 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: <1a406a5f-1336-4051-a722-04b9ea2f54df@nvidia.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: 1EFC5A001D X-Stat-Signature: 37ykk6egqe3swowzxrzwfd59y5esem34 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1714114661-612406 X-HE-Meta: U2FsdGVkX1/Ev+ohDKiInrrgFLSqrPchanPHzPl+62UbfG/qYKdOAmBHc1RM58TzrDfQNdvMV+4TL9RC6jooh/N90Uc3ja4uLOABOuY0vRsw4cXo4WCTBx7Z9R2cU/Jk9S6AHqeepdKhk9uNVPUILLK4Gym8SF2K6awPLe/TYCRYfN84cwS4uVHqrEKdj4U5Hb0433bhBKS1KZDc7F/vviLGC206Ghop3sXfLDnApM8V/ZZX4GlsVULc1xmWDPf2JIrXj1yH/iWQL+oWlBdS9KsqV8eD+98AOuz7fLtoRf3zi+UibfEo5sS0JnIAerhJ5RhMx+hdebmdvnnEI7U8nU8M4Rh5aHpkKj2UxFUnhFEo7wFgusYUYEQAJnEDzhMzkZKNmZZdVWc6AtZ/5fiaUQwtNULVx1wKGgvy8imm0CWiZkmo/0QJA5Wcp6nPoUo61m5H0ykcQkRpYwHpFNvsZDcJ/O9evL+owKhncDayJC65LIKOfSQwsKes0xRyraEstPb8DzFvaq6hvQYm9BVE+wPbBxeW2alSj39CyOku84XH8YfBE93Y5+jNpReJrc87BUVXsyjNWKwkCQ7Tc2giywKsmNndSiyyZyquerlsuRe9cOkL13lsFl1g5jxSWSBSnfRj/ZojrONUihBp4xFCLfeewiK/vWYmLSol6SH4IUn54q3aaE+N+5mcWjx5gbsK0SH/b1FCnjsHlqGjS9bfKadDikSFRmbafDe/WDUIJah1g3xAsvu++syC7TN+EixqLRmh0zTe/abgPwKCN+2gRYuiwagoxjmMCCMP+kGZMM5cVuPUIDTOn0uJNhkA88j4rGfofc+vfJ3PWRcsaoQu2AlJnqT9GcxSU1DykcpRqcj8FdxYsD5csi3wJdTyHY5bZ9mtWbnPzBwUy8V15jOTRlQcnc5F8diFU0uTuynrm87YfM5tIFxYl00jzmSyH/KugzXHvenbm8pULwY2hB1 jVv+V2L5 NeaputD7y+3wDftuv4fh8/1Gj+5LCa5xQTPX9lrvvBVQH2/sYJQqIye6YtjqVuZLMyzHEgwjCmW1aef22SwWnTzIeI23UTfNTHdyNzQEbKLJccncrjqkDXb5jPb4dXiLfwv17iW17HXhz3/8zurz794SO68hA8aqDZFvr4zjWRu5FqShe9+7Xwb2DUBKsZIo4EBa1X+tHUPXyLJYI8V+rSEwxWHsth1YfStSvWuJd4H/4x012ZfR42qEOJVkcvNUZ07FHiSmkSgX/Cb0dMQFnkjVzkZeH2G0zEFxtKUqrzOtrfTDv3giU3dHcnk2MTZFULMkLPsJ2JEbsAP0v9bK35et0Qz9MD/WtC0Zuj7k8vrMweDLXL6FmA0g2Zq+5AxocxSKuffEpYfLiRfBh5BQiotshgqqXkuerKlkfvlTvw3qztbtG+LWHvuuLf1BZDKJLVy2fwPBCEhM/70ZC4obfRjKjUwLgBDn+ogQxSP/XKc7xHnjeYboq4dIMDiSlt47uO5BGrcCn6GUN6ZCbLS0v3B5h9U3aM4wUn9r+Y9KA3UN5r8mubv1wS0GFdQ== 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 26.04.24 03:23, John Hubbard wrote: > On 4/25/24 1:06 AM, David Hildenbrand wrote: >> On 25.04.24 07:40, John Hubbard wrote: >>> On 4/24/24 9:17 PM, Matthew Wilcox wrote: >>>> On Wed, Apr 24, 2024 at 09:00:50PM -0700, John Hubbard wrote: > ... >> We'll talk more about all that at LSF/MM in the mapcount session. A spoiler: > > Looking forward to it. And as an aside, this year it feels like the mm > code is changing relatively fast. So many large and small improvements > have happened or are in progress. Yes, it's happening on a very fast pace (and it's hard for me to get reasonable work done while still keeping reviewing that much ...). I'll note, that replacing a page-based interface by a folio-based interface should not be shocking news in 2024, and that the issues with mapcounts for large folios have been a recurring topic at LSF/MM and on the mailing list. > > >> >> page_mapcount() in the context of large folios: >> * Is a misunderstood function (e.g., page_mapcount() vs page_count() >>   checks, mapped = !page_mapcount() checks). >> * Is a misleading function (e.g., page_mapped() == folio_mapped() but >>   page_mapcount() != folio_mapcount()) >> >> We could just rename it to "folio_precise_page_mapcount()", but then, once we tackle the subpage mapcount optimizations (initially using a separate kernel config toggle), we'll have to teach each caller about an alternative that gets the job done, and it's not that easy to prevent further reuse around the kernel. >> >> If you look at linux-next, we're down to 5 page_mapcount() calls in fs/proc/, so I'll relocate it to fs/proc/internal.h to prevent any further use - once the s390x change lands in the next merge window. >> >> Regarding the subpage mapcount optimizations, I can further add: >> * (un)map performance improvements for PTE-mapped THP >> * Preparation for folio_order() > PMD_ORDER, where the current scheme >>   won't scale and needs further adjustments/complexity to even keep it >>   working >> * Preparation for hugetlb-like vmemmap optimizations until we have >>   memdescs / dynamically allocated folios >> * (Paving the way for partially mapping hugetlb folios that faced >>    similar issues? Not sure if that ever gets real, though) >> >> Is this patch ahead of its time? LSF/MM is just around the corner, and I'm planning on posting the other relevant patches in the next months. > > I think so, yes. There is a lot of context required to understand the > motivation, and more required in order to figure out if it is safe, > and if it still provides "good" behavior. I think the motivation for removing page_mapcount() should be very clear at this point: a single remaining user in mm/ should be warranted, and the faster it is gone the better. [case in point: I even have another potential user [1] in my mailbox that should be using a folio interface, well, or PG_anon_exclusive :) ] [1] https://lore.kernel.org/all/Zirw0uINbP6GxFiK@bender.morinfr.org/T/#u Regarding removing subpage mapcounts I agree: I added too many details that made it look harder to understand :P > > I still think it's mostly harmless, though, so being ahead of its time > is not necessarily an indictment. :) I didn't express my thought clearly: LSF/MM is just around the corner and the discussion we are having here is the perfect preparation for that session! :) I don't particularly care if we merge this patch now or after the next merge window along with the remaining page_mapcount() removal. Discussing the impact of this change is the important piece. :) [...] >> Thanks for having a look! >> >> I'm only a bit concerned about folio_likely_mapped_shared() "false negatives" (detecting exclusive although shared), until we have a more precise folio_likely_mapped_shared() variant to not unexpectedly waste memory. >> >> Imagine someone would be setting "khugepaged_max_ptes_shared=0", and then we have an area where (I think this is the extreme case): >> >> * We map 256 subpages of a 2M folio that are shared 256 times with a >>   child process. >> * We don't map the first subpage. >> * One PTE maps another page and is pte_write(). >> * 255 PTEs are pte_none(). >> >> folio_likely_mapped_shared() would return "false". >> >> But then my thinking is: >> * We are already wasting 256 subpages that are free in the 2M folio. >>   Sure, we might be able to relaim it when deferred splitting. >> * Why would someone set khugepaged_max_ptes_shared=0 but leave >>   khugepaged_max_ptes_none set that high that we would allow 255 >>   pte_none? >> * If the child is a short-living subprocess, we don't really care >> * Any futher writes to unbacked/R/O PTEs in that PMD area would COW and >>   consume memory. >> >> So I had to use more and more "ifs" to construct a scenario where we might end up wasting 1M of memory, at which point I decided "this is really a corner case" and likely not worth the worry. >> >> If we run into real issues, though, it will be easy to just inline page_mapcount() here to resolve it; but the less special-casing the better. >> > > OK. I'll need to think through some more of these cases. And meanwhile, I > was poking around from the other direction: just injection test it by > pasting in "true" or "false", in place of calling folio_likely_mapped_shared(). > And see what changes. Highly appreciated! > > The "true" test lets me fail several khugepaged selftests, while the "false" > test just increases the counter in /proc/vmstat. > > That's more of a black box way of poking at it, just to have another facet > of testing. Because it is good to ensure that we really do have test > coverage if we're changing the code. Anyway, just ideas. Yes, all makes sense. I'm very interested if there are valid concerns that the "false negatives" are unacceptable: it would be another case for why we really want to make folio_likely_mapped_shared() precise. For me it's clear that we want to make it precise, but so far I am not convinced that it is absolutely required in the khugepaged context. Thanks! -- Cheers, David / dhildenb