On 11/18/07, Mark Lord <liml@xxxxxx> wrote: > Fajun Chen wrote: > > On 11/17/07, Mark Lord <liml@xxxxxx> wrote: > .. > >> What you probably intended to do instead, was to use mmap to just allocate > >> some page-aligned RAM, not to actually mmap'd any on-disk data. Right? > >> > >> Here's how that's done: > >> > >> read_buffer = (U8 *)mmap(NULL, buf_sz, PROT_READ | PROT_WRITE, > >> MAP_SHARED|MAP_ANONYMOUS, -1, 0); > >> > > What I intended to do is to write data into disc or read data from > > disc via SG_IO as requested by my user-space application. I don't want > > any automatically scheduled kernel task to sync data with disc. > .. > > Right. Then you definitely do NOT want to mmap your device, > because that's exactly what would otherwise happen, by design! > > > > I've experimented with memory mapping using MAP_ANONYMOUS as you > > suggested, the good news is that it does free up the cpu load and my > > system is much more responsive with the change. > .. > > Yes, that's what we expected to see. > > > > The bad news is that > > the data read back from disc (PIO or DMA read) seems to be invisible > > to user-space application. For instance, read buffer is all zeros > > after Identify Device command. Is this expected side effect of > > MAP_ANONYMOUS option? > .. > > No, that would be a side effect of some other bug in the code. > > Here (attached) is a working program that performs (PACKET)IDENTIFY DEVICE > commands, using a mmap() buffer to receive the data. > I verified your program works in my system and my application works as well if changed accordingly. However, this change (indirect IO in sg term) may come at a performance cost for IO intensive applications since it does NOT utilize mmaped buffer managed by sg driver. Please see relevant sg document below: http://sg.torque.net/sg/p/sg_v3_ho.html#id2495330 http://sg.torque.net/sg/p/sg_v3_ho.html#dmmio As an example, sg_rbuf.c in sg3_util package uses SG_FLAG_MMAP_IO flag in SG_IO. Please see source code attached. I also noticed that MAP_ANONYMOUS is NOT used in mmap() call in sg_rbuf.c, which may not be desirable as you pointed out in previous emails. So this brings up an interesting sg usage issue: can we use MAP_ANONYMOUS with SG_FLAG_MMAP_IO flag in SG_IO? Thanks, Fajun
Attachment:
sg_rbuf.c
Description: Binary data