Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp294310imm; Thu, 5 Jul 2018 00:00:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc3LRgHAf2srGcDjI8vXTvYo7V4uZVcx0vVNx5CEv0YF0hKOSZSxD/taBersT6tVPEO8DTF X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr5031311plb.245.1530774028771; Thu, 05 Jul 2018 00:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530774028; cv=none; d=google.com; s=arc-20160816; b=R6g+zlBjm9RlY/WVwMGzIFkCXUnKa35JbWB6kfw0G4sLD5qSL2IrmzEvq5fqAL+E/n 2XGcM1oTt6ptEA18hDkUFgk3Ayji+GVpy3rS23dT8apn6qndaZjo2gqr8nSyb6q882NE ky/ckliPTNna7C1uRODBlDm7bCvEztcoS7BDrW5Ej2QDNeFoK/05Jwo1VwFrk71P8HoI ERKIFJRR5dGK/g1p0U3RKBkzGBU+itIBIjhlgMDNRU6BzRezcKA0IE1mZjvYcXINaUb0 UrXLafAdmM9aQ3t8yHVAmXLcPgbH9cJURQTEPveaEqrphDcCIy1ksg1u86L6bTTbQvoG IBIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=rif1KKQDKT6S66Vk4b0BdG1z2mUxExzcOz9fOzY5BA0=; b=ixRuDCmHHXLAaQKPxiQwyfWs0THDv3lLC9UmbOc+3p3ThUXL2ZjWrDrm362jI564c2 7PbKynCYM1jsuznV0+gEi4BklRMFzgwGCg5REGncOEoqBdDVHv2kN56HZhqwqTd1xPpW rIU4zPYqyW8/kNdsE5Ws0ehCx7SmzvpLHNqhFQ1NeXI2IluJvl0HNd1DSMovhtY5Iv7x RzxrQ5+TkOH/GSHfsl8We/GW0s8blL2VdRAbsf7qNyGBRXh5FMonAmBECGBB8iWKv3Rt j2D7aF4S86tW47w/WWMFG8LJitv4barO92eQWcG8W6sz1O5blgz2RaQFyWGb26huvmqZ A0Tw== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x17-v6si5180865pfn.286.2018.07.05.00.00.14; Thu, 05 Jul 2018 00:00:28 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753429AbeGEG7T (ORCPT + 99 others); Thu, 5 Jul 2018 02:59:19 -0400 Received: from mga17.intel.com ([192.55.52.151]:22778 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752681AbeGEG7Q (ORCPT ); Thu, 5 Jul 2018 02:59:16 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 23:59:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,311,1526367600"; d="scan'208";a="64302111" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga002.fm.intel.com with ESMTP; 04 Jul 2018 23:59:15 -0700 Subject: [PATCH 03/13] mm: Teach memmap_init_zone() to initialize ZONE_DEVICE pages From: Dan Williams To: akpm@linux-foundation.org Cc: Logan Gunthorpe , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Christoph Hellwig , Michal Hocko , Vlastimil Babka , vishal.l.verma@intel.com, linux-nvdimm@lists.01.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Wed, 04 Jul 2018 23:49:18 -0700 Message-ID: <153077335821.40830.17705033415231166642.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153077334130.40830.2714147692560185329.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153077334130.40830.2714147692560185329.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rather than run a loop over the freshly initialized pages in devm_memremap_pages() *after* arch_add_memory() returns, teach memmap_init_zone() to return the pages fully initialized. This is in preparation for multi-threading page initialization work, but it also has some straight line performance benefits to not incur another loop of cache misses across a large (100s of GBs to TBs) address range. Cc: Andrew Morton Cc: Logan Gunthorpe Cc: "Jérôme Glisse" Cc: Christoph Hellwig Cc: Michal Hocko Cc: Vlastimil Babka Signed-off-by: Dan Williams --- kernel/memremap.c | 16 +--------------- mm/page_alloc.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index b861fe909932..85e4a7c576b2 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -173,8 +173,8 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap, struct vmem_altmap *altmap = pgmap->altmap_valid ? &pgmap->altmap : NULL; struct resource *res = &pgmap->res; - unsigned long pfn, pgoff, order; pgprot_t pgprot = PAGE_KERNEL; + unsigned long pgoff, order; int error, nid, is_ram; if (!pgmap->ref || !kill) @@ -251,20 +251,6 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap, if (error) goto err_add_memory; - for_each_device_pfn(pfn, pgmap) { - struct page *page = pfn_to_page(pfn); - - /* - * ZONE_DEVICE pages union ->lru with a ->pgmap back - * pointer. It is a bug if a ZONE_DEVICE page is ever - * freed or placed on a driver-private list. Seed the - * storage with LIST_POISON* values. - */ - list_del(&page->lru); - page->pgmap = pgmap; - percpu_ref_get(pgmap->ref); - } - pgmap->kill = kill; error = devm_add_action_or_reset(dev, devm_memremap_pages_release, pgmap); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f83682ef006e..fb45cfeb4a50 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5548,6 +5548,25 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, set_pageblock_migratetype(page, MIGRATE_MOVABLE); cond_resched(); } + + if (is_zone_device_page(page)) { + if (WARN_ON_ONCE(!pgmap)) + continue; + + /* skip invalid device pages */ + if (altmap && (pfn < (altmap->base_pfn + + vmem_altmap_offset(altmap)))) + continue; + /* + * ZONE_DEVICE pages union ->lru with a ->pgmap back + * pointer. It is a bug if a ZONE_DEVICE page is ever + * freed or placed on a driver-private list. Seed the + * storage with poison. + */ + page->lru.prev = LIST_POISON2; + page->pgmap = pgmap; + percpu_ref_get(pgmap->ref); + } } }