From patchwork Thu Jul 5 06:49:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10508227 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 B4F1760116 for ; Thu, 5 Jul 2018 06:59:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A356428DF2 for ; Thu, 5 Jul 2018 06:59:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9744328E49; Thu, 5 Jul 2018 06:59:19 +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 1575128DF2 for ; Thu, 5 Jul 2018 06:59:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB9A26B0269; Thu, 5 Jul 2018 02:59:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C693E6B026A; Thu, 5 Jul 2018 02:59:17 -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 B7FC76B026B; Thu, 5 Jul 2018 02:59:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 7568B6B0269 for ; Thu, 5 Jul 2018 02:59:17 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id w1-v6so1405841plq.8 for ; Wed, 04 Jul 2018 23:59:17 -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:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=rif1KKQDKT6S66Vk4b0BdG1z2mUxExzcOz9fOzY5BA0=; b=roq5xSOiRU4NSeMCRBL1BpZnbgGpqs9e9WajgOWeW5wk2+fofUIfWgq+njYSDaCnoC +2O5m6sj+GEWpLCN2i67Cd0dke3ytv62PMdTcWqUV/lDTnH0V/TyvYCLn96NMKwlXcEc iLBSsWfMDav1C1GoEwdEfat2ZmFkX9S0uTE7oZSkr6Oka3aCKilNVV42uWgMAWFiS3fQ E8kFfXt1uicIrDwZi7GsbVJmGXPtrk0X6VVw03k1nPIIgFt0kaih0OiuQ3U7+bERMFry QbZgKoW4yEj1ZXKOsGdP2pqsFi67B62cvJozTDyUWiZWUEzbQjtePTr7dB+PF2GgbufR tO4Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E3rcoMWdHtSKF67qBZB+PpIKQtIWWj1gDsG0IeSTb1Fo62sLeC3 9t7Pfq5VNA8a5OQBgRE1Q/WXNEsLhkyAubVgs1+fxqQFBq5ccSkQZhGvbxepDhv0aY3zp23oA6I 1gt+e0z8X2+dHH+Eh/AbHUMHVnyGCJLj7Oglle5qEpXFfaiwKhdftmTy+ZcS+vFzH7g== X-Received: by 2002:a63:af14:: with SMTP id w20-v6mr4554570pge.47.1530773957156; Wed, 04 Jul 2018 23:59:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfV/zm7EuKBZfO/ly58sw3RF797wo7mqZXXu6tfq0aSwntFfKlR/wTzxw3SchtlbDg8nxFL X-Received: by 2002:a63:af14:: with SMTP id w20-v6mr4554536pge.47.1530773956448; Wed, 04 Jul 2018 23:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530773956; cv=none; d=google.com; s=arc-20160816; b=xOxeYlVL+kkTeJv9bkeKg6+qgLweOvmD+0uXH/8F038ERlINnBZ6Y6byN6vSJdYyc4 uwaUgqllUpgLZIr7BS1ZdQflHTHA4XRxn7o380xxhvXhtqybJoBrvYrS493Ln+LmYYIw nggyzrJIPI5ZzZ6THFYg7nj3lnczOjayK6QuAhSo+SjWQEbu3zjYc5YxR3kin7Hv3d1M slYRLzTQ0QRFuCuL1B0cxC6hnComzKZnRSlY3zkkxq5rYoTLM/CJWG5kVa8DzXAc8dg+ c6KBSAjzVOMlBsZGRLdwjwqwhRHmDPSNxN6ItKvb5xCiCJE3z48XCjvhABq5/fYoyZc3 UZHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject :arc-authentication-results; bh=rif1KKQDKT6S66Vk4b0BdG1z2mUxExzcOz9fOzY5BA0=; b=nUKNM4KG0rKILSbqOc06GIaxjjue5lzOqmeOk53TDQYJR9UWztMsQOf2VPld69y7z+ UGK9NOwB6E0PgTB5/gCPAlrR6CSic85CmLomqbylfon2wt/ET4D55V9yeKHL0WKsRLFL djlJwthX+kxgdhgxoLdRf3FKAydqpsyQfOx+srms7x/cKbwuqGBvmRU7oC5o8WbxvZtS LBMuaf0mVmbSWXhhSMVTU5tDUsXnLY0eLUYHfokqnzG5E2V7KeUFLeuif1ipK1nvGBQ/ ToE6B9hOF0ms3kSGEuh/t7E+8M3J98C65hu9AqZB1dRBDGPa85Rtvp/8ZjsCpvA+pTBO dulg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id y11-v6si5158795pll.89.2018.07.04.23.59.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 23:59:16 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 23:59:16 -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 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 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); + } } }