From patchwork Mon Jul 16 17:00:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10527241 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 59CD6601D2 for ; Mon, 16 Jul 2018 17:10:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A67128D7E for ; Mon, 16 Jul 2018 17:10:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EE0D28D83; Mon, 16 Jul 2018 17:10:50 +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 C254228D7E for ; Mon, 16 Jul 2018 17:10:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 853F06B026D; Mon, 16 Jul 2018 13:10:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8052A6B026E; Mon, 16 Jul 2018 13:10:48 -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 71C0D6B026F; Mon, 16 Jul 2018 13:10:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 31C6D6B026D for ; Mon, 16 Jul 2018 13:10:48 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id q12-v6so3824165pgp.6 for ; Mon, 16 Jul 2018 10:10:48 -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=aHCO9UgqQIJzFsIN3nXmTIEgTUwiIyWuHHLIo0F6Ybo=; b=Q2JtACBX9XJ1fUd31v6Yp7BwdKTt6kwOMXGa6gdWoIM5FrxAtqOc3AmblVAJmsR2ey /QXWitTnHnncq2oKuDKdLazc6W+D5+brji1VFuaBaosHFK9Wdmo8Q6mnklC54AsGUs4q YOQvEN+7WXqWrngqb9oub8DeU4aKNSr0i8s3nyIeN4o3hzcAqqlKJ6yUNncyeZE8w79X 8NiLzKoW9+P52aXg2rBu5Q5sb42RqiLinsuPC1DtjilO+nhTDGB4jv3Rpal8g97M2ic1 br6xoSNO93ujIxVj2OdN33XjljKCdgBovFoKyWNaVQH//V0/KzVCIMRzzZNshEnmFohB siQA== 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: AOUpUlGDE/rj0uTJOKPTlfluX6qYxl/KrbsR7NTG7+eVnitWV/jdMP3f w+VRPCPLoJW9j5ae+2veOR3lrROl+by6wDbnVp/UVy5L0GqA78uVMxVky6Arh7SdmkT1MB/hwMg avh44AJvATVthD0MNowEKjPyMlyWfQ7PNQCQPrCAFm+aUhVQF7IyLMq7bgpBA1N4JDQ== X-Received: by 2002:a62:229a:: with SMTP id p26-v6mr18899987pfj.53.1531761047884; Mon, 16 Jul 2018 10:10:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdkRJyQxUHQzniJkSIcLhesM7+56yukrhlFJ+/d8bK5LE01H5sznFAow63vCEs/a47i9cGc X-Received: by 2002:a62:229a:: with SMTP id p26-v6mr18899927pfj.53.1531761047073; Mon, 16 Jul 2018 10:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531761047; cv=none; d=google.com; s=arc-20160816; b=i2koaRGC1iH5tLTcCReBQanDiZ9x5FZKklhp+us/eLEWkwXaUJ5YsaUkivtJOCiiEZ APbe/Tp3K4E3HShbATHNBm16iV//VJi/hB4di4441nbqNw8uiuvvg1JNQvyDb74Msroe MT9bh/NX13Y1oB0eRr+LE9Rc2WATPb+6kwgONpjxrFHEwBDPRE2BKWCYCbmE7IVq8YfJ PcVd3OtHe3iCgg4Ev75hvBDG+RXND9jtHkxfbq3n1zLsQ584i/wvpnY0R4LdMmXFB6xx oaSCBHYO4WQ0EW+441QzpFuTmk0Pm2PHvjXoiUDDoWAmIuQ8/JgsZ3ISeILmLIBf8nqJ mfGQ== 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=aHCO9UgqQIJzFsIN3nXmTIEgTUwiIyWuHHLIo0F6Ybo=; b=lC3cpQgWwn61derbz78MG97XqEi9rNq1ZQLjGiaFTK3g8jwsjuoMZEa2t+82C7GxrE llRF+xFah+xVD9c/lAIvLPJvPhRTr9FF4ZY5rYop7gXKWvWTwHqMOdqF/O/kuJ7+DChv F+N9j74R4bHrGEjWEuMZYp417qVbwdnL/3fHbpgHUpTwNs7iCQ24hCt4Ha3Y0o9Ipk/D adKdT67IpTdUzsuwarPtS8ow6DzVCr7tnDNenZ7TAtpEPGgtbEtoDCASjSzum6HuckK3 myWVS1883jd39Vew8q7yH4wycYVwun7ef/9SkxuO26XajcVfegyNwJ8cLhBqEhtvu+ji JJ0Q== 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 u19-v6si31410049pgk.100.2018.07.16.10.10.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 10:10:47 -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 orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.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 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 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,