From: kai@gnukai.com (Kai Meyer)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Understanding kmap/kunmap
Date: Thu, 01 Dec 2011 10:49:26 -0700 [thread overview]
Message-ID: <4ED7BE26.2040105@gnukai.com> (raw)
I want to be able to copy data into a struct bio *, so I use
bio_for_each_segment to loop through each bvec, like so:
void some_function(struct bio *bio, char *some_data) {
struct bio_vec *bvec;
int i;
unsigned int bio_so_far = 0;
bio_for_each_segment(bvec, bio, i) {
char *bio_buffer = __bio_kmap_atomic(bio, i, KM_USER0);
memcpy(bio_buffer, some_data + bio_so_far, bvec->bv_len);
__bio_kunmap_atomic(bio, KM_USER0);
bio_so_far += bvec->bv_len;
}
}
There's lots more to the function, but this is basically the distilled
version with out any extra stuff.
What I'm finding is that when the bio has multiple bvecs that share the
same page, only the first bvec's data actually gets copied back up to
user-space, the rest is garbage or null (meaning, what was there
already). For instance, I see a lot of bios from vfat that are 4096
bytes long but are comprised of 8 bvecs that are 512 bytes long that all
have an offset to the same page.
I've tried doing just one kmap_atomic on the page by keeping track of
what the last page I kmap'ed was, but that didn't fix the problem either.
Any documentation or high level explanation of kmap/kunmap or other
ideas to try are welcome.
-Kai Meyer
next reply other threads:[~2011-12-01 17:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-01 17:49 Kai Meyer [this message]
2011-12-01 20:05 ` Understanding kmap/kunmap Kai Meyer
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=4ED7BE26.2040105@gnukai.com \
--to=kai@gnukai.com \
--cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).