linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
	David Hildenbrand <david@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Pavel Tatashin <pasha.tatashin@oracle.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH v1 10/10] mm/memory_hotplug: allow online/offline memory by a kernel module
Date: Wed, 23 May 2018 17:11:51 +0200	[thread overview]
Message-ID: <20180523151151.6730-11-david@redhat.com> (raw)
In-Reply-To: <20180523151151.6730-1-david@redhat.com>

Kernel modules that want to control how/when memory is onlined/offlined
need a proper interface to these functions. Also, for adding memory
properly, memory_block_size_bytes is required.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Pavel Tatashin <pasha.tatashin@oracle.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 drivers/base/memory.c          |  1 +
 include/linux/memory_hotplug.h |  2 ++
 mm/memory_hotplug.c            | 27 +++++++++++++++++++++++++--
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index c785e4c01b23..0a7c79cfaaf8 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -88,6 +88,7 @@ unsigned long __weak memory_block_size_bytes(void)
 {
 	return MIN_MEMORY_BLOCK_SIZE;
 }
+EXPORT_SYMBOL(memory_block_size_bytes);
 
 static unsigned long get_memory_block_size(void)
 {
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index ae53017b54df..0e3e48410415 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -97,6 +97,8 @@ extern void __online_page_increment_counters(struct page *page);
 extern void __online_page_free(struct page *page);
 
 extern int try_online_node(int nid);
+extern int online_memory_blocks(uint64_t start, uint64_t size);
+extern int offline_memory_blocks(uint64_t start, uint64_t size);
 
 extern bool memhp_auto_online;
 /* If movable_node boot option specified */
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 3a5845a33910..071976e5e7f6 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -89,12 +89,14 @@ void mem_hotplug_begin(void)
 	cpus_read_lock();
 	percpu_down_write(&mem_hotplug_lock);
 }
+EXPORT_SYMBOL(mem_hotplug_begin);
 
 void mem_hotplug_done(void)
 {
 	percpu_up_write(&mem_hotplug_lock);
 	cpus_read_unlock();
 }
+EXPORT_SYMBOL(mem_hotplug_done);
 
 /* add this memory to iomem resource */
 static struct resource *register_memory_resource(u64 start, u64 size)
@@ -995,6 +997,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
 		memory_notify(MEM_ONLINE, &arg);
 	return 0;
 }
+EXPORT_SYMBOL(online_pages);
 #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
 
 static void reset_node_present_pages(pg_data_t *pgdat)
@@ -1124,6 +1127,25 @@ static int online_memory_block(struct memory_block *mem, void *arg)
 	return device_online(&mem->dev);
 }
 
+static int offline_memory_block(struct memory_block *mem, void *arg)
+{
+	return device_offline(&mem->dev);
+}
+
+int online_memory_blocks(uint64_t start, uint64_t size)
+{
+	return walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
+				 NULL, online_memory_block);
+}
+EXPORT_SYMBOL(online_memory_blocks);
+
+int offline_memory_blocks(uint64_t start, uint64_t size)
+{
+	return walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
+				 NULL, offline_memory_block);
+}
+EXPORT_SYMBOL(offline_memory_blocks);
+
 static int mark_memory_block_driver_managed(struct memory_block *mem, void *arg)
 {
 	mem->driver_managed = true;
@@ -1212,8 +1234,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online,
 
 	/* online pages if requested */
 	if (online)
-		walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
-				  NULL, online_memory_block);
+		online_memory_blocks(start, size);
 	else if (driver_managed)
 		walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1),
 				  NULL, mark_memory_block_driver_managed);
@@ -1312,6 +1333,7 @@ bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
 	/* All pageblocks in the memory block are likely to be hot-removable */
 	return true;
 }
+EXPORT_SYMBOL(is_mem_section_removable);
 
 /*
  * Confirm all pages in a range [start, end) belong to the same zone.
@@ -1774,6 +1796,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
 {
 	return __offline_pages(start_pfn, start_pfn + nr_pages, retry_forever);
 }
+EXPORT_SYMBOL(offline_pages);
 #endif /* CONFIG_MEMORY_HOTREMOVE */
 
 /**
-- 
2.17.0

  parent reply	other threads:[~2018-05-23 15:12 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 15:11 [PATCH v1 00/10] mm: online/offline 4MB chunks controlled by device driver David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 01/10] mm: introduce and use PageOffline() David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 02/10] mm/page_ext.c: support online/offline of memory < section size David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 03/10] kasan: prepare for online/offline of different start/size David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 04/10] kdump: include PAGE_OFFLINE_MAPCOUNT_VALUE in VMCOREINFO David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 05/10] mm/memory_hotplug: limit offline_pages() to sizes we can actually handle David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 06/10] mm/memory_hotplug: onlining pages can only fail due to notifiers David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 07/10] mm/memory_hotplug: print only with DEBUG_VM in online/offline_pages() David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 08/10] mm/memory_hotplug: allow to control onlining/offlining of memory by a driver David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 09/10] mm/memory_hotplug: teach offline_pages() to not try forever David Hildenbrand
2018-05-24 14:39   ` Michal Hocko
2018-05-24 20:36     ` David Hildenbrand
2018-05-23 15:11 ` David Hildenbrand [this message]
2018-05-23 19:51   ` [PATCH v1 10/10] mm/memory_hotplug: allow online/offline memory by a kernel module Christoph Hellwig
2018-05-24  5:59     ` David Hildenbrand
2018-05-24  7:53 ` [PATCH v1 00/10] mm: online/offline 4MB chunks controlled by device driver Michal Hocko
2018-05-24  8:31   ` David Hildenbrand
2018-05-24  8:56     ` Dave Young
2018-05-24  9:14       ` David Hildenbrand
2018-05-28  8:28         ` Dave Young
2018-05-28 10:03           ` David Hildenbrand
2018-05-24  9:31     ` Michal Hocko
2018-05-24 10:45       ` David Hildenbrand
2018-05-24 12:03         ` Michal Hocko
2018-05-24 14:04           ` David Hildenbrand
2018-05-24 14:22             ` Michal Hocko
2018-05-24 21:07               ` David Hildenbrand
2018-06-11 11:53                 ` David Hildenbrand
2018-06-11 11:56                   ` Michal Hocko
2018-06-11 12:33                     ` David Hildenbrand
2018-07-16 19:48                       ` David Hildenbrand
2018-07-16 20:05                         ` Michal Hocko
2018-07-18  9:56                           ` David Hildenbrand
2018-07-18 11:23                             ` Michal Hocko
2018-07-18 13:19                 ` Michal Hocko
2018-07-18 13:39                   ` David Hildenbrand
2018-07-18 13:43                     ` Michal Hocko
2018-07-18 13:47                       ` David Hildenbrand
2018-07-18 13:56                         ` Michal Hocko
2018-05-25 15:08           ` 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=20180523151151.6730-11-david@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=pasha.tatashin@oracle.com \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    /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).