Received: by 10.192.165.148 with SMTP id m20csp3578617imm; Mon, 30 Apr 2018 02:45:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpuX9qlQU9ypDcN8LSOg5OURA27uvWDcwxF4OTsmAiymZS303TJDTyJb6TSr9AeY6D5m4pF X-Received: by 2002:a17:902:aa04:: with SMTP id be4-v6mr11814178plb.20.1525081501104; Mon, 30 Apr 2018 02:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525081501; cv=none; d=google.com; s=arc-20160816; b=n9TD5TkqTNFzjgRQgcNYSIt1J4cDbZS2kwg22I5wg4GfeaLFKvQHOAJ0IqAaHBeyX/ bJSoSk8uSg4jjzCN/yJJ+uypYUwQJ6g1pezEmydiZdnMqqnrK37J2V9+UWSglBbflwni KtsWf4CgqDOCIblxOD4T6q0n107vaFyA65np8S16GbPCkYBS3olYUOwmF6hmcJ0iyXmC k+xYm/PLSH8x7y5VaYnQF+ferxbrM2YAX5KTofdIxO7ZMene8Kj5//d2BYslZ+gBU8/M m8ZGA/EwRL8xlRnXxF5/RMvq3o4YiE4cbx3GZZeeZajKdhMjzBrqqYX/7TygN9EAmY2D KwKQ== 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=k/kevtbN8t5jjZysacuzGBelZ/sEJRGUtgakmDP3mIA=; b=v5HyoQfF/ZJ1/nTcuxGnOgkyjuCX75DWVxAJkRWGVJGGFgIwqhCCxBJw+j2+PWRkuM nP/BqZuMlmYXZAE53I/C0dF5wKkqKsLJ0H7KqX+/fDrzqZhm6ND9qiz4/dsPVMwKKfZn gIl4sylt7yL69EgJGtI2Py0pem5qZdVKyjvXCoMp9w5M1I6pGlMeDe6pVwFbC6t33rLE 9X/dvV3uHhIHLRJ++e6G8QchcUnO75IXQd5tml4F/9BvhG5dhW9C3V7vZxdtmxX2miYU VdOtA9S17rAW7fPd6UApF6w53oui93op5oGaxlimoyH5QB2N32j5r/XmH/F5D1vO6csD 7H4Q== 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 d6-v6si5861163pgc.140.2018.04.30.02.44.47; Mon, 30 Apr 2018 02:45:01 -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 S1753482AbeD3JnK (ORCPT + 99 others); Mon, 30 Apr 2018 05:43:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43088 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753381AbeD3JnB (ORCPT ); Mon, 30 Apr 2018 05:43:01 -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 0231942BDF11; Mon, 30 Apr 2018 09:43:01 +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 35F512023499; Mon, 30 Apr 2018 09:42:59 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, David Hildenbrand , Greg Kroah-Hartman , Andrew Morton , Vlastimil Babka , Michal Hocko , Dan Williams , Pavel Tatashin , Joonsoo Kim , Thomas Gleixner Subject: [PATCH RCFv2 7/7] mm/memory_hotplug: allow online/offline memory by a kernel module Date: Mon, 30 Apr 2018 11:42:36 +0200 Message-Id: <20180430094236.29056-8-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.7]); Mon, 30 Apr 2018 09:43:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 30 Apr 2018 09:43:01 +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 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 Cc: Andrew Morton Cc: Vlastimil Babka Cc: Michal Hocko Cc: Dan Williams Cc: Pavel Tatashin Cc: Joonsoo Kim Cc: Thomas Gleixner Signed-off-by: David Hildenbrand --- 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 c47cc68341fc..849bf0543fb1 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) @@ -980,6 +982,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ memory_notify(MEM_CANCEL_ONLINE, &arg); return ret; } +EXPORT_SYMBOL(online_pages); #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ static void reset_node_present_pages(pg_data_t *pgdat) @@ -1109,6 +1112,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; @@ -1197,8 +1219,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); @@ -1297,6 +1318,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. @@ -1759,6 +1781,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.14.3