From patchwork Fri Mar 11 21:13:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilcox, Matthew R" X-Patchwork-Id: 8569191 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 52FFFC0553 for ; Fri, 11 Mar 2016 21:13:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84F3220361 for ; Fri, 11 Mar 2016 21:13:11 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B5D2E202B8 for ; Fri, 11 Mar 2016 21:13:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7343D1A1F89; Fri, 11 Mar 2016 13:13:26 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 78F161A1F7F for ; Fri, 11 Mar 2016 13:13:23 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 11 Mar 2016 13:13:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,321,1455004800"; d="scan'208";a="932015375" Received: from jduan1-mobl2.amr.corp.intel.com (HELO thog.int.wil.cx) ([10.252.134.213]) by orsmga002.jf.intel.com with SMTP; 11 Mar 2016 13:13:07 -0800 Received: by thog.int.wil.cx (Postfix, from userid 1000) id 8A5F35F9EC; Fri, 11 Mar 2016 16:13:05 -0500 (EST) From: Matthew Wilcox To: Dan Williams Subject: [PATCH 3/3] pfn_t: New functions pfn_t_add and pfn_t_cmp Date: Fri, 11 Mar 2016 16:13:04 -0500 Message-Id: <1457730784-9890-4-git-send-email-matthew.r.wilcox@intel.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1457730784-9890-1-git-send-email-matthew.r.wilcox@intel.com> References: <1457730784-9890-1-git-send-email-matthew.r.wilcox@intel.com> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox , linux-nvdimm@lists.01.org X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we find a huge PFN in the radix tree, we need to add the low bits of the index to it in order to find the PFN we are looking for. Since we want the result to stay in pfn_t form, create pfn_t_add(). We also need to compare PFNs, for example to determine if the PFN represents a zero page. At the moment, we only have use for comparing equality, but a general compare operation is no more code and may prove useful in the future. Signed-off-by: Matthew Wilcox --- include/linux/pfn_t.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/pfn_t.h b/include/linux/pfn_t.h index 0ff4c4e..c3bb5fe 100644 --- a/include/linux/pfn_t.h +++ b/include/linux/pfn_t.h @@ -67,6 +67,22 @@ static inline unsigned long pfn_t_to_pfn(pfn_t pfn) return v >> PFN_FLAG_BITS; } +static inline __must_check pfn_t pfn_t_add(const pfn_t pfn, int val) +{ + pfn_t tmp = pfn; + if (tmp.val & PFN_HUGE) + tmp.val &= ~PFN_SIZE_MASK; + tmp.val &= ~PFN_SG_MASK; + tmp.val += val << PFN_FLAG_BITS; + return tmp; +} + +/* Like memcmp, returns <0 if a0 if b>a */ +static inline int pfn_t_cmp(pfn_t a, pfn_t b) +{ + return pfn_t_to_pfn(b) - pfn_t_to_pfn(a); +} + extern pfn_t phys_to_pfn_t(phys_addr_t addr, u64 flags); static inline bool pfn_t_has_page(pfn_t pfn)