Re: O_DIRECT Inside Kernel Module?



jaylucasaustin.rr.com <jaylucas@xxxxxxxxxxxxx> wrote:
> I have written a target mode SCSI device driver that can use system memory
> for high speed reads and writes. I would like to be able to back these
> reads and writes up to a partition (I.E. to /dev/sdb1). I have been able to
> do so inside the module by opening the specified device and then I can
> simply read and write to it. However, standard reads and writes are cached
> and not immediately written to the hard drive and really spike CPU
> utilization. O_DIRECT has served me in the past as a way to read or write
> directly to a block level device, but I am getting an EFAULT (error 14 aka
> Bad Address) when I attempt this from a kernel module. I have verified that
> my I/O size is sector size and that my I/O's are aligned and a multiple of
> sector size, so this is not the problem. Also, I used the same code in user
> space and could read and write without incident.

Clearly it expects a user space address as a buffer (my guess)..

But I am extremely surprised that you can read or write ordinarily from
within a kernel module. I would not expect that at all, since those are
system calls, and therefore must go via the syscall nterface, using
special assembly linkage, calling conventions, address space
requirements, and so on. And then there is the possibility of creating
a deadlock loop - such as needing ram for buffer space to put your
writes into, but not being able to get any ram until you have flushed
existing writes aimed at your device, which needs ram for you to put
those writes into ... I would have thought the only safe thing to do
would have been to create block write requests out of existing
buffers and buffer heads and launch them int the block device
subsystem.

You want to ask yourself why systems like MD and LVM do not do "read
and write" to a target device from within the kernel.

Peter
.



Relevant Pages

  • Re: O_DIRECT Inside Kernel Module?
    ... >> Clearly it expects a user space address as a buffer.. ... > would be done for user and kernel space. ... but not being able to get any ram until you have flushed ...
    (comp.os.linux.development.system)
  • Re: can device drivers return non-ram via vm_ops->nopage?
    ... ALSA wants to mmap the buffer used to transfer data to/from the ... This buffer may be direct-mapped RAM, ... > drivers, and user space ALSA library, mainly the DMA buffer ...
    (Linux-Kernel)
  • Re: get_user_pages question
    ... I am testing this kernel module with several buffers from user space allocated ... All scenarious work EXCEPT the stack one. ... When passing the stack buffer ...
    (Linux-Kernel)
  • Re: allocation failed: out of vmalloc space error treating and VIDEO1394 IOC LISTEN CHANNEL ioctl fa
    ... > not need vmalloc in the first place.... ... we need a large ring buffer for reception of isochronous ... Driver uses vmalloc_to_pageon every page of the malloc'ed memory ... what I'd really like to do is to leave it to user space to ...
    (Linux-Kernel)
  • Re: Audio skips when RAM is ~full
    ... It's different because you need to reserve a fixed amount of ram for the ... There may be a problem with the way the audio buffer gets allocated or freed. ... Basically, you tell it how many kB you want to free, then it allocates ...
    (Linux-Kernel)