From: David Hildenbrand <david@redhat.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
David Hildenbrand <david@redhat.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Michael Ellerman <mpe@ellerman.id.au>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rashmica Gupta <rashmica.g@gmail.com>,
Balbir Singh <bsingharora@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>, Vlastimil Babka <vbabka@suse.cz>,
Dan Williams <dan.j.williams@intel.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Pavel Tatashin <pasha.tatashin@oracle.com>,
Reza Arbab <arbab@linux.vnet.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH v1 09/10] mm/memory_hotplug: teach offline_pages() to not try forever
Date: Wed, 23 May 2018 17:11:50 +0200 [thread overview]
Message-ID: <20180523151151.6730-10-david@redhat.com> (raw)
In-Reply-To: <20180523151151.6730-1-david@redhat.com>
It can easily happen that we get stuck forever trying to offline pages -
e.g. on persistent errors.
Let's add a way to change this behavior and fail fast.
This is interesting if offline_pages() is called from a driver and we
just want to find some block to offline.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rashmica Gupta <rashmica.g@gmail.com>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Pavel Tatashin <pasha.tatashin@oracle.com>
Cc: Reza Arbab <arbab@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/powerpc/platforms/powernv/memtrace.c | 2 +-
drivers/base/memory.c | 2 +-
include/linux/memory_hotplug.h | 8 ++++----
mm/memory_hotplug.c | 14 ++++++++++----
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c
index fc222a0c2ac4..8ce71f7e1558 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -110,7 +110,7 @@ static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE,
change_memblock_state);
- if (offline_pages(start_pfn, nr_pages)) {
+ if (offline_pages(start_pfn, nr_pages, true)) {
walk_memory_range(start_pfn, end_pfn, (void *)MEM_ONLINE,
change_memblock_state);
return false;
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 3b8616551561..c785e4c01b23 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -248,7 +248,7 @@ memory_block_action(struct memory_block *mem, unsigned long action)
ret = online_pages(start_pfn, nr_pages, mem->online_type);
break;
case MEM_OFFLINE:
- ret = offline_pages(start_pfn, nr_pages);
+ ret = offline_pages(start_pfn, nr_pages, true);
break;
default:
WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 497e28f5b000..ae53017b54df 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -303,7 +303,8 @@ static inline void pgdat_resize_init(struct pglist_data *pgdat) {}
extern bool is_mem_section_removable(unsigned long pfn, unsigned long nr_pages);
extern void try_offline_node(int nid);
-extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
+extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
+ bool retry_forever);
extern void remove_memory(int nid, u64 start, u64 size);
#else
@@ -315,7 +316,8 @@ static inline bool is_mem_section_removable(unsigned long pfn,
static inline void try_offline_node(int nid) {}
-static inline int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
+static inline int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
+ bool retry_forever)
{
return -EINVAL;
}
@@ -333,9 +335,7 @@ extern int arch_add_memory(int nid, u64 start, u64 size,
struct vmem_altmap *altmap, bool want_memblock);
extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
unsigned long nr_pages, struct vmem_altmap *altmap);
-extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
extern bool is_memblock_offlined(struct memory_block *mem);
-extern void remove_memory(int nid, u64 start, u64 size);
extern int sparse_add_one_section(struct pglist_data *pgdat,
unsigned long start_pfn, struct vmem_altmap *altmap);
extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms,
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 1610e214bfc8..3a5845a33910 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1633,8 +1633,8 @@ static void node_states_clear_node(int node, struct memory_notify *arg)
node_clear_state(node, N_MEMORY);
}
-static int __ref __offline_pages(unsigned long start_pfn,
- unsigned long end_pfn)
+static int __ref __offline_pages(unsigned long start_pfn, unsigned long end_pfn,
+ bool retry_forever)
{
unsigned long pfn, nr_pages;
long offlined_pages;
@@ -1686,6 +1686,10 @@ static int __ref __offline_pages(unsigned long start_pfn,
pfn = scan_movable_pages(start_pfn, end_pfn);
if (pfn) { /* We have movable pages */
ret = do_migrate_range(pfn, end_pfn);
+ if (ret && !retry_forever) {
+ ret = -EBUSY;
+ goto failed_removal;
+ }
goto repeat;
}
@@ -1752,6 +1756,7 @@ static int __ref __offline_pages(unsigned long start_pfn,
* offline_pages - offline pages in a given range (that are currently online)
* @start_pfn: start pfn of the memory range
* @nr_pages: the number of pages
+ * @retry_forever: weather to retry (possibly) forever
*
* This function tries to offline the given pages. The alignment/size that
* can be used is given by offline_nr_pages.
@@ -1764,9 +1769,10 @@ static int __ref __offline_pages(unsigned long start_pfn,
*
* Must be protected by mem_hotplug_begin() or a device_lock
*/
-int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
+int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
+ bool retry_forever)
{
- return __offline_pages(start_pfn, start_pfn + nr_pages);
+ return __offline_pages(start_pfn, start_pfn + nr_pages, retry_forever);
}
#endif /* CONFIG_MEMORY_HOTREMOVE */
--
2.17.0
next prev 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 ` David Hildenbrand [this message]
2018-05-24 14:39 ` [PATCH v1 09/10] mm/memory_hotplug: teach offline_pages() to not try forever Michal Hocko
2018-05-24 20:36 ` David Hildenbrand
2018-05-23 15:11 ` [PATCH v1 10/10] mm/memory_hotplug: allow online/offline memory by a kernel module David Hildenbrand
2018-05-23 19:51 ` 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-10-david@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=arbab@linux.vnet.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=bsingharora@gmail.com \
--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=mpe@ellerman.id.au \
--cc=pasha.tatashin@oracle.com \
--cc=paulus@samba.org \
--cc=rashmica.g@gmail.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).