From patchwork Wed May 23 15:11:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10421767 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 BB1586032A for ; Wed, 23 May 2018 15:13:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A946D28C68 for ; Wed, 23 May 2018 15:13:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A783A28F4C; Wed, 23 May 2018 15:13:55 +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 6A82829093 for ; Wed, 23 May 2018 15:12:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E35F6B0003; Wed, 23 May 2018 11:12:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 06D0E6B0006; Wed, 23 May 2018 11:12:36 -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 E57406B000C; Wed, 23 May 2018 11:12:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id B0E616B0003 for ; Wed, 23 May 2018 11:12:35 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id j33-v6so21239538qtc.18 for ; Wed, 23 May 2018 08:12:35 -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=Qwwj2CNiUzK76G8PXIM9QFTz93z0/sWlkC4fahy3Glg=; b=jmd/Xo+7MDUNlPRSg6kpGxdTYdZxLHne6VJS/XAacQnf8QGf1kGamEFgsjK22CLFfQ CdVN+4gpyS0oomZ7Y0Y9TwgmJxX9gwPfuHo9WqZ3q6ec8SEH6fWccxGJsgcSEk1yTd4t 3gQBbt2qPhkvn6v5DKbpcIT+nhVNU+v4mqCcSOab3jNvA6q0q2ljmToALSpLo5LZRImz Kdh404HsQ7BTrkJgzx0nxsIpXn3y8h0IhsKu2j8dXp99yPqUed5YzThv9itGOnHDQDCQ FgboJTnPYW4N9BMLzc5w48QNlWHS2Kc4YRCvF8mosYV2ObfJWQcTxAM/dEnqEHtPSaW+ iV+A== 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: ALKqPweR6hZjp1lmC9zulrmGxznqnSz1BzUR9hI9JBV3KvDYNQS5gW3P 1R3LQS0kTCCwkgIkGy2UkcRi9y4Zk1nTp7knzIhXCdm05nzO+yhIbSu2CnSTrVa5IQ812h9CcjP NsKLy3Vrgnj0YuydbTgKVnhiTZoqE2WJFrBxXO8u1JgFlDWG9IgT8DjwhZ1gf7LAw4Q== X-Received: by 2002:ac8:3138:: with SMTP id g53-v6mr3171568qtb.338.1527088355508; Wed, 23 May 2018 08:12:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLMblRmJsotrrLQIZO1B7CUpDZ6B90RMg0BBKOnjFK6pclvkX4qicvk7V/uTdhZb65PnQbJ X-Received: by 2002:ac8:3138:: with SMTP id g53-v6mr3171525qtb.338.1527088354958; Wed, 23 May 2018 08:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527088354; cv=none; d=google.com; s=arc-20160816; b=nH4N2pR/9MMbw3f4BHj2savaonWgm5itqmXijMxlT+Zsiz1xg5qad58+BtTjRU5jZg 7Rgn9mahG8wL9aWhwJScERUpgPx+dr/Me05Pcr3eluiEjDwmela7u8+DM9nEk+W9iNSQ WgfjqI8lIGLFglrGe95gkWKjD2Sd9uPY9zuiJkknwc5FD55+IgWx4a0V9m6NVipyFxWp ldR0F6TcFTNv0jW+o70iYLZCGth4mUJV04n4QNK+eYTE0h9jtER9v/nw3qX4tcbvPFzg +rviWZByDPBC9hG8cj/VtLwJq/h4UinGh1WTpOvX1k+yiwW+doia0d1qR3rrCtT6fCKW pMkg== 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=Qwwj2CNiUzK76G8PXIM9QFTz93z0/sWlkC4fahy3Glg=; b=nJscdDFLTq00sFCyKt4APg3hAOg9P6kuIAQ7adrV/mZK6nnZ7HZjDp9eTrXhAJabc/ 8tcaR08amwNQhKgZZRqbyBLg2W3S6Bi+aZf/Rh5pCWM8kgDkY4+Kr0x6ufS3sz3kSIL8 YBSwvg/LnakYNOiATNwRXvR85+1TcZe7IkvpDencTQ7vO1xq1hb6TkHz04dyBRnhsfLI aVaDNkp4HvErcW3DOrNVOKSxrCaP+vDBXsbQpgS72xALXXc+QgZrDHq01962kQzzpiss lfGBp/yzGs6A4/aQE51cEGEV2pGri5q6McT2i/UgFo6rdL00DT0IllG0xR2/+SLprf64 yrqQ== 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 b32-v6si5402465qta.275.2018.05.23.08.12.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 08:12:34 -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 9F92F818BAF8; Wed, 23 May 2018 15:12:34 +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 A418910C564A; Wed, 23 May 2018 15:12:30 +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 v1 10/10] mm/memory_hotplug: allow online/offline memory by a kernel module Date: Wed, 23 May 2018 17:11:51 +0200 Message-Id: <20180523151151.6730-11-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.8]); Wed, 23 May 2018 15:12:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 23 May 2018 15:12:34 +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 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 3a5845a33910..071976e5e7f6 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) @@ -995,6 +997,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ memory_notify(MEM_ONLINE, &arg); return 0; } +EXPORT_SYMBOL(online_pages); #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ static void reset_node_present_pages(pg_data_t *pgdat) @@ -1124,6 +1127,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; @@ -1212,8 +1234,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); @@ -1312,6 +1333,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. @@ -1774,6 +1796,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 */ /**