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 5159AC5320E for ; Thu, 22 Aug 2024 08:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC34480017; Thu, 22 Aug 2024 04:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4A7D6B00FB; Thu, 22 Aug 2024 04:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4FC380017; Thu, 22 Aug 2024 04:59:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7D9776B00B7 for ; Thu, 22 Aug 2024 04:59:33 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BB611A6DDB for ; Thu, 22 Aug 2024 08:59:32 +0000 (UTC) X-FDA: 82479282984.06.7B25A1E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 581E4140008 for ; Thu, 22 Aug 2024 08:59:30 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V3saogKM; spf=pass (imf23.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=1724317129; a=rsa-sha256; cv=none; b=MNochTYOE+wx1goAPah0TDrPEfydnxdolh6kTXpjWrLuqESY0BS8WPjIEY5i+fpv/hPohP K9gmM7SqwpQiIhYCVUz8zIN40A5CEbKi7iXKjI8JkUmnviSqjK8vnP0YbSeU/csbEWFUuL 3/H8mpp3jIokzhCdLccXQOvO63siAT0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V3saogKM; spf=pass (imf23.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=1724317129; 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=Pp23Pdf8+lQt6tURJ+naS20fU0X5TR5LuakppsMwxyA=; b=zdpGyReyCeLC5h+RI3sX5mKXhWt88v6xXFaV2OjGc/VBa2b+eD1SFCbQv/IRfNP5HN+/rF V/pj2BmsM0jS6VHA9CD2KLsa2NEOeAG5FqNKiJ7KQbI9nVP8W0yGr5cHAe8YMyCX6Slfc1 NIkDrpVTCcgAlCnDS0h/vt00QeMM9MY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724317169; 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=Pp23Pdf8+lQt6tURJ+naS20fU0X5TR5LuakppsMwxyA=; b=V3saogKMZU8T88bSQF/s8+OTMWcOnbsiCrSk0qTj7kbecjziGMG0CHPsI/FjpwARa+MJNZ NRlF7fl3hI9D6wsY60yBbOzaokXNWmHZOkAqgqRnLboFZAi+fzOYRLi8A5zq4cpvgOYwvA GxkSHERuV6sGjfq1aXknoruXVpXr+ZM= 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-544-JjGB8WlbM5yfTsGCYbNPqQ-1; Thu, 22 Aug 2024 04:59:28 -0400 X-MC-Unique: JjGB8WlbM5yfTsGCYbNPqQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37189fc2977so248579f8f.0 for ; Thu, 22 Aug 2024 01:59:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724317167; x=1724921967; 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=Pp23Pdf8+lQt6tURJ+naS20fU0X5TR5LuakppsMwxyA=; b=k4UZkU+UWow6HJQhHZgkR0wOBgMjYuc1XGxz8es3z+GiWFzxlRg32B9PaN4uXrNd1Z Bjv6RiuQ/EaaWRtqlDR19lkJw9PcH3TFL0oZgt3UdGRfTVsMyLhD6yaIE63J5Q63O+04 9L7TJX3oKzVbPIEvCCssBTxh/GMW4DStt00MNLZpgu+tVVQUMTGXLry++dcTBstVhFqP bQvEjegPcMOCAK0DmAYy7OJ6K7kbteI2UMmWEOZ25BGHtGpfddmBSJqDAscS9QGiZVkJ OvEINXmc4fEryS869NmkDND6s5uzJdMdd5fNJq2aiCm9DMwrruGyXP6DWmnI0N+/y0WE jvhQ== X-Forwarded-Encrypted: i=1; AJvYcCWnk35j54Z9XCX2VLWxD0gdGxgqG8uiawdQSgB6GhVTvCCPuO9khajpSoBqfq3a8kRl5CAH1Am/fg==@kvack.org X-Gm-Message-State: AOJu0YzmIKq8nQFDDmYTareLI9xwloAqcRkT+cKWdWzwE/DQM/zi6Q9j oSnU0OYS+hF2CkMQVGVp/+aHwgy3zravu6Suvi/sAa+xF7jWZmGwBDPM7CIQKJdmFzCMWdCnGrj uAnsefLlP3bFJ4gfBknlJ3ThmR2V2BHsqabV4ZxaUJv1zVXBD X-Received: by 2002:a05:6000:dc7:b0:36c:ff0c:36d7 with SMTP id ffacd0b85a97d-37308bffd08mr779061f8f.2.1724317166847; Thu, 22 Aug 2024 01:59:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEKG7uJjY0VBowvcTBEr+v2wBoRiQJ+9zTmefhgrwcvPNkHEFvzUkCS2jr4O/7Fj5Lu+yj9Q== X-Received: by 2002:a05:6000:dc7:b0:36c:ff0c:36d7 with SMTP id ffacd0b85a97d-37308bffd08mr779033f8f.2.1724317165862; Thu, 22 Aug 2024 01:59:25 -0700 (PDT) Received: from ?IPV6:2003:cb:c70f:2b00:f928:47d8:c9be:9d87? (p200300cbc70f2b00f92847d8c9be9d87.dip0.t-ipconnect.de. [2003:cb:c70f:2b00:f928:47d8:c9be:9d87]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac514e088sm17467545e9.8.2024.08.22.01.59.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Aug 2024 01:59:25 -0700 (PDT) Message-ID: <954f80c8-5bc3-44f5-a361-32073cbbd764@redhat.com> Date: Thu, 22 Aug 2024 10:59:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] mm: collect the number of anon large folios To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, chrisl@kernel.org, hanchuanhua@oppo.com, ioworker0@gmail.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, v-songbaohua@oppo.com, ziy@nvidia.com, yuanshuai@oppo.com References: <20240811224940.39876-1-21cnbao@gmail.com> <20240811224940.39876-2-21cnbao@gmail.com> <3572ae2e-2141-4a70-99da-850b2e7ade41@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com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KANLnRAb0NH/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: 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-Stat-Signature: hcws5z8hndazfturanfrn4jeionarh8g X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KVzQ3dobHH8viyEUf3SW1/fPRhHPpQt+K/cxKqCS8ytBF6+57ACziX92q4XP+XheuA7E/Dp+MHFPosboH5kIm6MC9+XrDpy7NY2P5DtI3Q/yd1+0/MGbz8PMNO8gm63dIKLQ6QdTg2kyVzxiGCV7re6elXFVei+fHwFIZAgCoyrrvDsurbJa+Xe2xJYt2vYDcQxtTmmo0ONTdSe4enEQ6uZeC9TlHNtY6JZDPd2r7bXoD9+JYLHy0zOCW16837UoH47FjbG8WeyVmf0HLsUIU7uSZWhOkJ1HdyMiOhwLyQAuy4QogJnsZ4YgOPG8mF7X3whKiiTQLIRGaj3zmCNwjbSpqeAdBPLfKwJD5UrzBW5thHygsujpPp0nKY2S9jm+skPruldHYTZLJsUdWumVhkMwdNOoS+kLKk5oQpuyUBe62BhHf0xZHyBip8I= 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 22.08.24 10:44, Barry Song wrote: > On Thu, Aug 22, 2024 at 12:52 PM Barry Song <21cnbao@gmail.com> wrote: >> >> On Thu, Aug 22, 2024 at 5:34 AM David Hildenbrand wrote: >>> >>> On 12.08.24 00:49, Barry Song wrote: >>>> From: Barry Song >>>> >>>> Anon large folios come from three places: >>>> 1. new allocated large folios in PF, they will call folio_add_new_anon_rmap() >>>> for rmap; >>>> 2. a large folio is split into multiple lower-order large folios; >>>> 3. a large folio is migrated to a new large folio. >>>> >>>> In all above three counts, we increase nr_anon by 1; >>>> >>>> Anon large folios might go either because of be split or be put >>>> to free, in these cases, we reduce the count by 1. >>>> >>>> Folios that have been added to the swap cache but have not yet received >>>> an anon mapping won't be counted. This is consistent with the AnonPages >>>> statistics in /proc/meminfo. >>> >>> Thinking out loud, I wonder if we want to have something like that for >>> any anon folios (including small ones). >>> >>> Assume we longterm-pinned an anon folio and unmapped/zapped it. It would >>> be quite interesting to see that these are actually anon pages still >>> consuming memory. Same with memory leaks, when an anon folio doesn't get >>> freed for some reason. >>> >>> The whole "AnonPages" counter thingy is just confusing, it only counts >>> what's currently mapped ... so we'd want something different. >>> >>> But it's okay to start with large folios only, there we have a new >>> interface without that legacy stuff :) >> >> We have two options to do this: >> 1. add a new separate nr_anon_unmapped interface which >> counts unmapped anon memory only >> 2. let the nr_anon count both mapped and unmapped anon >> folios. >> >> I would assume 1 is clearer as right now AnonPages have been >> there for years. and counting all mapped and unmapped together, >> we are still lacking an approach to find out anon memory leak >> problem you mentioned. >> >> We are right now comparing nr_anon(including mapped folios only) >> with AnonPages to get the distribution of different folio sizes in >> performance profiling. >> >> unmapped_nr_anon should be normally always quite small. otherwise, >> something must be wrong. >> >>> >>>> >>>> Signed-off-by: Barry Song >>>> --- >>>> Documentation/admin-guide/mm/transhuge.rst | 5 +++++ >>>> include/linux/huge_mm.h | 15 +++++++++++++-- >>>> mm/huge_memory.c | 13 ++++++++++--- >>>> mm/migrate.c | 4 ++++ >>>> mm/page_alloc.c | 5 ++++- >>>> mm/rmap.c | 1 + >>>> 6 files changed, 37 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst >>>> index 058485daf186..9fdfb46e4560 100644 >>>> --- a/Documentation/admin-guide/mm/transhuge.rst >>>> +++ b/Documentation/admin-guide/mm/transhuge.rst >>>> @@ -527,6 +527,11 @@ split_deferred >>>> it would free up some memory. Pages on split queue are going to >>>> be split under memory pressure, if splitting is possible. >>>> >>>> +nr_anon >>>> + the number of anon huge pages we have in the whole system. >>> >>> "transparent ..." otherwise people might confuse it with anon hugetlb >>> "huge pages" ... :) >>> >>> I briefly tried coming up with a better name than "nr_anon" but failed. >>> >>> >> >> if we might have unmapped_anon counter later, maybe rename it to >> nr_anon_mapped? and the new interface we will have in the future >> might be nr_anon_unmapped? We really shouldn't be using the mapped/unmapped terminology here ... we allocated pages and turned them into anonymous folios. At some point we free them. That's the lifecycle. > > On second thought, this might be incorrect as well. Concepts like 'anon', > 'shmem', and 'file' refer to states after mapping. If an 'anon' has been > unmapped but is still pinned and not yet freed, it isn't technically an > 'anon' anymore? It's just not mapped, and cannot get mapped, anymore. In the memdesc world, we'd be freeing the "struct anon" or "struct folio" once the last refcount goes to 0, not once (e.g., temporarily during a failed migration?) unmapped. The important part to me would be: this is memory that was allocated for anonymous memory, and it's still around for some reason and not getting freed. Usually, we would expect anon memory to get freed fairly quickly once unmapped. Except when there are long-term pinnings or other types of memory leaks. You could happily continue using these anon pages via vmsplice() or similar, even thought he original page table mapping was torn down. > > On the other hand, implementing nr_anon_unmapped could be extremely > tricky. I have no idea how to implement it as we are losing those mapping > flags. folio_mapcount() can tell you efficiently whether a folio is mapped or not -- and that information will stay for all eternity as long as we have any mapcounts :) . It cannot tell "how many" pages of a large folio are mapped, but at least "is any page of this large folio mapped". > > However, a page that is read-ahead but not yet mapped can still become > an anon, which seems slightly less tricky to count though seems still > difficult - except anon pages, shmem can be also swapped-backed? Yes. I'm sure there would be ways to achieve it, but I am not sure if it's worth the churn. These pages can be reclaimed easily (I would assume? They are not even mapped and were never accessible via GUP), and can certainly not have any longterm pinnings or similar. There are more like "cached things that could become an anon folio". -- Cheers, David / dhildenb