Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2573307imm; Mon, 16 Jul 2018 10:11:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcWdZOlRumuZmL8K4HctJHRwv45fz8+45kdOVcC6YlYerpTwZn+FRMzVEJrYxmrlfNjQzLs X-Received: by 2002:a62:c8c2:: with SMTP id i63-v6mr19002206pfk.73.1531761112725; Mon, 16 Jul 2018 10:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531761112; cv=none; d=google.com; s=arc-20160816; b=PlbJJCEZsTyPKVMyjIm9f1en3ec03TB//EPmoU3thq6OrEAfzaWCwuSb+mQbjlEtRh Qo+KNieuZdNCqrjMgugASU4AnCV0oLsvJdrQLmDtuddj75sVigZ6A5IP+u6LzS0Px6Wi ACSW2ImxUngRiH+rcSHwt0YCJ9tuS5kG3f/CAvYOlquy9bNp2AyxAIIBPhorxSHE+8rA Nd2OPw1wUhpLKGx5pfNdj1XWRARsPeQfbuANDkgxbydMU0oZLEPFbGI0cgV5T4Yn6+R5 gFM1YN+tj20UUryoAYXjet/kHiQMDtceneYs2QOsZNntywYzq+IbMsy3DcGcoV/dHYPz IOZA== 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=aHCO9UgqQIJzFsIN3nXmTIEgTUwiIyWuHHLIo0F6Ybo=; b=x4GwIp6FOX3ejx52j3FBwxytyug3Qf3reSYRTQDClhq76GHiRR1u9Yw8oG0zm50Sbh WepavUYvAOIPZKZA6Ol0a5IEqkxdrPrZqF5j+dtli0VomcpT+5fZKXuqCySDzFwuuZiR upAKYUzUpPc0u3t21+U1a0k1bfmaKyiYftRYZ4w+2kXeuudM+kFNViwOj31S3CnjOjJU FbT+gXsznaTKczMSFCQ1pQ9NF0NI0o3AOfyw7HyalVP7wW/im26HUMMeWW9kMR81BDvc C4eXsnUVXdzEJMSCp2LQsbJqyxR9r9ocK1K0xaN/tWxN87NAZX+r+KwJmud3TzICocRb kCmA== 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 w4-v6si32947599pfb.52.2018.07.16.10.11.37; Mon, 16 Jul 2018 10:11:52 -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 S1729865AbeGPRjE (ORCPT + 99 others); Mon, 16 Jul 2018 13:39:04 -0400 Received: from mga09.intel.com ([134.134.136.24]:28780 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbeGPRjE (ORCPT ); Mon, 16 Jul 2018 13:39:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 10:10:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,362,1526367600"; d="scan'208";a="58100609" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga006.jf.intel.com with ESMTP; 16 Jul 2018 10:10:45 -0700 Subject: [PATCH v2 05/14] mm, memremap: Up-level foreach_order_pgoff() From: Dan Williams To: akpm@linux-foundation.org Cc: Logan Gunthorpe , Matthew Wilcox , vishal.l.verma@intel.com, hch@lst.de, linux-mm@kvack.org, jack@suse.cz, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Mon, 16 Jul 2018 10:00:48 -0700 Message-ID: <153176044796.12695.10692625606054072713.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The foreach_order_pgoff() helper takes advantage of the ability to insert multi-order entries into a radix. It is currently used by devm_memremap_pages() to minimize the number of entries in the pgmap radix. Instead of dividing a range by a constant power-of-2 sized unit and inserting an entry for each unit, it determines the maximum power-of-2 sized entry (subject to alignment offset) that can be inserted at each iteration. Up-level this helper so it can be used for populating other radix instances. For example asynchronous-memmap-initialization-thread lookups arriving in a follow on change. Cc: Logan Gunthorpe Cc: Matthew Wilcox Signed-off-by: Dan Williams --- include/linux/memremap.h | 25 +++++++++++++++++++++++++ kernel/memremap.c | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index bfdc7363b13b..bff314de3f55 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -126,6 +126,31 @@ struct dev_pagemap { enum memory_type type; }; +static inline unsigned long order_at(struct resource *res, unsigned long pgoff) +{ + unsigned long phys_pgoff = PHYS_PFN(res->start) + pgoff; + unsigned long nr_pages, mask; + + nr_pages = PHYS_PFN(resource_size(res)); + if (nr_pages == pgoff) + return ULONG_MAX; + + /* + * What is the largest aligned power-of-2 range available from + * this resource pgoff to the end of the resource range, + * considering the alignment of the current pgoff? + */ + mask = phys_pgoff | rounddown_pow_of_two(nr_pages - pgoff); + if (!mask) + return ULONG_MAX; + + return find_first_bit(&mask, BITS_PER_LONG); +} + +#define foreach_order_pgoff(res, order, pgoff) \ + for (pgoff = 0, order = order_at((res), pgoff); order < ULONG_MAX; \ + pgoff += 1UL << order, order = order_at((res), pgoff)) + #ifdef CONFIG_ZONE_DEVICE void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap, void (*kill)(struct percpu_ref *)); diff --git a/kernel/memremap.c b/kernel/memremap.c index 85e4a7c576b2..fc2f28033460 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -16,31 +16,6 @@ static RADIX_TREE(pgmap_radix, GFP_KERNEL); #define SECTION_MASK ~((1UL << PA_SECTION_SHIFT) - 1) #define SECTION_SIZE (1UL << PA_SECTION_SHIFT) -static unsigned long order_at(struct resource *res, unsigned long pgoff) -{ - unsigned long phys_pgoff = PHYS_PFN(res->start) + pgoff; - unsigned long nr_pages, mask; - - nr_pages = PHYS_PFN(resource_size(res)); - if (nr_pages == pgoff) - return ULONG_MAX; - - /* - * What is the largest aligned power-of-2 range available from - * this resource pgoff to the end of the resource range, - * considering the alignment of the current pgoff? - */ - mask = phys_pgoff | rounddown_pow_of_two(nr_pages - pgoff); - if (!mask) - return ULONG_MAX; - - return find_first_bit(&mask, BITS_PER_LONG); -} - -#define foreach_order_pgoff(res, order, pgoff) \ - for (pgoff = 0, order = order_at((res), pgoff); order < ULONG_MAX; \ - pgoff += 1UL << order, order = order_at((res), pgoff)) - #if IS_ENABLED(CONFIG_DEVICE_PRIVATE) int device_private_entry_fault(struct vm_area_struct *vma, unsigned long addr,