linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: linux-mm@kvack.org
Subject: How best to bypass the page cache from within a kernel module?
Date: Wed, 17 Sep 2003 14:24:45 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.0309171402370.1171-100000@ida.rowland.org> (raw)

I'm working on a kernel module driver for Linux 2.6.  One of the things 
this driver needs to do is perform a VERIFY command; which means checking 
to make sure that certain disk sectors within a file actually can be read 
without encountering a bad sector or other hardware error.  Now, I realize 
that there are already issues involved with convincing the disk drive to 
read from its media rather than from its cache.  But apart from that, my 
problem is how to convince Linux to read from the drive rather than from 
the page cache.

One suggestion was to use O_DIRECT when opening the file, because that
does cause reads to go directly to the hardware.  The problem with this is
that since the direct-I/O routines send file data directly to user
buffers, they must check that the buffer addresses are valid and belong to
the user's address space.  But my code runs in a kernel thread so it has
no current->mm (and in any case I would prefer to use my kernel-space
buffers rather than user-space memory).  It might be possible to get hold
of an mm_struct, but it's not necessarily easy as mm_alloc() isn't
EXPORTed.  Perhaps my thread could keep its original current->mm by
incrementing current->mm->users before calling daemonize() and setting
current->mm back to its original value afterward.  Is that legal?  Having
done so, perhaps I could use some sort of mmap() call to allocate a
user-space buffer that would be okay for direct-I/O.  What's the best way
to do that -- what function would I have to call?

However, all that seems rather roundabout.  An equally acceptable solution 
would be simply to invalidate all the entries in the page cache referring 
to my file, so that reads would be forced to go to the drive.  Can anyone 
tell me how to do that?

TIA,

Alan Stern

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

             reply	other threads:[~2003-09-17 18:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-17 18:24 Alan Stern [this message]
2003-09-17 19:44 ` Dave Hansen
2003-09-17 19:50   ` William Lee Irwin III
2003-09-17 20:33     ` Alan Stern
2003-09-17 20:40       ` William Lee Irwin III
2003-09-17 20:43         ` William Lee Irwin III
2003-09-17 21:30         ` Alan Stern
2003-09-17 22:44           ` William Lee Irwin III
2003-09-22 18:51 ` Ray Bryant
2003-09-22 19:09   ` Alan Stern

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=Pine.LNX.4.44L0.0309171402370.1171-100000@ida.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=linux-mm@kvack.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