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 5334AC47DB3 for ; Mon, 29 Jan 2024 14:09:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7ADF6B0080; Mon, 29 Jan 2024 09:09:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B04426B0081; Mon, 29 Jan 2024 09:09:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 930A66B0082; Mon, 29 Jan 2024 09:09:39 -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 7C3096B0080 for ; Mon, 29 Jan 2024 09:09:39 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4ABC5C0A26 for ; Mon, 29 Jan 2024 14:09:39 +0000 (UTC) X-FDA: 81732531678.03.79092ED Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 1BA9B4000B for ; Mon, 29 Jan 2024 14:09:36 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yq01G4bL; spf=pass (imf12.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=1706537377; 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=gA9ehhRIWZoBAk2p2PsxETZzZSN7H2+EH7tg5JjIouo=; b=jFL6And797MJEwq5Mm0LMA3WIm3MYDLtQc4HNhpob74/NfwSvs0ztAeXcBTSddngPnSkHd DQPA8kI1Cckr1IEgtk8lX89nK5w7prX2AfoVW/2cFdMJDU+zTzAtB6RZuiY2DExXXVWdB6 KU0mw3s8KeN5SocJ6t0FaoD3ABI6fGY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yq01G4bL; spf=pass (imf12.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=1706537377; a=rsa-sha256; cv=none; b=orAPKcz0FpJxb244Cy8iY7+ZNvv7LwWqtlm95d0wg4Isa08DOxIP3zwCxV/F9E257yEcHv CV+8gjBWAO99lK4olD/uCq9kFOZeWvfmN82XcEumVoPfb1GrkvZf0FvrT+fENZtyvOHBYh CSH3IqYNROftrLLtdjkUVsKKzwn3djY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706537376; 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=gA9ehhRIWZoBAk2p2PsxETZzZSN7H2+EH7tg5JjIouo=; b=Yq01G4bL1eXxAkD2SNW+MX2RlVKcAHTOAUZosbZyxPkAiyLccjmKqYjMq0uu+0VcYOcbJk I8RzZoLsVgxu5AMcL58N29MehQlvXSOCuDbYgbCVfqIvxMcrb/lJA4fZDu94nWbTllcQGI qurASypvzM3Y81hlEciCLNlL4Hutol4= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-W7nC_5V6MUGLbVF3l5lwvg-1; Mon, 29 Jan 2024 09:09:35 -0500 X-MC-Unique: W7nC_5V6MUGLbVF3l5lwvg-1 Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-7bfeea77d25so39948439f.1 for ; Mon, 29 Jan 2024 06:09:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706537374; x=1707142174; 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=gA9ehhRIWZoBAk2p2PsxETZzZSN7H2+EH7tg5JjIouo=; b=QeRns6OrAqHx0KP0BQlNv1TKs97ZSJysZjYk/dViEgj5dhfgGaPNfxwJqY3mcb5L1F NObNh7J9n5qNG18PejbIWrFQoghwm2fNOXrGWQpZXQVZ6+1YgT4+pxoyOpxoXtWhBsKG 3I+cZbUQxaqoWs+wxdQwTuVZeZGbLcbLBtj+KXw3yA63FipLM3SB1C+aGdsgqSWY/W+c Gvjt4ybEC99QPGpsCe5Svf6tAlaHs8z/tVjKYcgoRMnXaG8LRK79nv/j66ZPQTH8ZFdy euQwDN/VSpFGw4kDpIYELP7HgDqtMsSO5R5NEZIERSsLDDxcB/ewnZUbQnykto6tR8wJ +hIw== X-Gm-Message-State: AOJu0Yy5d7KjHR/3xJiJDgbzfzeou9kHKiOYuttXGkM21ZEY0bhg9K3J mRWmmCQ+RHwtQRX9Q0/t22HpXfkTwU3qB0Z4D3emN7KgjPcyh3T0ZgETm+DftmByQc/63Od2L40 32n9huVZB5mo0tdr8EsEqffzWoeUaKJuGYoKHQsKaAVKEyRm7 X-Received: by 2002:a5d:93c1:0:b0:7bf:3532:96bc with SMTP id j1-20020a5d93c1000000b007bf353296bcmr4957822ioo.8.1706537374472; Mon, 29 Jan 2024 06:09:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjKsZrHlOiofPIh/SN9FsEXj3iVVLM1eZHRrW2ZE9CqRUOjIn5N9z2PhFrCHd3d31gNxV65g== X-Received: by 2002:a5d:93c1:0:b0:7bf:3532:96bc with SMTP id j1-20020a5d93c1000000b007bf353296bcmr4957809ioo.8.1706537374005; Mon, 29 Jan 2024 06:09:34 -0800 (PST) Received: from ?IPV6:2003:cb:c721:aa00:3221:f685:1200:6d03? (p200300cbc721aa003221f68512006d03.dip0.t-ipconnect.de. [2003:cb:c721:aa00:3221:f685:1200:6d03]) by smtp.gmail.com with ESMTPSA id gw21-20020a0566381ef500b0046f3b865e63sm1730131jab.178.2024.01.29.06.09.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Jan 2024 06:09:33 -0800 (PST) Message-ID: <2718876b-77df-4d78-a5de-f5d59ad414f4@redhat.com> Date: Mon, 29 Jan 2024 15:09:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [LSF/MM/BPF TOPIC] MM: Mapcount Madness To: Matthew Wilcox Cc: lsf-pc@lists.linux-foundation.org, "linux-mm@kvack.org" , Michal Hocko , Dan Williams References: <049e4674-44b6-4675-b53b-62e11481a7ce@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/Y91XuS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P5+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: 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: 7bit X-Rspamd-Queue-Id: 1BA9B4000B X-Rspam-User: X-Stat-Signature: mcpwz5hw1qok48ur6y5nrrqyko9nqer9 X-Rspamd-Server: rspam01 X-HE-Tag: 1706537376-49460 X-HE-Meta: U2FsdGVkX19Hou79Cx6CCrWPKANMOxaX0ON5rFFzcU9QN4SQ7dMRko3IjRnp0HdSPvf5b2DiKBLJMcd6HJ9RwRwdMfqN9ejUxCZ0kmqAbJmhoVW3sHvz/TrawpemTpXuURr/U+m3sQ7rcOhy5OmAWpznEdgvCre+gu5ooa7Xe2SJE9vTkvDgrmZDN/gi2+N5MS4vtWlgmxharQohU5a6MQ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/kgPXJUlN5i0zdSuw7HUL2H1/sfReM1r+UMyx+Fepfee9TFXJ7ChoLXSDAF3cWT8cS7NBiEyfoQg9Y5TE+A/OKCp9Ijam/P10kgrDGqxvdBwocxN7U3AhdOWgse2VUdUxbOjGdSDYmhKKqE6fOTy1SybjKVCLzFmCD/bEjuW0xX0s8XMI= 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 29.01.24 14:49, Matthew Wilcox wrote: > On Mon, Jan 29, 2024 at 01:05:04PM +0100, David Hildenbrand wrote: >> As PTE-mapped large folios become more relevant (mTHP [1]) and there is the >> desire to shrink the metadata allocated for such large folios as well >> (memdesc [2]), how we track folio mappings gets more relevant. Over the >> years, we used folio mapping information to answer various questions: is >> this folio mapped by somebody else? do we have to COW on write fault? how do >> we adjust memory statistics? ... >> >> Let's talk about ongoing work in the mapcount area, get a common >> understanding of what the users of the different mapcounts are and what the >> implications of removing some would be: which questions could we answer >> differently, which questions would we not be able to answer precisely >> anymore, and what would be the implications of such changes? >> >> For example, can we tolerate some imprecise memory statistics? How >> expressive is the PSS when large folios are only partially mapped? Would we >> need a transition period and glue changes to a new CONFIG_ option? Do we >> really have to support THP and friends on 32bit? > > Excellent topics to cover. I have some of my own questions ... > > Are we in danger of overflowing page refcount too easily? Pincount > isn't an issue here; we're talking about large folios, so pincount gets > its own field. But with tracking one mapcount per PTE mapping of a > folio, we can easily increment a PMD-sized folio's refcount by 512 > per VMA. Now we only need 2^22 VMAs to hit the 2^31 limit before the > page->refcount protections go into effect and operations start failing. I think we'll definitely either want to detect such overflows early and fail fork/pagefaults/ etc, or if there are sane use cases (2^22 sounds excessive, but we might be getting larger folios ...), much rather have a 64bit refcount for large folios (or any folios for simplicity? TBD) in the future. And I think, then, once again the question will be: how much time are we willing to invest to support THP and friends on 32bit, and is it really worth it. > > How / do we need to track mapcount for pages mapped to userspace which > are neither file-backed, nor anonymous mappings? eg drivers pass > vmalloc memory to vmf_insert_page() in their ->mmap handler. As of today, vm_insert_page() and friends end up calling insert_page_into_pte_locked(), which does a folio_get(folio); inc_mm_counter(vma->vm_mm, mm_counter_file(folio)); folio_add_file_rmap_pte(folio, page, vma); That is, we get non-rmappable folios (no pagecache/shmem/anon) in rmap code. It's nonsensical, because the rmap does not apply to such pages (rmap walks won't work, there is no rmap). When I stumbled over that recently, I was guessing that the current handling only exists for simplicity on the munmap/zap path. IMHO, we shouldn't call rmap code on that path (and similarly, when unmapping). If we want to adjust some mapcounts for some reason, we better do that explicitly. And that is an excellent topic to discuss. > > What do VM_PFNMAP and VM_MIXEDMAP really imply? The documentation here > is a little sparse. And that's sad, because I think we expect device > driver writers to use them, and without clear documentation of what > they actually do, they're going to be misused. Agreed, it's under-documented. In general VM_PFNMAP means "map whatever you want, as long as you make sure it cannot get freed+reused as long as it is still mapped". That is, if the memory was allocated, the driver has to hold a reference, but the core won't be messing with any refcount/mapcount/rmap/stats/ ... treating it like "struct page" wouldn't exist. VM_MIXEDMAP is the complicated brother that uses "struct page" if it exists. Another good topic, agreed. -- Cheers, David / dhildenb