Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mm/resource: Move child to new resource when release mem region.
@ 2019-10-10  7:28 lantianyu1986
  2019-10-10 14:29 ` Dave Hansen
  0 siblings, 1 reply; 3+ messages in thread
From: lantianyu1986 @ 2019-10-10  7:28 UTC (permalink / raw)
  To: dan.j.williams, dave.hansen, mingo, mpe, pasha.tatashin,
	osalvador, richardw.yang, Tianyu.Lan, christophe.leroy, bp,
	rdunlap, michael.h.kelley, kys, sashal
  Cc: linux-kernel, vkuznets, linux-hyperv

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

When release mem region, old mem region may be splited to
two regions. Current allocate new struct resource for high
end mem region but not move child resources whose ranges are
in the high end range to new resource. When adjust old mem
region's range, adjust_resource() detects child region's range
is out of new range and return error. Move child resources to
high end resource before adjusting old mem range.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
This patch is to prepare for memory hot-remove function
in Hyper-V balloon driver.
---
 kernel/resource.c | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index 158f04ec1d4f..7856347adfd2 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -181,6 +181,38 @@ static struct resource *alloc_resource(gfp_t flags)
 	return res;
 }
 
+static void move_child_to_newresource(struct resource *old,
+				      struct resource *new)
+{
+	struct resource *tmp, **p, **np;
+
+	if (!old->child)
+		return;
+
+	p = &old->child;
+	np = &new->child;
+
+	for (;;) {
+		tmp = *p;
+		if (!tmp)
+			break;
+
+		if (tmp->start >= new->start && tmp->end <= new->end) {
+			tmp->parent = new;
+			*np = tmp;
+			np = &tmp->sibling;
+			*p = tmp->sibling;
+
+			if (!tmp->sibling)
+				*np = NULL;
+			continue;
+		}
+
+		p = &tmp->sibling;
+	}
+}
+
 /* Return the conflict entry if you can't request it */
 static struct resource * __request_resource(struct resource *root, struct resource *new)
 {
@@ -1231,9 +1263,6 @@ EXPORT_SYMBOL(__release_region);
  * Note:
  * - Additional release conditions, such as overlapping region, can be
  *   supported after they are confirmed as valid cases.
- * - When a busy memory resource gets split into two entries, the code
- *   assumes that all children remain in the lower address entry for
- *   simplicity.  Enhance this logic when necessary.
  */
 int release_mem_region_adjustable(struct resource *parent,
 				  resource_size_t start, resource_size_t size)
@@ -1316,11 +1345,12 @@ int release_mem_region_adjustable(struct resource *parent,
 			new_res->sibling = res->sibling;
 			new_res->child = NULL;
 
+			move_child_to_newresource(res, new_res);
+			res->sibling = new_res;
 			ret = __adjust_resource(res, res->start,
 						start - res->start);
 			if (ret)
 				break;
-			res->sibling = new_res;
 			new_res = NULL;
 		}
 
-- 
2.14.5


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

* Re: [PATCH] mm/resource: Move child to new resource when release mem region.
  2019-10-10  7:28 [PATCH] mm/resource: Move child to new resource when release mem region lantianyu1986
@ 2019-10-10 14:29 ` Dave Hansen
  2019-10-11 14:53   ` Tianyu Lan
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Hansen @ 2019-10-10 14:29 UTC (permalink / raw)
  To: lantianyu1986, dan.j.williams, dave.hansen, mingo, mpe,
	pasha.tatashin, osalvador, richardw.yang, Tianyu.Lan,
	christophe.leroy, bp, rdunlap, michael.h.kelley, kys, sashal
  Cc: linux-kernel, vkuznets, linux-hyperv

On 10/10/19 12:28 AM, lantianyu1986@gmail.com wrote:
> When release mem region, old mem region may be splited to
> two regions. Current allocate new struct resource for high
> end mem region but not move child resources whose ranges are
> in the high end range to new resource. When adjust old mem
> region's range, adjust_resource() detects child region's range
> is out of new range and return error. Move child resources to
> high end resource before adjusting old mem range.

From the comment, it appears the old code intended to have the behavior
that you are changing.  Could you explain _why_ this has become a
problem for you?


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

* RE: [PATCH] mm/resource: Move child to new resource when release mem region.
  2019-10-10 14:29 ` Dave Hansen
@ 2019-10-11 14:53   ` Tianyu Lan
  0 siblings, 0 replies; 3+ messages in thread
From: Tianyu Lan @ 2019-10-11 14:53 UTC (permalink / raw)
  To: Dave Hansen, lantianyu1986, dan.j.williams, dave.hansen, mingo,
	mpe, pasha.tatashin, osalvador, richardw.yang, christophe.leroy,
	bp, rdunlap, Michael Kelley, KY Srinivasan, sashal
  Cc: linux-kernel, vkuznets, linux-hyperv

On 10/10/2019 10:29 PM, Dave Hansen wrote:> On 10/10/19 12:28 AM, lantianyu1986@gmail.com wrote:
>> When release mem region, old mem region may be splited to
>> two regions. Current allocate new struct resource for high
>> end mem region but not move child resources whose ranges are
>> in the high end range to new resource. When adjust old mem
>> region's range, adjust_resource() detects child region's range
>> is out of new range and return error. Move child resources to
>> high end resource before adjusting old mem range.
> 
>  From the comment, it appears the old code intended to have the behavior
> that you are changing.  Could you explain _why_ this has become a
> problem for you?
Hi Dave:
    Thanks for your review. current code assumes that all children remain in
 the lower address entry for simplicity. For memory hot-remove, selecting
remove region via scanning system memory may hit case of child in the
higher address entry.

For example, the following output from /proc/iomem shows kernel code,
data and bss locate from 3a000000 to 3b5fffff and these resources are the
system ram resource's children. If the 39800000-39ffffff was selected as
remove range, the resource will be split into two ranges 00100000-397fffff
and 39800000-b87f1fff. Current code move kernel image related resources
under 00100000-397fffff resource. This will cause adjust_resource() return
error because children are not in the parent's range.

00100000-b87f1fff : System RAM
  3a000000-3ac00e80 : Kernel code
  3ac00e81-3b33883f : Kernel data
  3b4d3000-3b5fffff : Kernel bss




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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10  7:28 [PATCH] mm/resource: Move child to new resource when release mem region lantianyu1986
2019-10-10 14:29 ` Dave Hansen
2019-10-11 14:53   ` Tianyu Lan

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