2 futex questions
1) There's a comment in sys_futex(...) that says pos_in_page must not be on a page boundary. Could someone explain why?
2) How is this ever true:
pos_in_page + sizeof(int) > PAGE_SIZE
when checking if pos_in_page is valid?
Thanks,
Alfred Landrum
Quoted 2 lines · On Tue, 24 Sep 2002 [email protected] wrote:
1) There's a comment in
sys_futex(...)that sayspos_in_pagemust not be on a page boundary. Could someone explain why?
what it wants to say: 'the futex word must not overflow into the next page', ie. the futex word needs to be on a single page.
Quoted 3 lines
2) How is this ever true:
pos_in_page+ sizeof(int) >PAGE_SIZE
when checking ifpos_in_pageis valid?
the full test is this:
pos_in_page = ((unsigned long)uaddr) % PAGE_SIZE;
if ((pos_in_page % __alignof__(int)) != 0
|| pos_in_page + sizeof(int) > PAGE_SIZE)
return -EINVAL;what it says: 'uaddr must be naturally aligned, and the word must be on a single page'. In theory it's possible that __alignof__(int) != sizeof(int).
Ingo
Quoted 5 lines · Ingo Molnar
what it says: 'uaddr must be naturally aligned, and the word must be on a single page'. In theory it's possible that
__alignof__(int)!= sizeof(int).
Ok, would the following actually save some cycles then?
kernel/futex.c Tue Sep 24 18:09:09 2002 renamed from kernel/futex.c Tue Sep 24 15:25:01 2002 +3 -2
@@ -321,9 +321,10 @@ pos_in_page = ((unsigned long)uaddr) % PAGE_SIZE; - /* Must be "naturally" aligned, and not on page boundary. */ + /* Must be "naturally" aligned, and must not cross a page boundary. */ if ((pos_in_page % __alignof__(int)) != 0 - || pos_in_page + sizeof(int) > PAGE_SIZE) + || ((sizeof(int) != __alignof__(int)) + && (pos_in_page + sizeof(int) > PAGE_SIZE))) return -EINVAL; /* Simpler if it doesn't vanish underneath us. */
Alfred Landrum