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 0B01DC47077 for ; Thu, 11 Jan 2024 20:28:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F1206B00A2; Thu, 11 Jan 2024 15:28:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 594AA6B00A4; Thu, 11 Jan 2024 15:28:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E76D6B00A7; Thu, 11 Jan 2024 15:28:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2DACF6B00A2 for ; Thu, 11 Jan 2024 15:28:30 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F262F160CCE for ; Thu, 11 Jan 2024 20:28:29 +0000 (UTC) X-FDA: 81668167938.10.F9B435A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 96E201C0004 for ; Thu, 11 Jan 2024 20:28:27 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LfuiZvjM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705004907; 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=BitH/jN1OvdxljA0/U1B9oFmIb7aqjoqDQp3VgbNKsE=; b=QMAnbM/enOcGBOmcVPLs2vaw8tI7Cj6M842jKERt2BpaTMI8C/hNAyX0AXjNj2qtHX1Oey S/1uJUXEbfyyVniFu8mYbXLgor32wuetaZbHAHVWxZaq/BV9EuzfTWhzXEfx4/eHuw26JU gvdqaNMXHxODHoaaNtrgKEGPL80adLg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LfuiZvjM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705004907; a=rsa-sha256; cv=none; b=qdZaK0KNdcEMqNXNGqLPpAeuS0w559SZ1fYELP4wltBn+wHHESW0KK6FAIBSKydVVgBzP+ 8uDZCGEWLK3d1vSDWTqu6vh+prBCvTTo7GePPwpC8X1FE9Y6wUApxn1v06uvGyUWbK+FGD T7kgySzV+rphy7cl3iYT4fwQB1/XnxY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705004906; 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=BitH/jN1OvdxljA0/U1B9oFmIb7aqjoqDQp3VgbNKsE=; b=LfuiZvjMdEALN6Fhd+kdrIC1qhzimPxH7mdD8Z9R81Oho1XOe2wY070JkVycXgB69UX7vu J3leg7LSosu74wk63IeAKJZdbmiXuVetFw2/og9LMeCfWb6MhIBkN4CI04kulLr9Y/XFFJ /96FY5z0FFzODAe+jap9U6y58K/8tJo= 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-150-cBQnY6ygMsWfL0ZwHlnxLw-1; Thu, 11 Jan 2024 15:28:24 -0500 X-MC-Unique: cBQnY6ygMsWfL0ZwHlnxLw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-33770774fe4so2342508f8f.3 for ; Thu, 11 Jan 2024 12:28:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705004903; x=1705609703; 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=BitH/jN1OvdxljA0/U1B9oFmIb7aqjoqDQp3VgbNKsE=; b=Ty0YWfLyFO/hgd4EJwg7LCSdMfmAYwGtDA+wqSc9apej1v+2aSrkxzYjLFkQoAZv4y 9HbOKtpMT3ean3eKdinHo20ForrQ0yenSVLLNydMiwExPiPQ2ydM840HSRcgHb6ht1SD 5H6w5b3LisuK48u3dMgRZGNq6Vk+2mtcmMEAqY6wtjt4leUd3VR0wcA57GtZcDGsENKu ByKZpSd78dM9QCVPi0je+EvJKjpzks7l7yHGWHxzNUwxqXfXZnKgOuO6teb0CpG4fmbz mWnsMTijvYzG9Wr2A2r4gDEwh7lMcnlmPYVDsYRGueHP16urksazmqK1NY+TGbzfJ4rO 3idQ== X-Gm-Message-State: AOJu0YyR1BWzW97GIPYtua2bMjyjLoCi4mRJ/m1PqIRvfTd399i/5l89 G2cPnMOxpo99Ers1mj97soYgIukQhpWVIh+FmZxLhmRV3xfWioGLDHXI75L99RocJpwWemm6vcl Ft7obbsUN9ibrAVp+9mc= X-Received: by 2002:a5d:4c88:0:b0:337:420e:b2c9 with SMTP id z8-20020a5d4c88000000b00337420eb2c9mr174039wrs.138.1705004903294; Thu, 11 Jan 2024 12:28:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoyPzfwg2NlhdyriGEV63GYcPYPr+dMFFNLI/laWxLsza5zHmaUqegl/pt7cxc7+cplG8yNQ== X-Received: by 2002:a5d:4c88:0:b0:337:420e:b2c9 with SMTP id z8-20020a5d4c88000000b00337420eb2c9mr174026wrs.138.1705004902779; Thu, 11 Jan 2024 12:28:22 -0800 (PST) Received: from ?IPV6:2003:cb:c747:f900:6099:1901:b863:450f? (p200300cbc747f90060991901b863450f.dip0.t-ipconnect.de. [2003:cb:c747:f900:6099:1901:b863:450f]) by smtp.gmail.com with ESMTPSA id l8-20020adfe588000000b0033662c2820bsm1989889wrm.117.2024.01.11.12.28.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jan 2024 12:28:22 -0800 (PST) Message-ID: <915d1397-2ac4-497d-9f94-c4b405f99f9a@redhat.com> Date: Thu, 11 Jan 2024 21:28:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1] tools/mm: Add thpmaps script to dump THP usage info To: Barry Song <21cnbao@gmail.com> Cc: Ryan Roberts , John Hubbard , Andrew Morton , Zenghui Yu , Matthew Wilcox , Kefeng Wang , Zi Yan , Alistair Popple , linux-mm@kvack.org References: <20240102153828.1002295-1-ryan.roberts@arm.com> <3bd5e4a3-9f67-4483-9a0e-9abb5eb783cd@arm.com> <94ebe62b-5f55-4be9-b464-4105b4692496@arm.com> <68d5ce7e-6587-47c6-bd0f-988adf5d92a4@arm.com> <974a2670-7fa9-425e-921e-8d54a596e6cf@arm.com> <6c77f143-9c2c-4d17-9a2a-d69d9adf2eea@arm.com> <40945967-3f16-4574-8f5d-80e0fcb0bcb4@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lh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/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: 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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 96E201C0004 X-Stat-Signature: g7mwrsfseajc41ssa4amj75hsto8nsms X-HE-Tag: 1705004907-127870 X-HE-Meta: U2FsdGVkX18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fiuifB6HlUzmabnw99dQ2LKp4EJfaGbccbufvd22HMiebzcJDLAcAw8XoVAYNJJ/W6gweeIz/amooh9Q/fAFa9ld/ahy1iNF32JKe5zt4WfGHBxcZswuoPiTFrKSTcGnUzcGcIOmwXKK7tJaPEu5eUWHt+8b6xyJbwyPTczkxkiW6t7Diu/YiG9Cgi2qwXX+FfJcyLkEZiMWNfR6ZBzTA9oz6x8427iMn8aqimOml/pyKF5X+0J412+G1o2w+xptZYU/LLcPZbMDp0mPLvYwS2HFKkjJhmP7qSQhQguHLC7aJmHZ6/UIHu2ijuWB9fQEnq51nw== 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 11.01.24 21:21, Barry Song wrote: > On Fri, Jan 12, 2024 at 2:18 AM David Hildenbrand wrote: >> >> On 11.01.24 13:25, Ryan Roberts wrote: >>> On 10/01/2024 22:14, Barry Song wrote: >>>> On Wed, Jan 10, 2024 at 7:59 PM Ryan Roberts wrote: >>>>> >>>>> On 10/01/2024 11:38, Barry Song wrote: >>>>>> On Wed, Jan 10, 2024 at 7:21 PM Ryan Roberts wrote: >>>>>>> >>>>>>> On 10/01/2024 11:00, David Hildenbrand wrote: >>>>>>>> On 10.01.24 11:55, Ryan Roberts wrote: >>>>>>>>> On 10/01/2024 10:42, David Hildenbrand wrote: >>>>>>>>>> On 10.01.24 11:38, Ryan Roberts wrote: >>>>>>>>>>> On 10/01/2024 10:30, Barry Song wrote: >>>>>>>>>>>> On Wed, Jan 10, 2024 at 6:23 PM Ryan Roberts wrote: >>>>>>>>>>>>> >>>>>>>>>>>>> On 10/01/2024 09:09, Barry Song wrote: >>>>>>>>>>>>>> On Wed, Jan 10, 2024 at 4:58 PM Ryan Roberts wrote: >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> On 10/01/2024 08:02, Barry Song wrote: >>>>>>>>>>>>>>>> On Wed, Jan 10, 2024 at 12:16 PM John Hubbard wrote: >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> On 1/9/24 19:51, Barry Song wrote: >>>>>>>>>>>>>>>>>> On Wed, Jan 10, 2024 at 11:35 AM John Hubbard >>>>>>>>>>>>>>>>>> wrote: >>>>>>>>>>>>>>>>> ... >>>>>>>>>>>>>>>>>>> Hi Ryan, >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> One thing that immediately came up during some recent testing of mTHP >>>>>>>>>>>>>>>>>>> on arm64: the pid requirement is sometimes a little awkward. I'm >>>>>>>>>>>>>>>>>>> running >>>>>>>>>>>>>>>>>>> tests on a machine at a time for now, inside various containers and >>>>>>>>>>>>>>>>>>> such, and it would be nice if there were an easy way to get some >>>>>>>>>>>>>>>>>>> numbers >>>>>>>>>>>>>>>>>>> for the mTHPs across the whole machine. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Just to confirm, you're expecting these "global" stats be truely global >>>>>>>>>>>>>>> and not >>>>>>>>>>>>>>> per-container? (asking because you exploicitly mentioned being in a >>>>>>>>>>>>>>> container). >>>>>>>>>>>>>>> If you want per-container, then you can probably just create the container >>>>>>>>>>>>>>> in a >>>>>>>>>>>>>>> cgroup? >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> I'm not sure if that changes anything about thpmaps here. Probably >>>>>>>>>>>>>>>>>>> this is fine as-is. But I wanted to give some initial reactions from >>>>>>>>>>>>>>>>>>> just some quick runs: the global state would be convenient. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Thanks for taking this for a spin! Appreciate the feedback. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> +1. but this seems to be impossible by scanning pagemap? >>>>>>>>>>>>>>>>>> so may we add this statistics information in kernel just like >>>>>>>>>>>>>>>>>> /proc/meminfo or a separate /proc/mthp_info? >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> Yes. From my perspective, it looks like the global stats are more useful >>>>>>>>>>>>>>>>> initially, and the more detailed per-pid or per-cgroup stats are the >>>>>>>>>>>>>>>>> next level of investigation. So feels odd to start with the more >>>>>>>>>>>>>>>>> detailed stats. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> probably because this can be done without the modification of the kernel. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Yes indeed, as John said in an earlier thread, my previous attempts to add >>>>>>>>>>>>>>> stats >>>>>>>>>>>>>>> directly in the kernel got pushback; DavidH was concerned that we don't >>>>>>>>>>>>>>> really >>>>>>>>>>>>>>> know exectly how to account mTHPs yet >>>>>>>>>>>>>>> (whole/partial/aligned/unaligned/per-size/etc) so didn't want to end up >>>>>>>>>>>>>>> adding >>>>>>>>>>>>>>> the wrong ABI and having to maintain it forever. There has also been some >>>>>>>>>>>>>>> pushback regarding adding more values to multi-value files in sysfs, so >>>>>>>>>>>>>>> David >>>>>>>>>>>>>>> was suggesting coming up with a whole new scheme at some point (I know >>>>>>>>>>>>>>> /proc/meminfo isn't sysfs, but the equivalent files for NUMA nodes and >>>>>>>>>>>>>>> cgroups >>>>>>>>>>>>>>> do live in sysfs). >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Anyway, this script was my attempt to 1) provide a short term solution >>>>>>>>>>>>>>> to the >>>>>>>>>>>>>>> "we need some stats" request and 2) provide a context in which to explore >>>>>>>>>>>>>>> what >>>>>>>>>>>>>>> the right stats are - this script can evolve without the ABI problem. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> The detailed per-pid or per-cgroup is still quite useful to my case in >>>>>>>>>>>>>>>> which >>>>>>>>>>>>>>>> we set mTHP enabled/disabled and allowed sizes according to vma types, >>>>>>>>>>>>>>>> eg. libc_malloc, java heaps etc. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> Different vma types can have different anon_name. So I can use the >>>>>>>>>>>>>>>> detailed >>>>>>>>>>>>>>>> info to find out if specific VMAs have gotten mTHP properly and how many >>>>>>>>>>>>>>>> they have gotten. >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> However, Ryan did clearly say, above, "In future we may wish to >>>>>>>>>>>>>>>>> introduce stats directly into the kernel (e.g. smaps or similar)". And >>>>>>>>>>>>>>>>> earlier he ran into some pushback on trying to set up /proc or /sys >>>>>>>>>>>>>>>>> values because this is still such an early feature. >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> I wonder if we could put the global stats in debugfs for now? That's >>>>>>>>>>>>>>>>> specifically supposed to be a "we promise *not* to keep this ABI stable" >>>>>>>>>>>>>>>>> location. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Now that I think about it, I wonder if we can add a --global mode to the >>>>>>>>>>>>>>> script >>>>>>>>>>>>>>> (or just infer global when neither --pid nor --cgroup are provided). I >>>>>>>>>>>>>>> think I >>>>>>>>>>>>>>> should be able to determine all the physical memory ranges from >>>>>>>>>>>>>>> /proc/iomem, >>>>>>>>>>>>>>> then grab all the info we need from /proc/kpageflags. We should then be >>>>>>>>>>>>>>> able to >>>>>>>>>>>>>>> process it all in much the same way as for --pid/--cgroup and provide the >>>>>>>>>>>>>>> same >>>>>>>>>>>>>>> stats, but it will apply globally. What do you think? >>>>>>>>>>>>> >>>>>>>>>>>>> Having now thought about this for a few mins (in the shower, if anyone wants >>>>>>>>>>>>> the >>>>>>>>>>>>> complete picture :) ), this won't quite work. This approach doesn't have the >>>>>>>>>>>>> virtual mapping information so the best it can do is tell us "how many of >>>>>>>>>>>>> each >>>>>>>>>>>>> size of THP are allocated?" - it doesn't tell us anything about whether they >>>>>>>>>>>>> are >>>>>>>>>>>>> fully or partially mapped or what their alignment is (all necessary if we >>>>>>>>>>>>> want >>>>>>>>>>>>> to know if they are contpte-mapped). So I don't think this approach is >>>>>>>>>>>>> going to >>>>>>>>>>>>> be particularly useful. >>>>>>>>>>>>> >>>>>>>>>>>>> And this is also the big problem if we want to gather stats inside the >>>>>>>>>>>>> kernel; >>>>>>>>>>>>> if we want something equivalant to /proc/meminfo's >>>>>>>>>>>>> AnonHugePages/ShmemPmdMapped/FilePmdMapped, we need to consider not just the >>>>>>>>>>>>> allocation of the THP but also whether it is mapped. That's easy for >>>>>>>>>>>>> PMD-mappings, because there is only one entry to consider - when you set it, >>>>>>>>>>>>> you >>>>>>>>>>>>> increment the number of PMD-mapped THPs, when you clear it, you decrement. >>>>>>>>>>>>> But >>>>>>>>>>>>> for PTE-mappings it's harder; you know the size when you are mapping so its >>>>>>>>>>>>> easy >>>>>>>>>>>>> to increment, but you can do a partial unmap, so you would need to scan the >>>>>>>>>>>>> PTEs >>>>>>>>>>>>> to figure out if we are unmapping the first page of a previously >>>>>>>>>>>>> fully-PTE-mapped THP, which is expensive. We would need a cheap mechanism to >>>>>>>>>>>>> determine "is this folio fully and contiguously mapped in at least one >>>>>>>>>>>>> process?". >>>>>>>>>>>> >>>>>>>>>>>> as OPPO's approach I shared to you before is maintaining two mapcount >>>>>>>>>>>> 1. entire map >>>>>>>>>>>> 2. subpage's map >>>>>>>>>>>> 3. if 1 and 2 both exist, it is DoubleMapped. >>>>>>>>>>>> >>>>>>>>>>>> This isn't a problem for us. and everytime if we do a partial unmap, >>>>>>>>>>>> we have an explicit >>>>>>>>>>>> cont_pte split which will decrease the entire map and increase the >>>>>>>>>>>> subpage's mapcount. >>>>>>>>>>>> >>>>>>>>>>>> but its downside is that we expose this info to mm-core. >>>>>>>>>>> >>>>>>>>>>> OK, but I think we have a slightly more generic situation going on with the >>>>>>>>>>> upstream; If I've understood correctly, you are using the PTE_CONT bit in the >>>>>>>>>>> PTE to determne if its fully mapped? That works for your case where you only >>>>>>>>>>> have 1 size of THP that you care about (contpte-size). But for the upstream, we >>>>>>>>>>> have multi-size THP so we can't use the PTE_CONT bit to determine if its fully >>>>>>>>>>> mapped because we can only use that bit if the THP is at least 64K and aligned, >>>>>>>>>>> and only on arm64. We would need a SW bit for this purpose, and the mm would >>>>>>>>>>> need to update that SW bit for every PTE one the full -> partial map >>>>>>>>>>> transition. >>>>>>>>>> >>>>>>>>>> Oh no. Let's not make everything more complicated for the purpose of some stats. >>>>>>>>>> >>>>>>>>> >>>>>>>>> Indeed, I was intending to argue *against* doing it this way. Fundamentally, if >>>>>>>>> we want to know what's fully mapped and what's not, then I don't see any way >>>>>>>>> other than by scanning the page tables and we might as well do that in user >>>>>>>>> space with this script. >>>>>>>>> >>>>>>>>> Although, I expect you will shortly make a proposal that is simple to implement >>>>>>>>> and prove me wrong ;-) >>>>>>>> >>>>>>>> Unlikely :) As you said, once you have multiple folio sizes, it stops really >>>>>>>> making sense. >>>>>>>> >>>>>>>> Assume you have a 128 kiB pageache folio, and half of that is mapped. You can >>>>>>>> set cont-pte bits on that half and all is fine. Or AMD can benefit from it's >>>>>>>> optimizations without the cont-pte bit and everything is fine. >>>>>>> >>>>>>> Yes, but for debug and optimization, its useful to know when THPs are >>>>>>> fully/partially mapped, when they are unaligned etc. Anyway, the script does >>>>>>> that for us, and I think we are tending towards agreement that there are >>>>>>> unlikely to be any cost benefits by moving it into the kernel. >>>>>> >>>>>> frequent partial unmap can defeat all purpose for us to use large folios. >>>>>> just imagine a large folio can soon be splitted after it is formed. we lose >>>>>> the performance gain and might get regression instead. >>>>> >>>>> nit: just because a THP gets partially unmapped in a process doesn't mean it >>>>> gets split into order-0 pages. If the folio still has all its pages mapped at >>>>> least once then no further action is taken. If the page being unmapped was the >>>>> last mapping of that page, then the THP is put on the deferred split queue, so >>>>> that it can be split in future if needed. >>>>>> >>>>>> and this can be very frequent, for example, one userspace heap management >>>>>> is releasing memory page by page. >>>>>> >>>>>> In our real product deployment, we might not care about the second partial >>>>>> unmapped, we do care about the first partial unmapped as we can use this >>>>>> to know if split has ever happened on this large folios. an partial unmapped >>>>>> subpage can be unlikely re-mapped back. >>>>>> >>>>>> so i guess 1st unmap is probably enough, at least for my product. I mean we >>>>>> care about if partial unmap has ever happened on a large folio more than how >>>>>> they are exactly partially unmapped :-) >>>>> >>>>> I'm not sure what you are suggesting here? A global boolean that tells you if >>>>> any folio in the system has ever been partially unmapped? That will almost >>>>> certainly always be true, even for a very well tuned system. >>>> >>>> not a global boolean but a per-folio boolean. in case userspace maps a region >>>> and has no userspace management, then we are fine as it is unlikely to have >>>> partial unmap/map things; in case userspace maps a region, but manages it >>>> by itself, such as heap things, we might result in lots of partial map/unmap, >>>> which can lead to 3 problems: >>>> 1. potential memory footprint increase, for example, while userspace releases >>>> some pages in a folio, we might still keep it as frequent splitting folio into >>>> basepages and releasing the unmapped subpage might be too expensive. >>>> 2. if cont-pte is involved, frequent dropping cont-pte/tlb shootdown >>>> might happen. >>>> 3. other maintenance overhead such as splitting large folios etc. >>>> >>>> We'd like to know how serious partial map things are happening. so either >>>> we will disable mTHP in this kind of VMAs, or optimize userspace to do >>>> some alignment according to the size of large folios. >>>> >>>> in android phones, we detect lots of apps, and also found some apps might >>>> do things like >>>> 1. mprotect on some pages within a large folio >>>> 2. mlock on some pages within a large folio >>>> 3. madv_free on some pages within a large folio >>>> 4. madv_pageout on some pages within a large folio. >>>> >>>> it would be good if we have a per-folio boolean to know how serious userspace >>>> is breaking the large folios. for example, if more than 50% folios in a vma has >>>> this problem, we can find it out and take some action. >>> >>> The high level value of these stats seems clear - I agree we need to be able to >>> get these insights. I think the issues are more around the implementation >>> though. I'm struggling to understand exactly how we could implement a lot of >>> these things cheaply (either in the kernel or in user space). >>> >>> Let me try to work though what I think you are suggesting: >>> >>> - every THP is initially fully mapped >> >> Not for pagecache folios. >> >>> - when an operation causes a partial unmap, mark the folio as having at least >>> one partial mapping >>> - on transition from "no partial mappings" to "at least one partial mapping" >>> increment a "anon-partial-kB" (one for each supported folio size) >>> counter by the folio size >>> - on transition from "at least one partial mapping" to "fully unampped >>> everywhere" decrement the counter by the folio size >>> >>> I think the issue with this is that a folio that is fully mapped in a process >>> that gets forked, then is partially unmapped in 1 process, will be accounted as >>> partially mapped even after the process that partially unmapped it exits, even >>> though that folio is now fully mapped in all processes that map it. Is that a >>> problem, perhaps not? I'm not sure. >> >> What I can offer with my total mapcount I am working on (+ entire/pmd >> mapcount, but let's put that aside): >> >> 1) total_mapcount not multiples of folio_nr_page -> at least one process >> currently maps the folio partially >> >> 2) total_mapcount is less than folio_nr_page -> surely partially mapped >> >> I think for most of anon memory (note that most folios are always >> exclusive in our system, not cow-shared) 2) would already be sufficient. > > if we can improve Ryan's "mm: Batch-copy PTE ranges during fork()" to > add nr_pages in copy_pte_range for rmap. > copy_pte_range() > { > folio_try_dup_anon_rmap_ptes(...nr_pages....) > } > and at the same time, in zap_pte_range(), we remove the whole anon_rmap > if the zapped-range covers the whole folio. > > Replace the for-loop > for (i = 0; i < nr; i++, page++) { > add_rmap(1); > } > for (i = 0; i < nr; i++, page++) { > remove_rmap(1); > } > by always using add_rmap(nr_pages) and remove_rmap(nr_pages) if we > are doing the entire mapping/unmapping That's precisely what I have already running as protoypes :) And I promised Ryan to get to this soon, clean it up and sent it out. . > > then we might be able to TestAndSetPartialMapped flag for this folio anywhile > 1. someone is adding rmap with a number not equal nr_pages > 2. someone is removing rmap with a number not equal nr_pages > That means we are doing partial mapping or unmapping. > and we increment partialmap_count by 1, let debugfs or somewhere present > this count. Yes. The only "ugly" corner case if you have a split VMA. We're not batching rmap exceeding that. -- Cheers, David / dhildenb