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 C7C77C4345F for ; Wed, 24 Apr 2024 03:48:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 294216B01F5; Tue, 23 Apr 2024 23:48:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 243D36B01F6; Tue, 23 Apr 2024 23:48:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1330D6B01F7; Tue, 23 Apr 2024 23:48:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E85676B01F5 for ; Tue, 23 Apr 2024 23:48:35 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8BEF7140478 for ; Wed, 24 Apr 2024 03:48:35 +0000 (UTC) X-FDA: 82043043390.04.ABFB4E4 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf14.hostedemail.com (Postfix) with ESMTP id 2E461100007 for ; Wed, 24 Apr 2024 03:48:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=XZdKxFjH; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713930513; 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=i+3UguXcbzDLCETmEYwCVhpdB29rZwyImQLfXWWDzHk=; b=MU53BxGOGRjaCoxT+bZ7M9tu8aIz3LJZGxYcADIGSFJ7TIMb7j3F0bItXjUm5dWxVYO3D/ LcS6lJrXxWrftuaTaT29G63snEfgJb5d8gdvzTK5zsppXIJaFLypr+Hr69dzGDi/whRGtt wzJ8+gZt5GZmu4XSKGyHJSGJELjGWqs= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=XZdKxFjH; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713930513; a=rsa-sha256; cv=none; b=pHVzWTlBVJSN7MzkoolxnHl4xdSdsNn5ueRYn7nLJhM0Z03cWIZdpFzKIi/7l+4EKNgOoZ E5LPLhSDs+zuAWdW4yaRhMr0lE79t5mcBs1MTC8zc6c+NeRMEMLWsKwF7JFv1vVI3lEPrR opJLAQvRd94E+rz+mj9wOif3SLn1Feo= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713930508; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=i+3UguXcbzDLCETmEYwCVhpdB29rZwyImQLfXWWDzHk=; b=XZdKxFjHn1SsTcDMj04oKltGqSP3EfVbmwcRsw/WndNlFTHaWJo9iDffSvWysjFG4bF/5FiHQYihPDRBo8ZTVIbtIUJq48NVhIhokfONyGTchyCAgq60As2atZtYe1rOi45hC90fsmmMXzOyWTWftKWHEXAv9Nk9+uRVsrqM0bU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R321e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033022160150;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0W5AlpPR_1713930504; Received: from 30.97.56.58(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W5AlpPR_1713930504) by smtp.aliyun-inc.com; Wed, 24 Apr 2024 11:48:26 +0800 Message-ID: <8e0a34df-3a02-40a6-a09d-3b4a25ec7fcf@linux.alibaba.com> Date: Wed, 24 Apr 2024 11:48:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 5/5] mm: shmem: add anonymous share mTHP counters To: Ryan Roberts , Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, hughd@google.com, willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, shy828301@gmail.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <05d0096e4ec3e572d1d52d33a31a661321ac1551.1713755580.git.baolin.wang@linux.alibaba.com> <3045341d-06c2-4fdb-88a1-3f0d473f99ee@linux.alibaba.com> <5f147c9d-ba00-4757-b88e-38b45fffb8d3@arm.com> From: Baolin Wang In-Reply-To: <5f147c9d-ba00-4757-b88e-38b45fffb8d3@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2E461100007 X-Stat-Signature: ekw8i3dezuq7dh4oraq4ueorfzep8ac8 X-HE-Tag: 1713930511-34658 X-HE-Meta: U2FsdGVkX19zMhoM3ugZK3YHqO3t5P9d/eD1+5rylv5VxIbqtH4aK0Itfc/6U5ICqbz60ulOno16sk78ZJ/gGgF9uF6BTKDpUYteCjCHzHCfKo8lQDNJgPHsNZkE3LKKdOllnlHql96mCZyjNfkgPE8wUEfuk21mPD/4seo6C4h6gwnF1aXFWIN2HfurVTfCP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FrEq2z8N90iZ9lTrQsDor/jlWiodNXY50T4lxMLjUOe++glfKYR3ZUTL8Fh4N8yxa42RfP1H 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 2024/4/23 19:39, Ryan Roberts wrote: > On 23/04/2024 02:46, Baolin Wang wrote: >> >> >> On 2024/4/23 09:17, Barry Song wrote: >>> On Mon, Apr 22, 2024 at 3:03 PM Baolin Wang >>> wrote: >>>> >>>> Signed-off-by: Baolin Wang >>>> --- >>>>   include/linux/huge_mm.h | 2 ++ >>>>   mm/huge_memory.c        | 4 ++++ >>>>   mm/shmem.c              | 5 ++++- >>>>   3 files changed, 10 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >>>> index 26b6fa98d8ac..67b9c1acad31 100644 >>>> --- a/include/linux/huge_mm.h >>>> +++ b/include/linux/huge_mm.h >>>> @@ -270,6 +270,8 @@ enum mthp_stat_item { >>>>          MTHP_STAT_ANON_SWPOUT, >>>>          MTHP_STAT_ANON_SWPOUT_FALLBACK, >>>>          MTHP_STAT_ANON_SWPIN_REFAULT, >>>> +       MTHP_STAT_SHMEM_ANON_ALLOC, >>>> +       MTHP_STAT_SHMEM_ANON_ALLOC_FALLBACK, >>> >>> not quite sure about this. for 2MB pmd-mapped THP shmem, we count them >>> as FILE_THP. >>> here we are counting as SHMEM_ANON. To me, SHMEM_ANON is more correct but >>> it doesn't align with pmd-mapped THP. David, Ryan, what do you think? >> >> Thanks for reviewing. >> >> IMO, I think both approaches are acceptable, which also reflects the dual nature >> of anonymous shared pages: on the one hand they are anonymous pages, and on the >> other hand, they are backed by a pseudo file. From the user's perspective, I >> prefer to use the term "anonymous shmem", which can be distinguished from the >> real file-backed THP. >> >> Anyway, let's see what others think. > > From a quick look at the code, it looks like the shmem alloc/fallback/charge > events are all lumped in with FILE_THP. But the instantaneous "how many are > allocated" and "how many are mapped" have their own NR_SHMEM_THPS and > NR_SHMEM_PMDMAPPED counters? So its a bit inconsistent today. > > My preference would be to add these to be consistent with the anon stats: > > MTHP_STAT_SHMEM_FAULT_ALLOC, > MTHP_STAT_SHMEM_FAULT_FALLBACK, > MTHP_STAT_SHMEM_FAULT_FALLBACK_CHARGE, > > But it looks like these aren't always allocated due to faults? So perhaps: > > MTHP_STAT_SHMEM_ALLOC, > MTHP_STAT_SHMEM_FALLBACK, > MTHP_STAT_SHMEM_FALLBACK_CHARGE, This looks good to me. > If I've understood the code correctly (I know nothing about shmem), the > allocation can be for both mmap(SHARED|ANON) and for tmpfs? So "SHMEM_ANON" This is allowed, but the 'fd' for tmpfs will be ignored (see ksys_mmap_pgoff()), which is same with anonymous shmem. > probably isn't quite right? > > >> >>>>          __MTHP_STAT_COUNT >>>>   }; >>>> >>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>>> index 9e52c0db7580..dc15240c1ab3 100644 >>>> --- a/mm/huge_memory.c >>>> +++ b/mm/huge_memory.c >>>> @@ -557,6 +557,8 @@ DEFINE_MTHP_STAT_ATTR(anon_alloc_fallback, >>>> MTHP_STAT_ANON_ALLOC_FALLBACK); >>>>   DEFINE_MTHP_STAT_ATTR(anon_swpout, MTHP_STAT_ANON_SWPOUT); >>>>   DEFINE_MTHP_STAT_ATTR(anon_swpout_fallback, MTHP_STAT_ANON_SWPOUT_FALLBACK); >>>>   DEFINE_MTHP_STAT_ATTR(anon_swpin_refault, MTHP_STAT_ANON_SWPIN_REFAULT); >>>> +DEFINE_MTHP_STAT_ATTR(shmem_anon_alloc, MTHP_STAT_SHMEM_ANON_ALLOC); >>>> +DEFINE_MTHP_STAT_ATTR(shmem_anon_alloc_fallback, >>>> MTHP_STAT_SHMEM_ANON_ALLOC_FALLBACK); >>>> >>>>   static struct attribute *stats_attrs[] = { >>>>          &anon_alloc_attr.attr, >>>> @@ -564,6 +566,8 @@ static struct attribute *stats_attrs[] = { >>>>          &anon_swpout_attr.attr, >>>>          &anon_swpout_fallback_attr.attr, >>>>          &anon_swpin_refault_attr.attr, >>>> +       &shmem_anon_alloc_attr.attr, >>>> +       &shmem_anon_alloc_fallback_attr.attr, >>>>          NULL, >>>>   }; >>>> >>>> diff --git a/mm/shmem.c b/mm/shmem.c >>>> index 8b009e7040b2..4a0aa75ab29c 100644 >>>> --- a/mm/shmem.c >>>> +++ b/mm/shmem.c >>>> @@ -1706,11 +1706,14 @@ static struct folio *shmem_alloc_and_add_folio(struct >>>> vm_fault *vmf, >>>>                          pages = 1 << order; >>>>                          index = round_down(index, pages); >>>>                          folio = shmem_alloc_hugefolio(gfp, info, index, order); >>>> -                       if (folio) >>>> +                       if (folio) { >>>> +                               count_mthp_stat(order, >>>> MTHP_STAT_SHMEM_ANON_ALLOC); > > is there any reason why this can't go next to the existing PMD-size stat? No, will move to the existing PMD-size stat.