linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: lantianyu1986@gmail.com
To: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org,
	dave.hansen@linux.intel.com, luto@kernel.org,
	peterz@infradead.org, kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, sashal@kernel.org,
	akpm@linux-foundation.org, rppt@linux.ibm.com, jgross@suse.com,
	mhocko@suse.com, paul.burton@mips.com, m.mizuma@jp.fujitsu.com,
	huang.zijiang@zte.com.cn, karahmed@amazon.de,
	dan.j.williams@intel.com, bhelgaas@google.com, osalvador@suse.de,
	rdunlap@infradead.org, richardw.yang@linux.intel.com,
	david@redhat.com, pavel.tatashin@microsoft.com, cai@lca.pw,
	arunks@codeaurora.org, vbabka@suse.cz,
	mgorman@techsingularity.net, alexander.h.duyck@linux.intel.com,
	glider@google.com, logang@deltatee.com, bsingharora@gmail.com,
	bhe@redhat.com, Tianyu.Lan@microsoft.com,
	michael.h.kelley@microsoft.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hyperv@vger.kernel.org, linux-mm@kvack.org,
	vkuznets@redhat.com
Subject: [RFC PATCH] mm: set memory section offline when all its pages are offline.
Date: Tue,  8 Oct 2019 22:36:48 +0800	[thread overview]
Message-ID: <20191008143648.11882-1-Tianyu.Lan@microsoft.com> (raw)

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

If size of offline memory region passed to offline_pages() is
not aligned with PAGES_PER_SECTION, memory section will be set
to offline in the offline_mem_sections() with some pages of
memory section online. Fix it, Update memory section status after
marking offline pages as "reserved" in __offline_isolated_pages()
and check all pages in memory are reserved or not before setting
memory section offline.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
This patch is to prepare for hot remove memory function in Hyper-V
balloon driver. It requests to offline memory with random size.
---
 mm/page_alloc.c |  3 ++-
 mm/sparse.c     | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index dbd0d5cbbcbb..cc02866924ae 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8540,7 +8540,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
 	if (pfn == end_pfn)
 		return offlined_pages;
 
-	offline_mem_sections(pfn, end_pfn);
 	zone = page_zone(pfn_to_page(pfn));
 	spin_lock_irqsave(&zone->lock, flags);
 	pfn = start_pfn;
@@ -8576,6 +8575,8 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
 	}
 	spin_unlock_irqrestore(&zone->lock, flags);
 
+	offline_mem_sections(pfn, end_pfn);
+
 	return offlined_pages;
 }
 #endif
diff --git a/mm/sparse.c b/mm/sparse.c
index fd13166949b5..eb5860487b84 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -571,6 +571,7 @@ void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
 void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
 {
 	unsigned long pfn;
+	int i;
 
 	for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
 		unsigned long section_nr = pfn_to_section_nr(pfn);
@@ -583,6 +584,15 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
 		if (WARN_ON(!valid_section_nr(section_nr)))
 			continue;
 
+		/*
+		 * Check whether all pages in the section are reserverd before
+		 * setting setction offline.
+		 */
+		for (i = 0; i < PAGES_PER_SECTION; i++)
+			if (!PageReserved(pfn_to_page(
+			    SECTION_ALIGN_DOWN(pfn + i))))
+				continue;
+
 		ms = __nr_to_section(section_nr);
 		ms->section_mem_map &= ~SECTION_IS_ONLINE;
 	}
-- 
2.14.5



             reply	other threads:[~2019-10-08 14:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 14:36 lantianyu1986 [this message]
2019-10-08 14:51 ` David Hildenbrand

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=20191008143648.11882-1-Tianyu.Lan@microsoft.com \
    --to=lantianyu1986@gmail.com \
    --cc=Tianyu.Lan@microsoft.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.h.duyck@linux.intel.com \
    --cc=arunks@codeaurora.org \
    --cc=bhe@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=bsingharora@gmail.com \
    --cc=cai@lca.pw \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=glider@google.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=huang.zijiang@zte.com.cn \
    --cc=jgross@suse.com \
    --cc=karahmed@amazon.de \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=logang@deltatee.com \
    --cc=luto@kernel.org \
    --cc=m.mizuma@jp.fujitsu.com \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=michael.h.kelley@microsoft.com \
    --cc=mingo@redhat.com \
    --cc=osalvador@suse.de \
    --cc=paul.burton@mips.com \
    --cc=pavel.tatashin@microsoft.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=richardw.yang@linux.intel.com \
    --cc=rkrcmar@redhat.com \
    --cc=rppt@linux.ibm.com \
    --cc=sashal@kernel.org \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.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