Re: why mprotect(PROT_SEM) ?
Peter Waechtler <[email protected]>
| Newsgroups | gmane.linux.ngpt.devel |
|---|---|
| Message-ID | <[email protected]> |
"Dr. Uwe Girlich" schrieb: > > Hello list! > > In my quest to remove (or at least handle the size dynamically) of > /dev/shm/ngpt I just read about sys_futex.c/sys_futex_region() and found, it > calls in the end only > mprotect(area, size, PROT_READ|PROT_WRITE|PROT_SEM); > The read and write protection should be OK anyway (the file /dev/shm/ngpt > itself has access rights 666) so the only interesting point here is PROT_SEM. > This macro came new into the kernel with the futex patch. It is defined in > asm-(IBM-architectures)/mman.h as > > #define PROT_SEM 0x8 /* page may be used for atomic ops */ > > and used only once: in mm/mprotect.c/sys_mprotect() this new flag is also > allowed but nobody does anything with it. > > So what can we learn from this? Is this mprotect() call necessary at all? May > it be, that other architectures may need to prepare something more to allow > atomic operations in user pages? > In 2.4 the mprotect is necessary to prevent that the page gets evicted and paged in at different physical address. The physical address and offset is used as a hash for the futex. In 2.5 we have now a cache for mappings virtual -> physical with a callback notification. I hope that makes sense to you.