mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, guro@fb.com, hannes@cmpxchg.org,
	linux-mm@kvack.org, mhocko@kernel.org,
	mm-commits@vger.kernel.org, shakeelb@google.com,
	shy828301@gmail.com, songmuchun@bytedance.com,
	stable@vger.kernel.org, torvalds@linux-foundation.org
Subject: [patch 05/19] mm: fix numa stats for thp migration
Date: Sat, 23 Jan 2021 21:01:15 -0800	[thread overview]
Message-ID: <20210124050115.pcRcPJgcb%akpm@linux-foundation.org> (raw)
In-Reply-To: <20210123210029.a7c704d0cab204683e41ad10@linux-foundation.org>

From: Shakeel Butt <shakeelb@google.com>
Subject: mm: fix numa stats for thp migration

Currently the kernel is not correctly updating the numa stats for
NR_FILE_PAGES and NR_SHMEM on THP migration.  Fix that.  For NR_FILE_DIRTY
and NR_ZONE_WRITE_PENDING, although at the moment there is no need to
handle THP migration as kernel still does not have write support for file
THP but to be more future proof, this patch adds the THP support for those
stats as well.

Link: https://lkml.kernel.org/r/20210108155813.2914586-2-shakeelb@google.com
Fixes: e71769ae52609 ("mm: enable thp migration for shmem thp")
Signed-off-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Yang Shi <shy828301@gmail.com>
Reviewed-by: Roman Gushchin <guro@fb.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/migrate.c |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

--- a/mm/migrate.c~mm-fix-numa-stats-for-thp-migration
+++ a/mm/migrate.c
@@ -402,6 +402,7 @@ int migrate_page_move_mapping(struct add
 	struct zone *oldzone, *newzone;
 	int dirty;
 	int expected_count = expected_page_refs(mapping, page) + extra_count;
+	int nr = thp_nr_pages(page);
 
 	if (!mapping) {
 		/* Anonymous page without mapping */
@@ -437,7 +438,7 @@ int migrate_page_move_mapping(struct add
 	 */
 	newpage->index = page->index;
 	newpage->mapping = page->mapping;
-	page_ref_add(newpage, thp_nr_pages(page)); /* add cache reference */
+	page_ref_add(newpage, nr); /* add cache reference */
 	if (PageSwapBacked(page)) {
 		__SetPageSwapBacked(newpage);
 		if (PageSwapCache(page)) {
@@ -459,7 +460,7 @@ int migrate_page_move_mapping(struct add
 	if (PageTransHuge(page)) {
 		int i;
 
-		for (i = 1; i < HPAGE_PMD_NR; i++) {
+		for (i = 1; i < nr; i++) {
 			xas_next(&xas);
 			xas_store(&xas, newpage);
 		}
@@ -470,7 +471,7 @@ int migrate_page_move_mapping(struct add
 	 * to one less reference.
 	 * We know this isn't the last reference.
 	 */
-	page_ref_unfreeze(page, expected_count - thp_nr_pages(page));
+	page_ref_unfreeze(page, expected_count - nr);
 
 	xas_unlock(&xas);
 	/* Leave irq disabled to prevent preemption while updating stats */
@@ -493,17 +494,17 @@ int migrate_page_move_mapping(struct add
 		old_lruvec = mem_cgroup_lruvec(memcg, oldzone->zone_pgdat);
 		new_lruvec = mem_cgroup_lruvec(memcg, newzone->zone_pgdat);
 
-		__dec_lruvec_state(old_lruvec, NR_FILE_PAGES);
-		__inc_lruvec_state(new_lruvec, NR_FILE_PAGES);
+		__mod_lruvec_state(old_lruvec, NR_FILE_PAGES, -nr);
+		__mod_lruvec_state(new_lruvec, NR_FILE_PAGES, nr);
 		if (PageSwapBacked(page) && !PageSwapCache(page)) {
-			__dec_lruvec_state(old_lruvec, NR_SHMEM);
-			__inc_lruvec_state(new_lruvec, NR_SHMEM);
+			__mod_lruvec_state(old_lruvec, NR_SHMEM, -nr);
+			__mod_lruvec_state(new_lruvec, NR_SHMEM, nr);
 		}
 		if (dirty && mapping_can_writeback(mapping)) {
-			__dec_lruvec_state(old_lruvec, NR_FILE_DIRTY);
-			__dec_zone_state(oldzone, NR_ZONE_WRITE_PENDING);
-			__inc_lruvec_state(new_lruvec, NR_FILE_DIRTY);
-			__inc_zone_state(newzone, NR_ZONE_WRITE_PENDING);
+			__mod_lruvec_state(old_lruvec, NR_FILE_DIRTY, -nr);
+			__mod_zone_page_state(oldzone, NR_ZONE_WRITE_PENDING, -nr);
+			__mod_lruvec_state(new_lruvec, NR_FILE_DIRTY, nr);
+			__mod_zone_page_state(newzone, NR_ZONE_WRITE_PENDING, nr);
 		}
 	}
 	local_irq_enable();
_

  parent reply	other threads:[~2021-01-24  5:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-24  5:00 incoming Andrew Morton
2021-01-24  5:00 ` [patch 01/19] x86/setup: don't remove E820_TYPE_RAM for pfn 0 Andrew Morton
2021-01-24  5:01 ` [patch 02/19] mm: fix initialization of struct page for holes in memory layout Andrew Morton
2021-01-24  5:01 ` [patch 03/19] mm: memcg/slab: optimize objcg stock draining Andrew Morton
2021-01-24  5:01 ` [patch 04/19] mm: memcg: fix memcg file_dirty numa stat Andrew Morton
2021-01-24  5:01 ` Andrew Morton [this message]
2021-01-24  5:01 ` [patch 06/19] mm: memcontrol: prevent starvation when writing memory.high Andrew Morton
2021-01-24 18:01   ` Shakeel Butt
2021-01-24 18:35     ` Linus Torvalds
2021-01-24  5:01 ` [patch 07/19] kasan: fix unaligned address is unhandled in kasan_remove_zero_shadow Andrew Morton
2021-01-24  5:01 ` [patch 08/19] kasan: fix incorrect arguments passing in kasan_add_zero_shadow Andrew Morton
2021-01-24  5:01 ` [patch 09/19] kasan: fix HW_TAGS boot parameters Andrew Morton
2021-01-24  5:01 ` [patch 10/19] kasan, mm: fix conflicts with init_on_alloc/free Andrew Morton
2021-01-24  5:01 ` [patch 11/19] kasan, mm: fix resetting page_alloc tags for HW_TAGS Andrew Morton
2021-01-24  5:01 ` [patch 12/19] ubsan: disable unsigned-overflow check for i386 Andrew Morton
2021-01-24  5:01 ` [patch 13/19] mm: fix page reference leak in soft_offline_page() Andrew Morton
2021-01-24  5:01 ` [patch 14/19] sparc/mm/highmem: flush cache and TLB Andrew Morton
2021-01-24  5:02 ` [patch 15/19] mm/highmem: prepare for overriding set_pte_at() Andrew Morton
2021-01-24  5:02 ` [patch 16/19] mips/mm/highmem: use set_pte() for kmap_local() Andrew Morton
2021-01-24  5:02 ` [patch 17/19] powerpc/mm/highmem: use __set_pte_at() " Andrew Morton
2021-01-24  5:02 ` [patch 18/19] proc_sysctl: fix oops caused by incorrect command parameters Andrew Morton
2021-01-24  5:02 ` [patch 19/19] MAINTAINERS: add a couple more files to the Clang/LLVM section Andrew Morton

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=20210124050115.pcRcPJgcb%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=shakeelb@google.com \
    --cc=shy828301@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).