Received: by 10.192.165.148 with SMTP id m20csp3578418imm; Mon, 30 Apr 2018 02:44:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqOVdIJ3CUSxwdTyXSK42gVpN1c3tsbZ+DJR3kQW3yYqfqvixpE3GeH0dLVso2djC/RY5aC X-Received: by 10.98.69.137 with SMTP id n9mr10163533pfi.158.1525081487506; Mon, 30 Apr 2018 02:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525081487; cv=none; d=google.com; s=arc-20160816; b=hC6ErtneB/Cn2aw49yT5R3OaxAY2k1SZYDNmFHu8l36bp6qrfbpgNT8BBSKrprlrsL U6BKJC9F5jimm7jA7M7UxmCCfH5D5XrzMgCNQvYRPmGLqAznC2bYm1N3H+1CSdDtzc/e LaaOnY2qYlAjeeWA8DxSqH4Rz+9V1vJKA/aiaB6BYn1aLBVPB4tHFHAe9afspRFvYRXn XtB0fWwhK8dHVQTWsyCfyEmD8+NbpPMgWJ1rpRS3Fe361sZoeR88ZEbQMuJXD0+GoZAI muQr4Lzdh05zAtiRA4XshVQGOwxNjoktBI14b6i/q/v15j/FcTZpPuxr9qYf5o9wKoG1 wurg== 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=vI1G9VZx6NLsaFmPzM0/LJ2r6OYZNVPY4e/GoJIqA18=; b=mT2tXOSZYFu2n9wP0JAQSUHUMdBBBDfU37dapJau/pRU1bfsY0CWHQ0QBXawktX4c5 /64rKqe4PUYyQPPlzXaoJOINSJ1thAlIcLDueOZ3papRIF4e6pFMTEuitb7sBJuxjxkk 0o37ec0gXsfm6aGvpeaojvYDzKFDjLoiwq0Q32s4w9GoQQL0algSH6EFFu7cFU3RBdo7 kqxnU6KdoaZ9Bsd/GcB6z/WqyvpQ1a1dwHqF6c/KgAScJX76+37ltsD2OFXpMePGeUGJ uvUys7J71mg0NJ04j2ICL+KbnuIrfbZXT9hdapXqr4Um66ScYUsxQHmwD1LzPiXMokOB SWYw== 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 n3-v6si3036410pgp.344.2018.04.30.02.44.33; Mon, 30 Apr 2018 02:44:47 -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 S1753265AbeD3Jm4 (ORCPT + 99 others); Mon, 30 Apr 2018 05:42:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36274 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753081AbeD3Jmv (ORCPT ); Mon, 30 Apr 2018 05:42:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AC788182D1C; Mon, 30 Apr 2018 09:42:51 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-122.ams2.redhat.com [10.36.117.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B0092023499; Mon, 30 Apr 2018 09:42:49 +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 RCFv2 3/7] mm/memory_hotplug: limit offline_pages() to sizes we can actually handle Date: Mon, 30 Apr 2018 11:42:32 +0200 Message-Id: <20180430094236.29056-4-david@redhat.com> In-Reply-To: <20180430094236.29056-1-david@redhat.com> References: <20180430094236.29056-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 30 Apr 2018 09:42:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 30 Apr 2018 09:42:51 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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.14.3