From patchwork Wed May 23 15:11:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10421765 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E5FB160224 for ; Wed, 23 May 2018 15:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6229289D4 for ; Wed, 23 May 2018 15:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4AD728F5D; Wed, 23 May 2018 15:13:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA07229182 for ; Wed, 23 May 2018 15:12:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B2516B0007; Wed, 23 May 2018 11:12:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0457C6B000D; Wed, 23 May 2018 11:12:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E03CA6B0274; Wed, 23 May 2018 11:12:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by kanga.kvack.org (Postfix) with ESMTP id B14F96B0007 for ; Wed, 23 May 2018 11:12:31 -0400 (EDT) Received: by mail-qk0-f197.google.com with SMTP id o97-v6so11912363qkh.14 for ; Wed, 23 May 2018 08:12:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=doC6gfdj9p4gVcFWGLWwm4nwujXCeDS2QVJuzrm58fs=; b=eqHxJwGIFGT1IYZBz3wYZiSELByA+bu6oQYPICgDb+Btdj3LcBN8Z2TmnDyuroSZn6 dhr7fXrXIFOz3l9bsxmKfx/r6Op+t84606zZQ0jHMfI5tlSy0cM46B9WqGNSVDxvYUNo 6wN1ojqBtg81EL2FuCuSQdLi55IYd6ljxAH8uZS0pIiPmAuHEsYw3aYgKwKzbHJVHUWn 3ifQteIUoxvnXvYnl1vC9HEANKEiXDsMjtRCDPxlKKZL2/xbMzEn60pxyYXZTSjv/0Ma UCxpkyve5Iv9HCMVWyPmy5AYFq6LMuM39p4P0TK3eQCbG3Xgi8+xEpw6k8hJv08yS201 gvYg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ALKqPwfdrBvuKZlQV7UE5R+NcYFtGxD0PorIwW5bbtlirIePUfqgXrUw 0slxGC+19Qx/nRTkKhibsw4F42DnBfJt5Q0VuASu8I9GQtdzRw7uygrw8vHod+WU3FDZaYor3pG ukUiiZiBocI9h3FLHcJCpWnramrDdTZuTYm5BNVY1Lm4HC++WmnNSsAnLdUyMCnJO1w== X-Received: by 2002:a37:5cc:: with SMTP id 195-v6mr2958057qkf.101.1527088351463; Wed, 23 May 2018 08:12:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrXfVRN5u6E9HDbUI5I5pZI02CSDB1LskkxzV+ZPfIXrFCNhzEvgDaqpI04VloQ4JPPcJuG X-Received: by 2002:a37:5cc:: with SMTP id 195-v6mr2958009qkf.101.1527088350772; Wed, 23 May 2018 08:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527088350; cv=none; d=google.com; s=arc-20160816; b=xNWnbNC9f9LYx049E2y2oUd5JJmxt+X0Zcn/YkCw+Z5fe3PeYN+nF/pOjSFdMITveY kFi5N9hBGyTwCRmzKSzRhaLgCHh2oNSPzPO9CrYzy2hvwCcO8qEvcW2bP5PJPeKVzE8y rGAlhxXZAwnQCItn4HfTjxWD06oJ9h0LPzUrvDa9/6G1NQ55JRt5zmtk+vs0IMOo5uPH WpmdXWSWElGxUVQhaj/HXZgP+Kwz7HGVY3ap7Na39VU+eR8z4+9CLoJqd0OzkOndyuzh bbowdVb1eZtNNGGn8fNlM619VE9SHYbn2dgWY2Dki4d8Oumoo1aBMl77HzxOZwRe84mT VhtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=doC6gfdj9p4gVcFWGLWwm4nwujXCeDS2QVJuzrm58fs=; b=ZTXzRHUppCABjWr1DYqpmjRJrjEq3oZ9i7OqUPqP6qGg9qEPeSgrE58wwPtBgvx4Ww saOdGlKHtaP+UjbPPg6/RJB5UfhKTfFCNmK4zxlgb7B/TZCNw3wWkTE6qidBYWFfLeX/ XMKtPPAP8kyiPTuHtKLGBMhktaiBO42ZVJePMXCHW+mj7BpsIN1r7doKX8GlqH7sI85D tee2J+8IBCXhdh720JLfRdP2uW2ru3FURgYexUWIzUgCsyQYtBw2hrh7ktMcOiZnzH5P YKFT479sPAAWTOr+WV1LwW6SmkBGbexLBDetTaQUG91gVLFKwiYpvtPa/mpb1lzntQdU YbVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id q1-v6si10280279qti.323.2018.05.23.08.12.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 08:12:30 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60E7DBB405; Wed, 23 May 2018 15:12:30 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-112.ams2.redhat.com [10.36.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id D765010C564A; Wed, 23 May 2018 15:12:27 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, David Hildenbrand , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Greg Kroah-Hartman , Rashmica Gupta , Balbir Singh , Andrew Morton , Michal Hocko , Vlastimil Babka , Dan Williams , Joonsoo Kim , Pavel Tatashin , Reza Arbab , Thomas Gleixner Subject: [PATCH v1 09/10] mm/memory_hotplug: teach offline_pages() to not try forever Date: Wed, 23 May 2018 17:11:50 +0200 Message-Id: <20180523151151.6730-10-david@redhat.com> In-Reply-To: <20180523151151.6730-1-david@redhat.com> References: <20180523151151.6730-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 23 May 2018 15:12:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 23 May 2018 15:12:30 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Paul Mackerras Cc: Michael Ellerman Cc: Greg Kroah-Hartman Cc: Rashmica Gupta Cc: Balbir Singh Cc: Andrew Morton Cc: Michal Hocko Cc: Vlastimil Babka Cc: Dan Williams Cc: Joonsoo Kim Cc: Pavel Tatashin Cc: Reza Arbab Cc: Thomas Gleixner Signed-off-by: David Hildenbrand --- 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 */