Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp966993imm; Wed, 23 May 2018 08:14:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrn32aIGxChad6n4Sk8hDBoGhrM7Kcfno3v0KqxINqoPv7lUe2PxaLzFagLmzbbPFqLn6s+ X-Received: by 2002:a65:4ac8:: with SMTP id c8-v6mr2738281pgu.246.1527088462931; Wed, 23 May 2018 08:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527088462; cv=none; d=google.com; s=arc-20160816; b=eYNzwTKOKAxx2cdUoYb0TN0VpQWORjihDZqYSbrF2hnQLuQz+Zv1NNOzM5CJclu241 Uh219dELd/9dNOEhuDlYdqU4sl6iwI1K2U25UDNN/bizBFhek2+ysoJ4NpYIsST9agvR j/OIWnW5MKjZcyJgT/hWuQ1wFDNbjQBUPm4BuuEIiCrTTMC3eqn5I0yquCD2kwbScUBw cnAx9bxbidwnOMEkPhxZZ4mJMQtrZ6F60sapcWySw5ukBlPnBrmtGfOMVirpmIq7T/WV I0EyNOMQwHq/40s4QtQodDC4K1M2VE2nzatMwNeuPuRLpWyj4wXmgwRVBj6RYcaHV4Wt KSkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=EQ0p5zD1wrTQszvVXnBma/30StiYx8/b/52JX4oWfmw=; b=kRHSTNqQ/DSvwpKDVIzzYITJoivmHnTQJHFr4gt0DflMdZpFNsPoRwdkgSOK6VKg+R waXjr7HFTrlHM/z7/YZBZrI32lXc8d6okpqm7W9DxIhE2x0ch8g6+I71bC8FWHcDwE/U o/FUxSdJDWA5dP6MPxcewPyWZgtfymo5yuaHdJTkxs102qhTRdUJCbjSMb8E7G9R5b7f MV7uffuWW6AIVfQcq6DUvqjtflJ+AohIDL1RVEJN6WSYzKfuYKpijdW6wZKNDVpSAn59 ZxHEt1mCvri+WSJAI3MDKVqrK0SDFK/FGclDoelYFp/pmwuc/aG4r8OXhna43oeZHVo3 ITXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13-v6si18503379plp.128.2018.05.23.08.14.05; Wed, 23 May 2018 08:14:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933534AbeEWPM0 (ORCPT + 99 others); Wed, 23 May 2018 11:12:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45310 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933475AbeEWPMV (ORCPT ); Wed, 23 May 2018 11:12:21 -0400 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 0F45940BC04A; Wed, 23 May 2018 15:12:21 +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 32C9E10C564A; Wed, 23 May 2018 15:12:19 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, David Hildenbrand , Andrew Morton , Vlastimil Babka , Michal Hocko , Dan Williams , Joonsoo Kim , Greg Kroah-Hartman , Pavel Tatashin , Reza Arbab , Thomas Gleixner Subject: [PATCH v1 05/10] mm/memory_hotplug: limit offline_pages() to sizes we can actually handle Date: Wed, 23 May 2018 17:11:46 +0200 Message-Id: <20180523151151.6730-6-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.7]); Wed, 23 May 2018 15:12:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 23 May 2018 15:12:21 +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:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have to take care of MAX_ORDER. Page blocks might contain references to the next page block. So sometimes a page block cannot be offlined independently. E.g. on x86: page block size is 2MB, MAX_ORDER -1 (10) allows 4MB allocations. E.g. a buddy page could either overlap at the beginning or the end of the range to offline. While the end case could be handled easily (shrink the buddy page), overlaps at the beginning are hard to handle (unknown page order). Let document offline_pages() while at it. Cc: Andrew Morton Cc: Vlastimil Babka Cc: Michal Hocko Cc: Dan Williams Cc: Joonsoo Kim Cc: Greg Kroah-Hartman Cc: Pavel Tatashin Cc: Reza Arbab Cc: Thomas Gleixner Signed-off-by: David Hildenbrand --- include/linux/memory_hotplug.h | 6 ++++++ mm/memory_hotplug.c | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index e0e49b5b1ee1..d71829d54360 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -294,6 +294,12 @@ static inline void pgdat_resize_init(struct pglist_data *pgdat) {} #endif /* !(CONFIG_MEMORY_HOTPLUG || CONFIG_DEFERRED_STRUCT_PAGE_INIT) */ #ifdef CONFIG_MEMORY_HOTREMOVE +/* + * Isolation and offlining code cannot deal with pages (e.g. buddy) + * overlapping with the range to be offlined yet. + */ +#define offline_nr_pages max((unsigned long)pageblock_nr_pages, \ + (unsigned long)MAX_ORDER_NR_PAGES) extern bool is_mem_section_removable(unsigned long pfn, unsigned long nr_pages); extern void try_offline_node(int nid); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7f7bd2acb55b..c971295a1100 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1599,10 +1599,9 @@ static int __ref __offline_pages(unsigned long start_pfn, struct zone *zone; struct memory_notify arg; - /* at least, alignment against pageblock is necessary */ - if (!IS_ALIGNED(start_pfn, pageblock_nr_pages)) + if (!IS_ALIGNED(start_pfn, offline_nr_pages)) return -EINVAL; - if (!IS_ALIGNED(end_pfn, pageblock_nr_pages)) + if (!IS_ALIGNED(end_pfn, offline_nr_pages)) return -EINVAL; /* This makes hotplug much easier...and readable. we assume this for now. .*/ @@ -1700,7 +1699,22 @@ static int __ref __offline_pages(unsigned long start_pfn, return ret; } -/* Must be protected by mem_hotplug_begin() or a device_lock */ +/** + * 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 + * + * This function tries to offline the given pages. The alignment/size that + * can be used is given by offline_nr_pages. + * + * Returns 0 if sucessful, -EBUSY if the pages cannot be offlined and + * -EINVAL if start_pfn/nr_pages is not properly aligned or not in a zone. + * -EINTR is returned if interrupted by a signal. + * + * Bad things will happen if pages in the range are already offline. + * + * Must be protected by mem_hotplug_begin() or a device_lock + */ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) { return __offline_pages(start_pfn, start_pfn + nr_pages); -- 2.17.0