From patchwork Wed Feb 13 15:10:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 14780 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5F6E723FD7 for ; Wed, 13 Feb 2013 15:18:30 +0000 (UTC) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by fiordland.canonical.com (Postfix) with ESMTP id B742CA18ECB for ; Wed, 13 Feb 2013 15:18:29 +0000 (UTC) Received: by mail-ve0-f175.google.com with SMTP id cy12so1131924veb.20 for ; Wed, 13 Feb 2013 07:18:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-extloop1:x-ironport-av:from:to:date:message-id :x-mailer:in-reply-to:references:in-reply-to:references:cc:subject :x-beenthere:x-mailman-version:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-gm-message-state; bh=dWT9eXK0h2/T4xnlRxHYj7Wfu4bM/hvMX5Y2HJS9luw=; b=ETLUQCaMDPZEtLwB2etFRRzbkd1oX2c/R0e6a+D0RAkCyFaCRl7OeX9SzEiWJP1ZSg 4TOFVYwVSIfc06MAzEcS78waMCl4fP+7djC7n1FK5CVWmw4n9CcEemOKLLX3+iKVq3R5 hkb2ms1xoOKtTreGJzXG2vZWiF0SSGmmv8upVylq7y+xUXh0KWESZ/rfgR3jbdqcoMCW r0OOwdooiuYA/A/iaxrhOa4quGwvQkivf+BPMHNeZRByXha8uuawJI4SydPlAoRN7y2a iaixvmWO4uOUp+btbvXpGx7bKlnDDPDb5kUF4bvP3BGmd1gWLBfrHPhDjelsQ6Eaobcd TeSQ== X-Received: by 10.52.175.66 with SMTP id by2mr26173960vdc.53.1360768709230; Wed, 13 Feb 2013 07:18:29 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.221.4.5 with SMTP id oa5csp200499vcb; Wed, 13 Feb 2013 07:18:28 -0800 (PST) X-Received: by 10.14.182.71 with SMTP id n47mr5167416eem.11.1360768246931; Wed, 13 Feb 2013 07:10:46 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id m43si5281514een.199.2013.02.13.07.10.46; Wed, 13 Feb 2013 07:10:46 -0800 (PST) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1U5dyv-0007NT-Dc; Wed, 13 Feb 2013 15:10:45 +0000 Received: from mga02.intel.com ([134.134.136.20]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1U5dyt-0007N7-LW for linaro-mm-sig@lists.linaro.org; Wed, 13 Feb 2013 15:10:43 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 13 Feb 2013 07:10:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,657,1355126400"; d="scan'208";a="285222032" Received: from unknown (HELO localhost) ([10.252.120.81]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2013 07:10:38 -0800 From: Imre Deak To: linux-kernel@vger.kernel.org Date: Wed, 13 Feb 2013 17:10:24 +0200 Message-Id: <1360768224-18163-2-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360768224-18163-1-git-send-email-imre.deak@intel.com> References: <1360768224-18163-1-git-send-email-imre.deak@intel.com> In-Reply-To: <1360608604-3520-1-git-send-email-imre.deak@intel.com> References: <1360608604-3520-1-git-send-email-imre.deak@intel.com> Cc: Maxim Levitsky , linaro-mm-sig@lists.linaro.org, Tejun Heo , Andrew Morton Subject: [Linaro-mm-sig] [PATCH v3 2/2] lib/scatterlist: use page iterator in the mapping iterator X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQllet3g4UByzYXfJXMIdHyR0xgXcpFtCgPsLC++WF2h7MUnMc+6cKTenlr/ZlIItFWw94xF For better code reuse use the newly added page iterator to iterate through the pages. The offset, length within the page is still calculated by the mapping iterator as well as the actual mapping. Idea from Tejun Heo . Signed-off-by: Imre Deak --- include/linux/scatterlist.h | 6 +++--- lib/scatterlist.c | 46 ++++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 788a853..a6cd692 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -295,9 +295,9 @@ struct sg_mapping_iter { size_t consumed; /* number of consumed bytes */ /* these are internal states, keep away */ - struct scatterlist *__sg; /* current entry */ - unsigned int __nents; /* nr of remaining entries */ - unsigned int __offset; /* offset within sg */ + unsigned int __offset; /* offset within page */ + struct sg_page_iter __piter; /* page iterator */ + unsigned int __remaining; /* remaining bytes on page */ unsigned int __flags; }; diff --git a/lib/scatterlist.c b/lib/scatterlist.c index a1d1564..4e4974a 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -449,9 +449,7 @@ void sg_miter_start(struct sg_mapping_iter *miter, struct scatterlist *sgl, { memset(miter, 0, sizeof(struct sg_mapping_iter)); - miter->__sg = sgl; - miter->__nents = nents; - miter->__offset = 0; + __sg_page_iter_start(&miter->__piter, sgl, nents, 0); WARN_ON(!(flags & (SG_MITER_TO_SG | SG_MITER_FROM_SG))); miter->__flags = flags; } @@ -476,36 +474,33 @@ EXPORT_SYMBOL(sg_miter_start); */ bool sg_miter_next(struct sg_mapping_iter *miter) { - unsigned int off, len; - - /* check for end and drop resources from the last iteration */ - if (!miter->__nents) - return false; - sg_miter_stop(miter); - /* get to the next sg if necessary. __offset is adjusted by stop */ - while (miter->__offset == miter->__sg->length) { - if (--miter->__nents) { - miter->__sg = sg_next(miter->__sg); - miter->__offset = 0; - } else + /* + * Get to the next page if necessary. + * __remaining, __offset is adjusted by sg_miter_stop + */ + if (!miter->__remaining) { + struct scatterlist *sg; + unsigned long pgoffset; + + if (!__sg_page_iter_next(&miter->__piter)) return false; - } - /* map the next page */ - off = miter->__sg->offset + miter->__offset; - len = miter->__sg->length - miter->__offset; + sg = miter->__piter.sg; + pgoffset = miter->__piter.sg_pgoffset; - miter->page = nth_page(sg_page(miter->__sg), off >> PAGE_SHIFT); - off &= ~PAGE_MASK; - miter->length = min_t(unsigned int, len, PAGE_SIZE - off); - miter->consumed = miter->length; + miter->__offset = pgoffset ? 0 : sg->offset; + miter->__remaining = sg->offset + sg->length - + (pgoffset << PAGE_SHIFT) - miter->__offset; + } + miter->page = miter->__piter.page; + miter->consumed = miter->length = miter->__remaining; if (miter->__flags & SG_MITER_ATOMIC) - miter->addr = kmap_atomic(miter->page) + off; + miter->addr = kmap_atomic(miter->page) + miter->__offset; else - miter->addr = kmap(miter->page) + off; + miter->addr = kmap(miter->page) + miter->__offset; return true; } @@ -532,6 +527,7 @@ void sg_miter_stop(struct sg_mapping_iter *miter) /* drop resources from the last iteration */ if (miter->addr) { miter->__offset += miter->consumed; + miter->__remaining -= miter->consumed; if (miter->__flags & SG_MITER_TO_SG) flush_kernel_dcache_page(miter->page);