From: Imre Deak <imre.deak@intel.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Maxim Levitsky <maximlevitsky@gmail.com>,
Tejun Heo <tj@kernel.org>, Daniel Vetter <daniel.vetter@ffwll.ch>,
linaro-mm-sig@lists.linaro.org, Imre Deak <imre.deak@intel.com>
Subject: [PATCH v3 2/2] lib/scatterlist: use page iterator in the mapping iterator
Date: Wed, 13 Feb 2013 17:10:24 +0200 [thread overview]
Message-ID: <1360768224-18163-2-git-send-email-imre.deak@intel.com> (raw)
In-Reply-To: <1360768224-18163-1-git-send-email-imre.deak@intel.com>
In-Reply-To: <1360608604-3520-1-git-send-email-imre.deak@intel.com>
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 <tj@kernel.org>.
Signed-off-by: Imre Deak <imre.deak@intel.com>
---
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);
--
1.7.10.4
next prev parent reply other threads:[~2013-02-13 15:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1353590706-1366-5-git-send-email-imre.deak@intel.com>
2013-02-11 16:32 ` [PATCH] lib/scatterlist: add simple page iterator Imre Deak
2013-02-11 18:50 ` [PATCH v2] " Imre Deak
2013-02-11 20:54 ` Andrew Morton
2013-02-12 17:07 ` Imre Deak
2013-02-12 17:13 ` Tejun Heo
2013-02-13 14:51 ` Imre Deak
2013-02-12 21:28 ` Andrew Morton
2013-02-13 15:10 ` [PATCH v3 1/2] " Imre Deak
2013-02-13 15:10 ` Imre Deak [this message]
2013-02-21 13:58 ` [PATCH v4] lib/scatterlist: use page iterator in the mapping iterator Imre Deak
2013-02-24 11:05 ` [PATCH v5] " Imre Deak
2013-02-27 2:30 ` Stephen Warren
2013-02-23 4:29 ` [PATCH v3 2/2] " Stephen Warren
2013-02-23 20:04 ` Imre Deak
2013-02-23 23:45 ` Stephen Warren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360768224-18163-2-git-send-email-imre.deak@intel.com \
--to=imre.deak@intel.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.vetter@ffwll.ch \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maximlevitsky@gmail.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome