From patchwork Mon Jul 16 17:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10527303 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 BC78E601D2 for ; Mon, 16 Jul 2018 17:13:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB28C28B1B for ; Mon, 16 Jul 2018 17:13:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F84828D8F; Mon, 16 Jul 2018 17:13:27 +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=unavailable 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 9106628B1B for ; Mon, 16 Jul 2018 17:13:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC7CB6B0281; Mon, 16 Jul 2018 13:13:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A747C6B0282; Mon, 16 Jul 2018 13:13:25 -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 914D76B0283; Mon, 16 Jul 2018 13:13:25 -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 4D9346B0281 for ; Mon, 16 Jul 2018 13:13:25 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id x2-v6so25094091plv.0 for ; Mon, 16 Jul 2018 10:13:25 -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=B99kVgYz/EtNwtL57WigVxfhwvihD5s7n4eeGglrSRo=; b=g//zg3GoGofUh5tdjGjJuza4/aSEzofAQQxdqdUBedtq6o6NlPNYoyG3wY3zW3V3Pl ulckL2oamZdW99JVmMbJcqVLnBpArXYTTNhtvkmAXusQ7Ulqb0mvghZMzW1bMrRrpEdX AJ5BfxaJXHw7qsBo6iv+X8TNm2Kr0xwahc2qOusp/o7FYjQ2EZlRdO1yWQ4XLc0dQ9aZ VLyTjThkAoy7g2kZQsXaozk3qyIE6YgHqzh8pFPd0qFPYCXJ+IcnBZw1WtTzpmTfzb9C jqP0kg+kwhs8pg8V98B0rpki8eIJnnj7ZSggGY5vO85ffjQh0lFR6BNYyZLyLK1j8q6v XQkA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 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: AOUpUlE5P1iRvgUWzmI3Ml61iSA0gPv6N66SauHMHmHfvuVG8nYz6QlV UxZkbrsbaIRZTzkmuZqzqxnE4DAp/REzZjRX6pvcKgOg4kfKx4utdIEe4OOvtBFfDXCM39Xtn7g oaJ9AWXBfaqsyo8u5BdcJ5ls57Nbehozhvk4roYudSo7qjcjaVzCI1J+2w+xx6yLHTQ== X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr17236422pld.72.1531761204998; Mon, 16 Jul 2018 10:13:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf4E4al1/M7iY4HvULrkP/ybfFyQelrRBjTW6eRteSs/LPS5RREnXYWOs0F+cgvHUMbIehn X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr17236365pld.72.1531761204261; Mon, 16 Jul 2018 10:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531761204; cv=none; d=google.com; s=arc-20160816; b=mxTcvE0l1xLGuA6s++gS8mVSZClbGjI9X5Q6r4nnvHfS0D5Lq740Jb5DFdKRy46+Da kBdLYw8IV236Uth8ky9nhsKfhZAeO7yajDXDnREyRwZDFz7LSebeuF53YFIb0hHqIRne SaRMCxCYifH4WCFdFAH3GL995Fuazmc8VfvgTN+v/nmPlHs4PJYxLZVETnu0UILKuorE VkMjYn585M24PqjUJvvlYVt9ueiwbD9W+gpRBzmUuIZMrltmRiudbtj1kwTfBxLGq1SP /g+dzH3Oq94CHJmz5JOM2+//HS1EGMEQ7bAPqPQ99RBHSHtSnR+5hXBV4X93dgTUPIVH vSfQ== 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=B99kVgYz/EtNwtL57WigVxfhwvihD5s7n4eeGglrSRo=; b=GLX8OdGcDyDV6+rqwxnMF+Pz33ZeWUMggE0FNW2pNe2KjaH7oQAHGlwVY9ATdSVlhO 5Rzp+YkWGZcgQIfb71+BfX/lkQuZ+lJsix7lwXfGBfAY2hHuQSL0aoYV+SuvQnwBOO04 1Kj6dB46U9nEYmtnbdNuzWaUoNc7dd0o3Ydxnq9iAHuzQ4na1j2IRCr9kvyWHcZUB32y nfvbNOZFt3xoIks/uog3BDGR+pkcmXgZ+k5h4LX9mkxrJr0rHTGBuFUYCulGsYI2wY2e BlqoFejws/6sVBmtov8sDKQajrEFiELshDcZORn8iIkvphaOHc+WGD8s5qW6ONY+Hgrk jrvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id d26-v6si30103688pgd.32.2018.07.16.10.13.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 10:13:24 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 as permitted sender) client-ip=134.134.136.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 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 fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 10:13:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,362,1526367600"; d="scan'208";a="245695082" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga005.fm.intel.com with ESMTP; 16 Jul 2018 10:10:35 -0700 Subject: [PATCH v2 03/14] 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 , Daniel Jordan , Pavel Tatashin , vishal.l.verma@intel.com, linux-mm@kvack.org, jack@suse.cz, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Mon, 16 Jul 2018 10:00:37 -0700 Message-ID: <153176043742.12695.12733023097134464039.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153176041838.12695.3365448145295112857.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153176041838.12695.3365448145295112857.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: Daniel Jordan Cc: Pavel Tatashin Cc: Andrew Morton 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); + } } }