diff mbox series

[2/3] drivers/base/memory: introduce a new state 'isolate' for memblock

Message ID 1537327066-27852-3-git-send-email-kernelfans@gmail.com (mailing list archive)
State New, archived
Headers show
Series introduce a new state 'isolate' for memblock to split the isolation and migration steps | expand

Commit Message

Pingfan Liu Sept. 19, 2018, 3:17 a.m. UTC
Currently, offline pages in the unit of memblock, and normally, it is done
one by one on each memblock. If there is only one numa node, then the dst
pages may come from the next memblock to be offlined, which wastes time
during memory offline. For a system with multi numa node, if only replacing
part of mem on a node, and the migration dst page can be allocated from
local node (which is done by [3/3]), it also faces such issue.
This patch suggests to introduce a new state, named 'isolate', the state
transition can be isolate -> online or reversion. And another slight
benefit of "isolated" state is no further allocation on this memblock,
which can block potential unmovable page allocated again from this
memblock for a long time.

After this patch, the suggested ops to offline pages
will looks like:
  for i in {s..e}; do  echo isolate > memory$i/state; done
  for i in {s..e}; do  echo offline > memory$i/state; done

Since this patch does not change the original offline path, hence
  for i in (s..e); do  echo offline > memory$i/state; done
still works.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Pavel Tatashin <pasha.tatashin@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Bharata B Rao <bharata@linux.vnet.ibm.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 drivers/base/memory.c  | 31 ++++++++++++++++++++++++++++++-
 include/linux/memory.h |  1 +
 2 files changed, 31 insertions(+), 1 deletion(-)

Comments

kernel test robot Sept. 19, 2018, 6:49 a.m. UTC | #1
Hi Pingfan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.19-rc4 next-20180918]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Pingfan-Liu/introduce-a-new-state-isolate-for-memblock-to-split-the-isolation-and-migration-steps/20180919-112650
config: x86_64-randconfig-s0-09191204 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/base/memory.o: In function `store_mem_state':
>> drivers/base/memory.c:385: undefined reference to `start_isolate_page_range'
>> drivers/base/memory.c:391: undefined reference to `undo_isolate_page_range'

vim +385 drivers/base/memory.c

   323	
   324	static ssize_t
   325	store_mem_state(struct device *dev,
   326			struct device_attribute *attr, const char *buf, size_t count)
   327	{
   328		struct memory_block *mem = to_memory_block(dev);
   329		int ret, online_type;
   330		int isolated = 0;
   331		unsigned long start_pfn;
   332		unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
   333	
   334		ret = lock_device_hotplug_sysfs();
   335		if (ret)
   336			return ret;
   337	
   338		if (sysfs_streq(buf, "online_kernel"))
   339			online_type = MMOP_ONLINE_KERNEL;
   340		else if (sysfs_streq(buf, "online_movable"))
   341			online_type = MMOP_ONLINE_MOVABLE;
   342		else if (sysfs_streq(buf, "online"))
   343			online_type = MMOP_ONLINE_KEEP;
   344		else if (sysfs_streq(buf, "offline"))
   345			online_type = MMOP_OFFLINE;
   346		else if (sysfs_streq(buf, "isolate")) {
   347			isolated = 1;
   348			goto memblock_isolated;
   349		} else if (sysfs_streq(buf, "unisolate")) {
   350			isolated = -1;
   351			goto memblock_isolated;
   352		} else {
   353			ret = -EINVAL;
   354			goto err;
   355		}
   356	
   357		/*
   358		 * Memory hotplug needs to hold mem_hotplug_begin() for probe to find
   359		 * the correct memory block to online before doing device_online(dev),
   360		 * which will take dev->mutex.  Take the lock early to prevent an
   361		 * inversion, memory_subsys_online() callbacks will be implemented by
   362		 * assuming it's already protected.
   363		 */
   364		mem_hotplug_begin();
   365	
   366		switch (online_type) {
   367		case MMOP_ONLINE_KERNEL:
   368		case MMOP_ONLINE_MOVABLE:
   369		case MMOP_ONLINE_KEEP:
   370			mem->online_type = online_type;
   371			ret = device_online(&mem->dev);
   372			break;
   373		case MMOP_OFFLINE:
   374			ret = device_offline(&mem->dev);
   375			break;
   376		default:
   377			ret = -EINVAL; /* should never happen */
   378		}
   379	
   380		mem_hotplug_done();
   381	err:
   382	memblock_isolated:
   383		if (isolated == 1 && mem->state == MEM_ONLINE) {
   384			start_pfn = section_nr_to_pfn(mem->start_section_nr);
 > 385			ret = start_isolate_page_range(start_pfn, start_pfn + nr_pages,
   386				MIGRATE_MOVABLE, true, true);
   387			if (!ret)
   388				mem->state = MEM_ISOLATED;
   389		} else if (isolated == -1 && mem->state == MEM_ISOLATED) {
   390			start_pfn = section_nr_to_pfn(mem->start_section_nr);
 > 391			ret = undo_isolate_page_range(start_pfn, start_pfn + nr_pages,
   392				MIGRATE_MOVABLE, true);
   393			if (!ret)
   394				mem->state = MEM_ONLINE;
   395		}
   396		unlock_device_hotplug();
   397	
   398		if (ret < 0)
   399			return ret;
   400		if (ret)
   401			return -EINVAL;
   402	
   403		return count;
   404	}
   405	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index c8a1cb0..3b714be 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -19,6 +19,7 @@ 
 #include <linux/memory.h>
 #include <linux/memory_hotplug.h>
 #include <linux/mm.h>
+#include <linux/page-isolation.h>
 #include <linux/mutex.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
@@ -166,6 +167,9 @@  static ssize_t show_mem_state(struct device *dev,
 	case MEM_GOING_OFFLINE:
 		len = sprintf(buf, "going-offline\n");
 		break;
+	case MEM_ISOLATED:
+		len = sprintf(buf, "isolated\n");
+		break;
 	default:
 		len = sprintf(buf, "ERROR-UNKNOWN-%ld\n",
 				mem->state);
@@ -323,6 +327,9 @@  store_mem_state(struct device *dev,
 {
 	struct memory_block *mem = to_memory_block(dev);
 	int ret, online_type;
+	int isolated = 0;
+	unsigned long start_pfn;
+	unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
 
 	ret = lock_device_hotplug_sysfs();
 	if (ret)
@@ -336,7 +343,13 @@  store_mem_state(struct device *dev,
 		online_type = MMOP_ONLINE_KEEP;
 	else if (sysfs_streq(buf, "offline"))
 		online_type = MMOP_OFFLINE;
-	else {
+	else if (sysfs_streq(buf, "isolate")) {
+		isolated = 1;
+		goto memblock_isolated;
+	} else if (sysfs_streq(buf, "unisolate")) {
+		isolated = -1;
+		goto memblock_isolated;
+	} else {
 		ret = -EINVAL;
 		goto err;
 	}
@@ -366,6 +379,20 @@  store_mem_state(struct device *dev,
 
 	mem_hotplug_done();
 err:
+memblock_isolated:
+	if (isolated == 1 && mem->state == MEM_ONLINE) {
+		start_pfn = section_nr_to_pfn(mem->start_section_nr);
+		ret = start_isolate_page_range(start_pfn, start_pfn + nr_pages,
+			MIGRATE_MOVABLE, true, true);
+		if (!ret)
+			mem->state = MEM_ISOLATED;
+	} else if (isolated == -1 && mem->state == MEM_ISOLATED) {
+		start_pfn = section_nr_to_pfn(mem->start_section_nr);
+		ret = undo_isolate_page_range(start_pfn, start_pfn + nr_pages,
+			MIGRATE_MOVABLE, true);
+		if (!ret)
+			mem->state = MEM_ONLINE;
+	}
 	unlock_device_hotplug();
 
 	if (ret < 0)
@@ -455,6 +482,7 @@  static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
 static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
 static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
 static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
+//static DEVICE_ATTR(isolate, 0600, show_mem_isolate, store_mem_isolate);
 
 /*
  * Block size attribute stuff
@@ -631,6 +659,7 @@  static struct attribute *memory_memblk_attrs[] = {
 #ifdef CONFIG_MEMORY_HOTREMOVE
 	&dev_attr_valid_zones.attr,
 #endif
+	//&dev_attr_isolate.attr,
 	NULL
 };
 
diff --git a/include/linux/memory.h b/include/linux/memory.h
index a6ddefc..e00f22c 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -47,6 +47,7 @@  int set_memory_block_size_order(unsigned int order);
 #define	MEM_GOING_ONLINE	(1<<3)
 #define	MEM_CANCEL_ONLINE	(1<<4)
 #define	MEM_CANCEL_OFFLINE	(1<<5)
+#define	MEM_ISOLATED	(1<<6)
 
 struct memory_notify {
 	unsigned long start_pfn;