Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
* [RFC PATCH] mm: set memory section offline when all its pages are offline.
@ 2019-10-08 14:36 lantianyu1986
  2019-10-08 14:51 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: lantianyu1986 @ 2019-10-08 14:36 UTC (permalink / raw)
  To: pbonzini, rkrcmar, tglx, mingo, bp, hpa, x86, dave.hansen, luto,
	peterz, kys, haiyangz, sthemmin, sashal, akpm, rppt, jgross,
	mhocko, paul.burton, m.mizuma, huang.zijiang, karahmed,
	dan.j.williams, bhelgaas, osalvador, rdunlap, richardw.yang,
	david, pavel.tatashin, cai, arunks, vbabka, mgorman,
	alexander.h.duyck, glider, logang, bsingharora, bhe, Tianyu.Lan,
	michael.h.kelley
  Cc: kvm, linux-kernel, linux-hyperv, linux-mm, vkuznets

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH] mm: set memory section offline when all its pages are offline.
  2019-10-08 14:36 [RFC PATCH] mm: set memory section offline when all its pages are offline lantianyu1986
@ 2019-10-08 14:51 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2019-10-08 14:51 UTC (permalink / raw)
  To: lantianyu1986, pbonzini, rkrcmar, tglx, mingo, bp, hpa, x86,
	dave.hansen, luto, peterz, kys, haiyangz, sthemmin, sashal, akpm,
	rppt, jgross, mhocko, paul.burton, m.mizuma, huang.zijiang,
	karahmed, dan.j.williams, bhelgaas, osalvador, rdunlap,
	richardw.yang, pavel.tatashin, cai, arunks, vbabka, mgorman,
	alexander.h.duyck, glider, logang, bsingharora, bhe, Tianyu.Lan,
	michael.h.kelley
  Cc: kvm, linux-kernel, linux-hyperv, linux-mm, vkuznets

On 08.10.19 16:36, lantianyu1986@gmail.com wrote:
> 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.

I proposed roughly the same a while ago. See

https://lkml.org/lkml/2018/4/30/207

Memory onlining/offlining works in memory block granularity only.
Sub-sections, you have to emulate it on top, similar to how hyper-v
balloon handles it already. E.g., have a look how virtio-mem handles it
using alloc_contig_range/free_contig_range and PG_offline extensions.

https://lkml.org/lkml/2018/4/30/207

So a clear NACK from my side.


> ---
>  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;
>  	}
> 


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-08 14:36 [RFC PATCH] mm: set memory section offline when all its pages are offline lantianyu1986
2019-10-08 14:51 ` David Hildenbrand

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hyperv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git