0

The library which I intend to use is, io_submit. Not to be confused with POSIX aio.

The iocb structure has a field, called as, aio_buf, which is the address( aligned) of a buffer.

On most examples on the internet, the way it has been shown is,

char data[4096];
struct iocb cb
cb.aio_buf = (uint64_t)data

Here is my problem:

There exists some other API already, which gives me aligned address. ( specifically a kernel driver, which maps into my address space ).

Here is what I am able to do:

char **someBuffer = new char*[someCount];
// in a loop 
someBuffer[loopCounter] = valloc(aLenght)
memcpy(someBuffer[loopCounter], someAddress, aLenght);
...
...
...
cbs[someCount].aio_buf = (uint64_t)(someBuffer[loopCounter])
...
...
...
...
...
...
... // looping ends
...
... 
...
...
call io_submit.

Here is what I want to do:

I want to avoid the new, memcpy, calls.

I know that the address is already memory aligned which is given to me.

But some basic understanding is missing on my part.

I have tried using io_submit using the addresses, but I get back the error (-14) [bad address] in the io_getevents call.

How Have I tried:

cb.aio_buf = (uint64_t) someAddress;

rrai
  • 23
  • 5
  • https://stackoverflow.com/questions/32612881/why-use-mm-malloc-as-opposed-to-aligned-malloc-alligned-alloc-or-posix-mem – stark Apr 15 '18 at 15:30
  • @stark I do not want to use any allocation. The kernel code which runs in my process's context only, and always, maps memory aligned address into my process address space. I am missing on some basic pointer understanding. – rrai Apr 15 '18 at 15:33
  • This `cb.aio_buf = (uint64_t)data` are you sure it's not `cb.aio_buf = (uint64_t *)data` ? Which if so would make your code `cb.aio_buf = (uint64_t *) someAddress;` – Richard Critten Apr 15 '18 at 15:39
  • @RichardCritten https://www.fsl.cs.sunysb.edu/~vass/linux-aio.txt Line 62, example 2 – rrai Apr 15 '18 at 15:43
  • Are you setting `aio_nbytes` to the correct value? – Clearer Apr 15 '18 at 16:39
  • @Clearer Yes. I am setting it to the correct value. – rrai Apr 15 '18 at 17:07
  • You might get better answers if you could also show the declaration and documentation of the memory mapping kernel call. – Sebastian Apr 15 '18 at 17:22
  • @Sebastian The kernel driver simply vm_mmap into my address space. And I get to know the address by an ioctl into the driver. As I have told, if I do a vmalloc on the address, and then do a memcpy, then give the address of the buffer into which I memcpy ied, then the io* calls work. I am missing something on pointers. – rrai Apr 15 '18 at 17:26
  • Is your mapped memory read-only, and io_submit tries to write? Or does the mapping not stay valid until io_submit is done using it (maybe asynchronously)? – Sebastian Apr 15 '18 at 17:40
  • @Sebastian No, that is not the case. Also, there is another ioctl which I have to call once I intend to inform the kernel module to to an unmap from the address space. And, I am not doing. – rrai Apr 15 '18 at 17:47

0 Answers0