From patchwork Mon Dec 3 23:35:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10710901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7389413BF for ; Mon, 3 Dec 2018 23:36:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6267129267 for ; Mon, 3 Dec 2018 23:36:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54B3C2B222; Mon, 3 Dec 2018 23:36:10 +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 9A0F329267 for ; Mon, 3 Dec 2018 23:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CA6B6B6BB1; Mon, 3 Dec 2018 18:36:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 650CB6B6BB2; Mon, 3 Dec 2018 18:36:08 -0500 (EST) 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 4F1F86B6BB3; Mon, 3 Dec 2018 18:36:08 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 23AA56B6BB1 for ; Mon, 3 Dec 2018 18:36:08 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id u32so15365478qte.1 for ; Mon, 03 Dec 2018 15:36:08 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=zRntr0v24OrOu9F3uW12kta4v58xqWX3PVG2df0NLbw=; b=q9cTE/2xvKnP8aNwJvQMCbhUclbjV1EehrQZ5arIxju8Xxyh6/cwoXCnwCygI2cDnq C70xbg+AikvjZ+dQJrpt8xMfitRLFv9TekKnd0smCaVuCcXYcfqY4mPWigMQbm5ziOpy jEz8xUOSjBz0Q+JkQFUYSatNO5NbNwTiGRxrG/kL7XvhIaIervJP96HUbof3ihDt5y3X TGuMVxCPcY3yUQBcU1IIQ0xR1fwMbjmErdEzr/VtNGtwun7TkTEv12JsI+BvdS0OeyUy +lyh+ZSAUu7v6M8Ixuqa+mfonYRwaXpLyZXOMco8cGNQRXjJWxR49GOImuYyVxM0gsI1 8Xjw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWYPO28MKxK4SLE4V/tXSx/qHC4PROyzqNrFjS9JonDG0feAaGzh tFRIr0BARvIsPOProlA1fKyb5pxkdIPHr9oHlYcXuh1NkTA3Ciwzwoz6UJewAhBnKmUoSDRRkHR ibAdtDgRFy/Asn1/+ahspOZcDm0Zl1NYKoXbpb2tegtfr5FLGknDxE1tFDrDMdIYBsg== X-Received: by 2002:a37:2f84:: with SMTP id v126mr16295805qkh.254.1543880167877; Mon, 03 Dec 2018 15:36:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/XN3nM0QC08Zn5+t6RLGF2RVGLyRUcVuykXioi2+8uRRXeCHNMBLbkt0VDD2ws/ewmQM7D9 X-Received: by 2002:a37:2f84:: with SMTP id v126mr16295770qkh.254.1543880166776; Mon, 03 Dec 2018 15:36:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543880166; cv=none; d=google.com; s=arc-20160816; b=0nfYyi2UlmLeqRVvbgHhdSrU81Rz6KgRPVqXwvmckYrUxKUPcIGuzrjEcHeEIZKlfO h7cLnO7kAysQcFhZqqHzqbHAzrFxSIz0Gw9738j9xEL76VzZe6TD0HpbdQL3+eVIbd4b TJ+AumiCN+BIYRwbwyrzmBfP3cwIJXWoLo5wkrNYG6lQKJ+D6TyyBlNasw2+zV3CjDH7 98zuaW373HRGM6glU5nrQxr/3+vO8asdi2yIRSLqwNG76SvTkoczqlkW2NgX5yNF+Z4A SltQLW4mJyp+huYzMZstONIe+aJSUAn6aG/ySuP9Fg81po6LtLESPsfyp5bmrJxOPOFc b2Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=zRntr0v24OrOu9F3uW12kta4v58xqWX3PVG2df0NLbw=; b=V1P+AMATXvu6rEzSqdK9hVleDsIkVHoP9whPnMNxyboa0yJlE/uBS5CWgZW+Pr3XMG oSM/uRT3M1FfVegp6SGwg5F37DimCCiwCjw3P+9lTCxY3G9zbAxWC8bUV5FgpvENfjGv QYquY3OQMifsO3XE9Vwn1f9QhE7IN+LitW1jPGB+g9KnBg3rJY6JixjeQSlOisIMq3n/ Ht7+pAaUziw8MfpFEGzM3uVZ3GNpfEpZTF4bPurPV3BJ3Ff9qyWmU8BKBXhk9/vYQyWW j1WMMgvHQ1vVAD39P0xhYIn4Rz0JIcCUITsJSB38sx9EQFHX12uk5QiKv6HVTbobwrLj Z2XQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 35si6223263qvm.133.2018.12.03.15.36.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 15:36:06 -0800 (PST) Received-SPF: pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A90E4312E9FB; Mon, 3 Dec 2018 23:36:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-188.rdu2.redhat.com [10.10.120.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42AE2600C7; Mon, 3 Dec 2018 23:36:02 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "Rafael J . Wysocki" , Ross Zwisler , Dan Williams , Dave Hansen , Haggai Eran , Balbir Singh , "Aneesh Kumar K . V" , Benjamin Herrenschmidt , Felix Kuehling , Philip Yang , =?utf-8?q?Christian_K=C3=B6nig?= , Paul Blinzer , Logan Gunthorpe , John Hubbard , Ralph Campbell , Michal Hocko , Jonathan Cameron , Mark Hairgrove , Vivek Kini , Mel Gorman , Dave Airlie , Ben Skeggs , Andrea Arcangeli Subject: [RFC PATCH 07/14] mm/hms: register main memory with heterogenenous memory system Date: Mon, 3 Dec 2018 18:35:02 -0500 Message-Id: <20181203233509.20671-8-jglisse@redhat.com> In-Reply-To: <20181203233509.20671-1-jglisse@redhat.com> References: <20181203233509.20671-1-jglisse@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 03 Dec 2018 23:36:06 +0000 (UTC) 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 From: Jérôme Glisse Register main memory as target under HMS scheme. Memory is registered per node (one target device per node). We also create a default link to connect main memory and CPU that are in the same node. For details see Documentation/vm/hms.rst. This is done to allow application to use one API for regular memory or device memory. Signed-off-by: Jérôme Glisse Cc: Rafael J. Wysocki Cc: Ross Zwisler Cc: Dan Williams Cc: Dave Hansen Cc: Haggai Eran Cc: Balbir Singh Cc: Aneesh Kumar K.V Cc: Benjamin Herrenschmidt Cc: Felix Kuehling Cc: Philip Yang Cc: Christian König Cc: Paul Blinzer Cc: Logan Gunthorpe Cc: John Hubbard Cc: Ralph Campbell Cc: Michal Hocko Cc: Jonathan Cameron Cc: Mark Hairgrove Cc: Vivek Kini Cc: Mel Gorman Cc: Dave Airlie Cc: Ben Skeggs Cc: Andrea Arcangeli --- drivers/base/node.c | 65 +++++++++++++++++++++++++++++++++++++++++++- include/linux/node.h | 6 ++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 86d6cd92ce3d..05621ba3cf13 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -323,6 +323,11 @@ static int register_node(struct node *node, int num) if (error) put_device(&node->dev); else { + hms_link_register(&node->link, &node->dev, 0); + hms_target_register(&node->target, &node->dev, + num, NULL, 0, 0); + hms_link_target(node->link, node->target); + hugetlb_register_node(node); compaction_register_node(node); @@ -339,6 +344,9 @@ static int register_node(struct node *node, int num) */ void unregister_node(struct node *node) { + hms_target_unregister(&node->target); + hms_link_unregister(&node->link); + hugetlb_unregister_node(node); /* no-op, if memoryless node */ device_unregister(&node->dev); @@ -415,6 +423,9 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr); sect_end_pfn += PAGES_PER_SECTION - 1; for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { +#if defined(CONFIG_HMS) + unsigned long size = PAGE_SIZE; +#endif int page_nid; /* @@ -445,9 +456,35 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) if (ret) return ret; - return sysfs_create_link_nowarn(&mem_blk->dev.kobj, + ret = sysfs_create_link_nowarn(&mem_blk->dev.kobj, &node_devices[nid]->dev.kobj, kobject_name(&node_devices[nid]->dev.kobj)); + if (ret) + return ret; + +#if defined(CONFIG_HMS) + /* + * Right now here i do not see any easier way to get the size + * in bytes of valid memory that is added to this node. + */ + for (++pfn; pfn <= sect_end_pfn; pfn++) { + if (!pfn_present(pfn)) { + pfn = round_down(pfn + PAGES_PER_SECTION, + PAGES_PER_SECTION) - 1; + continue; + } + page_nid = get_nid_for_pfn(pfn); + if (page_nid < 0) + continue; + if (page_nid != nid) + continue; + size += PAGE_SIZE; + } + + hms_target_add_memory(node_devices[nid]->target, size); +#endif + + return 0; } /* mem section does not span the specified node */ return 0; @@ -471,6 +508,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, sect_start_pfn = section_nr_to_pfn(phys_index); sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { +#if defined(CONFIG_HMS) + unsigned long size = 0; + int page_nid; +#endif int nid; nid = get_nid_for_pfn(pfn); @@ -484,6 +525,28 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, kobject_name(&mem_blk->dev.kobj)); sysfs_remove_link(&mem_blk->dev.kobj, kobject_name(&node_devices[nid]->dev.kobj)); + +#if defined(CONFIG_HMS) + /* + * Right now here i do not see any easier way to get the size + * in bytes of valid memory that is added to this node. + */ + for (; pfn <= sect_end_pfn; pfn++) { + if (!pfn_present(pfn)) { + pfn = round_down(pfn + PAGES_PER_SECTION, + PAGES_PER_SECTION) - 1; + continue; + } + page_nid = get_nid_for_pfn(pfn); + if (page_nid < 0) + continue; + if (page_nid != nid) + break; + size += PAGE_SIZE; + } + + hms_target_remove_memory(node_devices[nid]->target, size); +#endif } NODEMASK_FREE(unlinked_nodes); return 0; diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..297b01d3c1ed 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -15,6 +15,7 @@ #ifndef _LINUX_NODE_H_ #define _LINUX_NODE_H_ +#include #include #include #include @@ -22,6 +23,11 @@ struct node { struct device dev; +#if defined(CONFIG_HMS) + struct hms_target *target; + struct hms_link *link; +#endif + #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) struct work_struct node_work; #endif