Syllable Forum Index Syllable
Syllable Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

msync() with MS_ASYNC flag is not reliable

 
Post new topic   Reply to topic    Syllable Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Vanders
The Knights of Syllable


Joined: 14 Sep 2007
Posts: 849

PostPosted: Tue Oct 11, 2011 3:40 pm    Post subject: msync() with MS_ASYNC flag is not reliable Reply with quote

Flicking over some (of my own) code earlier I noticed that msync() makes use of aio_write_pos_p() to queue an async write in an attempt to clear the flush. There are two immediate problems I noticed:

1. If MS_ASYNC is set the PTE_DIRTY flag is cleared on the page before the async write may have completed I.e. msync() acts as though every page write is synchronous.
2. aio_write_pos_p() flat out doesn't work if if the async request has come from the kernel: aio_create_context() looks for the symbol __aio_callback, which only exists in Glibc. However this is a kernel initiated async I/O request, so the callback shouldn't be going to userspace.

I'm not sure what happens if __aio_callback() is invoked in Glibc when no user-space AIO has been initiated but it may not be good.
Back to top
View user's profile Send private message Send e-mail
Vanders
The Knights of Syllable


Joined: 14 Sep 2007
Posts: 849

PostPosted: Fri Apr 13, 2012 8:36 am    Post subject: Reply with quote

#2 above is a non-issue:

a) The process calls msync(MS_ASYNC) from user space
b) The kernel invokes aio_write_pos_p()
c) aio_write_pos_p() calls aio_insert_op(), which checks for a current AIO context. If none exists, it calls aio_create_context()
d) aio_create_context() creates a thread who's entry point is the user-space __aio_callback() function. All this does is immediately invoke the aio_worker syscall, so we come back into the kernel at sys_aio_worker()
e) do_aio_worker() consumes AIO requests inserted by aio_insert_op() (which may well have come from the kernel via. aio_write_pos_p(), but the source doesn't matter). do_aio_worker() even checks if the AIO operation is from the kernel and does the right thing.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Syllable Forum Index -> Bugs All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group