linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: chunpeng lee <chunpeng.lee@outlook.com>
To: 21cnbao@gmail.com
Cc: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com,
	chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com,
	ioworker0@gmail.com, kaleshsingh@google.com, kasong@tencent.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	ryan.roberts@arm.com, usamaarif642@gmail.com,
	v-songbaohua@oppo.com, yuanshuai@oppo.com, ziy@nvidia.com
Subject: Re: [PATCH v4 1/2] mm: count the number of anonymous THPs per size
Date: Tue, 10 Sep 2024 03:56:01 +0800	[thread overview]
Message-ID: <TYAPR01MB4685E67999FE3372EAE2CC4692992@TYAPR01MB4685.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <20240824010441.21308-2-21cnbao@gmail.com>

> Let's track for each anonymous THP size, how many of them are currently
> allocated. We'll track the complete lifespan of an anon THP, starting
> when it becomes an anon THP ("large anon folio") (->mapping gets set),
> until it gets freed (->mapping gets cleared).

IIUC, If an anon THP is swapped out as a whole, it is still being counted, correct?

> Note that AnonPages in /proc/meminfo currently tracks the total number
> of *mapped* anonymous *pages*, and therefore has slightly different
> semantics. In the future, we might also want to track "nr_anon_mapped"
> for each THP size, which might be helpful when comparing it to the
> number of allocated anon THPs (long-term pinning, stuck in swapcache,
> memory leaks, ...).

If we do not consider tracking each THP size, Can we expand the NR_ANON_THPS
statistic to include pte-mapped thp as well?

---
 mm/memcontrol-v1.c | 2 +-
 mm/rmap.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 44803cbea38a..3e44175db81f 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -786,7 +786,7 @@ static int mem_cgroup_move_account(struct folio *folio,
 if (folio_mapped(folio)) {
 __mod_lruvec_state(from_vec, NR_ANON_MAPPED, -nr_pages);
 __mod_lruvec_state(to_vec, NR_ANON_MAPPED, nr_pages);
- if (folio_test_pmd_mappable(folio)) {
+ if (folio_test_large(folio)) {
 __mod_lruvec_state(from_vec, NR_ANON_THPS,
 -nr_pages);
 __mod_lruvec_state(to_vec, NR_ANON_THPS,
diff --git a/mm/rmap.c b/mm/rmap.c
index a8797d1b3d49..97eb25d023ba 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1291,6 +1291,11 @@ static void __folio_mod_stat(struct folio *folio, int nr, int nr_pmdmapped)
 if (nr) {
 idx = folio_test_anon(folio) ? NR_ANON_MAPPED : NR_FILE_MAPPED;
 __lruvec_stat_mod_folio(folio, idx, nr);
+
+ if (folio_test_anon(folio) &&
+ folio_test_large(folio) &&
+ nr == 1 << folio_order(folio))
+ __lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr);
 }
 if (nr_pmdmapped) {
 if (folio_test_anon(folio)) {
--


  parent reply	other threads:[~2024-09-09 19:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-24  1:04 [PATCH v4 0/2] " Barry Song
2024-08-24  1:04 ` [PATCH v4 1/2] " Barry Song
2024-08-26  6:35   ` David Hildenbrand
2024-09-09 19:56   ` chunpeng lee [this message]
2024-08-24  1:04 ` [PATCH v4 2/2] mm: count the number of partially mapped " Barry Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=TYAPR01MB4685E67999FE3372EAE2CC4692992@TYAPR01MB4685.jpnprd01.prod.outlook.com \
    --to=chunpeng.lee@outlook.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hanchuanhua@oppo.com \
    --cc=ioworker0@gmail.com \
    --cc=kaleshsingh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=usamaarif642@gmail.com \
    --cc=v-songbaohua@oppo.com \
    --cc=yuanshuai@oppo.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox