Nulik
Nulik

Reputation: 7380

Are io_submit writes() guaranteed to be executed in order?

Does io_submit() system call in Linux guarantees the order of the execution of each operation submitted by multiple sequential io_submit()s by the same process ?

Consider the following example: I submit some write() operations on a file descriptor , like:

io_prep_pwrite(iocb_ptrs[0],fd,&buf1,buf1_len,buf1_offset);
io_prep_pwrite(iocb_ptrs[1],fd,&buf2,buf2_len,buf2_offset);
io_submit(ctx,2,&iocb_ptrs[0]);

Just immediately after submitting the first io_submit the process submits data again:

io_prep_pwrite(iocb_ptrs[2],fd,&buf3,buf3_len,buf3_offset);
io_prep_pwrite(iocb_ptrs[3],fd,&buf4,buf4_len,buf4_offset);
io_submit(ctx,2,&iocb_ptrs[2]);

If the buf3_offset happens to be the same value as buf1_offset, does the possibility of overwrite of the data in buf3 by the data in buf1 exists ? Consider that we have a multicore system and the process that does aio submission is running on the core1. (note: we have only one user process) First io_submit() happened and the core1 started to write the data to disk. But then an network interrupt occurs and the core1 has to stop the first io_submit() to attend the interrupt. Now, the core2 is idle , it takes the second io_submit() call and sends the data to disk. When core1 returns from the interrupt it will continue to work on the the first io_submit() and the data that I asked the process to write first, will actually be written last.

Can this happen ?

Upvotes: 0

Views: 876

Answers (1)

rici
rici

Reputation: 241881

I don't know what happened to this manpage with an overview of linux async io, but it clearly states that "the operations are carried out in arbitrary order and more than one operation for one file descriptor can be started." So it seems like your nervousness is justified.

Upvotes: 3

Related Questions