From patchwork Tue Apr 11 17:42:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 9675879 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 9E11860231 for ; Tue, 11 Apr 2017 17:43:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9654D28538 for ; Tue, 11 Apr 2017 17:43:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B53228598; Tue, 11 Apr 2017 17:43:09 +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=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 477E428538 for ; Tue, 11 Apr 2017 17:43:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3639C20080F0A; Tue, 11 Apr 2017 10:43:09 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1C0C92095C3C9 for ; Tue, 11 Apr 2017 10:43:08 -0700 (PDT) Received: by mail-pg0-x243.google.com with SMTP id 79so696145pgf.0 for ; Tue, 11 Apr 2017 10:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nHZ416Y4hyhuktNm3QTm7VPfAHHX5tX8H9mQKUmjZ4c=; b=n93bXK0TlBuY1OK8CGbd15FC3FKpFaUf03hotrTmUkjG5WR/RxM2kCfDVZ78gmQm4D cHVP0tK74cmxloeLUGkV20aKLqKhsH83K5Vpj3In+OmKzph/HEgCESnvI+dF4hOOZPz+ i+POZEtvwD7BoGCjJjlQXeNVK8Eh3z+THTrg8O5YmV1qvCaaf+3gFICBk+y12FucdFhg bdPTJFXQLycwwPC9KCswXitf/aU1NOSdpIADFbOtwqAi43XuLCIJ+dmy/umPzKCUHWrU QcUweMf18YDiqO75xvbDXYVPbV15M+EqVyzO/bJPDfdvRxBHHIlXLZ5Js28azPW6bJ9h M5/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nHZ416Y4hyhuktNm3QTm7VPfAHHX5tX8H9mQKUmjZ4c=; b=FsaSL1Pv6YmTwHuzVjqLhwqCxohp7ohc3RswZxhVxa1Eiws5+F79kIc/9cGm0uY4Uw c34Rzap+crl4PHNtCCerKgN/aukAOhIYrrGEEFh2vTJL8AJdPjRGBgkh3sDQMyXTkCAU QfHWm5AcEUSTIZ6sH94OGqCdpUvmMat661IHN/veSFo+Gb+Jd28Y8rA2zSIUtdlNNwJU s1hKeUzsVabkN/S7mVYBOMT78iAwiwdpsRTGjsydmZo10SgzcigYOq9dGbyQnnxJcAOP 1sP/aAgtX6E4eEbF1qoYg8DGvB1t9SIyi85rXh/6ApxWL1SCC1jDlpKFezxzhkMoMVuW 1rNg== X-Gm-Message-State: AFeK/H2dwYK4bzGXVH+osgevwtl5p2ivo6guDYLTSitb6RZV3Ua89LWf1O5iHOLoZyzj+g== X-Received: by 10.98.130.70 with SMTP id w67mr61491344pfd.173.1491932587811; Tue, 11 Apr 2017 10:43:07 -0700 (PDT) Received: from localhost.localdomain ([103.57.0.128]) by smtp.gmail.com with ESMTPSA id r185sm20182582pfr.72.2017.04.11.10.43.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 10:43:07 -0700 (PDT) From: Oliver O'Halloran To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 5/9] powerpc/vmemmap: Add altmap support Date: Wed, 12 Apr 2017 03:42:29 +1000 Message-Id: <20170411174233.21902-6-oohall@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170411174233.21902-1-oohall@gmail.com> References: <20170411174233.21902-1-oohall@gmail.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bsingharora@gmail.com, arbab@linux.vnet.ibm.com, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Adds support to powerpc for the altmap feature of ZONE_DEVICE memory. An altmap is a driver provided region that is used to provide the backing storage for the struct pages of ZONE_DEVICE memory. In situations where large amount of ZONE_DEVICE memory is being added to the system the altmap reduces pressure on main system memory by allowing the mm/ metadata to be stored on the device itself rather in main memory. Signed-off-by: Oliver O'Halloran Reviewed-by: Balbir Singh --- arch/powerpc/mm/init_64.c | 20 +++++++++++++++----- arch/powerpc/mm/mem.c | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c index f8124edb6ffa..225fbb8034e6 100644 --- a/arch/powerpc/mm/init_64.c +++ b/arch/powerpc/mm/init_64.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -171,13 +172,17 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node) pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node); for (; start < end; start += page_size) { + struct vmem_altmap *altmap; void *p; int rc; if (vmemmap_populated(start, page_size)) continue; - p = vmemmap_alloc_block(page_size, node); + /* altmap lookups only work at section boundaries */ + altmap = to_vmem_altmap(SECTION_ALIGN_DOWN(start)); + + p = __vmemmap_alloc_block_buf(page_size, node, altmap); if (!p) return -ENOMEM; @@ -241,9 +246,10 @@ void __ref vmemmap_free(unsigned long start, unsigned long end) pr_debug("vmemmap_free %lx...%lx\n", start, end); for (; start < end; start += page_size) { - struct page *page = pfn_to_page(addr >> PAGE_SHIFT); - unsigned int nr_pages; - unsigned long addr; + unsigned long nr_pages, addr; + struct vmem_altmap *altmap; + struct page *section_base; + struct page *page; /* * the section has already be marked as invalid, so @@ -258,9 +264,13 @@ void __ref vmemmap_free(unsigned long start, unsigned long end) continue; page = pfn_to_page(addr >> PAGE_SHIFT); + section_base = pfn_to_page(vmemmap_section_start(start)); nr_pages = 1 << page_order; - if (PageReserved(page)) { + altmap = to_vmem_altmap((unsigned long) section_base); + if (altmap) { + vmem_altmap_free(altmap, nr_pages); + } else if (PageReserved(page)) { /* allocated from bootmem */ if (page_size < PAGE_SIZE) { /* diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 3bbba178b464..6f7b64eaa9d8 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -176,7 +177,8 @@ int arch_remove_memory(u64 start, u64 size, enum memory_type type) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; - struct zone *zone; + struct vmem_altmap *altmap; + struct page *page; int ret; /* @@ -193,8 +195,16 @@ int arch_remove_memory(u64 start, u64 size, enum memory_type type) return -EINVAL; } - zone = page_zone(pfn_to_page(start_pfn)); - ret = __remove_pages(zone, start_pfn, nr_pages); + /* + * If we have an altmap then we need to skip over any reserved PFNs + * when querying the zone. + */ + page = pfn_to_page(start_pfn); + altmap = to_vmem_altmap((unsigned long) page); + if (altmap) + page += vmem_altmap_offset(altmap); + + ret = __remove_pages(page_zone(page), start_pfn, nr_pages); if (ret) return ret;