Commit 7e9c56da authored by Lance Yang's avatar Lance Yang Committed by Liu Shixin
Browse files

mm: add per-order mTHP split counters

mainline inclusion
from mainline-v6.11-rc1
commit f216c845f3c772e54d27fe209fd300b10e7bf54a
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAIHPC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f216c845f3c772e54d27fe209fd300b10e7bf54a

--------------------------------

Patch series "mm: introduce per-order mTHP split counters", v3.

At present, the split counters in THP statistics no longer include
PTE-mapped mTHP.  Therefore, we want to introduce per-order mTHP split
counters to monitor the frequency of mTHP splits.  This will assist
developers in better analyzing and optimizing system performance.

/sys/kernel/mm/transparent_hugepage/hugepages-<size>/stats
        split
        split_failed
        split_deferred

This patch (of 2):

Currently, the split counters in THP statistics no longer include
PTE-mapped mTHP.  Therefore, we propose introducing per-order mTHP split
counters to monitor the frequency of mTHP splits.  This will help
developers better analyze and optimize system performance.

/sys/kernel/mm/transparent_hugepage/hugepages-<size>/stats
        split
        split_failed
        split_deferred

[ioworker0@gmail.com: make things more readable, per Barry and Baolin]
  Link: https://lkml.kernel.org/r/20240704012905.42971-2-ioworker0@gmail.com
[ioworker0@gmail.com: use == for `order' test, per David]
  Link: https://lkml.kernel.org/r/20240705113119.82210-1-ioworker0@gmail.com
Link: https://lkml.kernel.org/r/20240704012905.42971-1-ioworker0@gmail.com
Link: https://lkml.kernel.org/r/20240704012905.42971-2-ioworker0@gmail.com
Link: https://lkml.kernel.org/r/20240628130750.73097-1-ioworker0@gmail.com
Link: https://lkml.kernel.org/r/20240628130750.73097-2-ioworker0@gmail.com


Signed-off-by: default avatarMingzhe Yang <mingzhe.yang@ly.com>
Signed-off-by: default avatarLance Yang <ioworker0@gmail.com>
Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Acked-by: default avatarBarry Song <baohua@kernel.org>
Reviewed-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
Cc: Bang Li <libang.li@antgroup.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent e9c3ca09
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -284,6 +284,9 @@ enum mthp_stat_item {
	MTHP_STAT_FILE_ALLOC,
	MTHP_STAT_FILE_FALLBACK,
	MTHP_STAT_FILE_FALLBACK_CHARGE,
	MTHP_STAT_SPLIT,
	MTHP_STAT_SPLIT_FAILED,
	MTHP_STAT_SPLIT_DEFERRED,
	__MTHP_STAT_COUNT
};

+10 −2
Original line number Diff line number Diff line
@@ -722,6 +722,9 @@ DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK);
DEFINE_MTHP_STAT_ATTR(file_alloc, MTHP_STAT_FILE_ALLOC);
DEFINE_MTHP_STAT_ATTR(file_fallback, MTHP_STAT_FILE_FALLBACK);
DEFINE_MTHP_STAT_ATTR(file_fallback_charge, MTHP_STAT_FILE_FALLBACK_CHARGE);
DEFINE_MTHP_STAT_ATTR(split, MTHP_STAT_SPLIT);
DEFINE_MTHP_STAT_ATTR(split_failed, MTHP_STAT_SPLIT_FAILED);
DEFINE_MTHP_STAT_ATTR(split_deferred, MTHP_STAT_SPLIT_DEFERRED);

static struct attribute *stats_attrs[] = {
	&anon_fault_alloc_attr.attr,
@@ -732,6 +735,9 @@ static struct attribute *stats_attrs[] = {
	&file_alloc_attr.attr,
	&file_fallback_attr.attr,
	&file_fallback_charge_attr.attr,
	&split_attr.attr,
	&split_failed_attr.attr,
	&split_deferred_attr.attr,
	NULL,
};

@@ -3250,7 +3256,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
	XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order);
	struct anon_vma *anon_vma = NULL;
	struct address_space *mapping = NULL;
	bool is_thp = folio_test_pmd_mappable(folio);
	int order = folio_order(folio);
	int extra_pins, ret;
	pgoff_t end;
	bool is_hzp;
@@ -3435,8 +3441,9 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
		i_mmap_unlock_read(mapping);
out:
	xas_destroy(&xas);
	if (is_thp)
	if (order == HPAGE_PMD_ORDER)
		count_vm_event(!ret ? THP_SPLIT_PAGE : THP_SPLIT_PAGE_FAILED);
	count_mthp_stat(order, !ret ? MTHP_STAT_SPLIT : MTHP_STAT_SPLIT_FAILED);
	return ret;
}

@@ -3489,6 +3496,7 @@ void deferred_split_folio(struct folio *folio)
	if (list_empty(&folio->_deferred_list)) {
		if (folio_test_pmd_mappable(folio))
			count_vm_event(THP_DEFERRED_SPLIT_PAGE);
		count_mthp_stat(folio_order(folio), MTHP_STAT_SPLIT_DEFERRED);
		list_add_tail(&folio->_deferred_list, &ds_queue->split_queue);
		ds_queue->split_queue_len++;
#ifdef CONFIG_MEMCG