History

Avoid page waitqueue race leaving possible page locker waiting

The "lock_page_killable()" function waits for exclusive access to the page lock bit using the WQ_FLAG_EXCLUSIVE bit in the waitqueue entry set. That means that if it gets woken up, other waiters may have been skipped. That, in turn, means that if it sees the page being unlocked, it *must* take that lock and return success, even if a lethal signal is also pending. So instead of checking for lethal signals first, we need to check for them after we've checked the actual bit that we were waiting for. Even if that might then delay the killing of the process. This matches the order of the old "wait_on_bit_lock()" infrastructure that the page locking used to use (and is still used in a few other areas). Note that if we still return an error after having unsuccessfully tried to acquire the page lock, that is ok: that means that some other thread was able to get ahead of us and lock the page, and when that other thread then unlocks the page, the wakeup event will be repeated. So any other pending waiters will now get properly woken up.

Linus Torvalds committed 9 years ago

Commit a8b169a1 parent 3510ca21 file · +5 −4Browse files

Unified · Split

mm/filemap.c+5−4
@@ -986,10 +986,6 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q, · 985 unmodified lines
986986
987987 if (likely(test_bit(bit_nr, &page->flags))) {
988988 io_schedule();
989− if (unlikely(signal_pending_state(state, current))) {
990− ret = -EINTR;
991− break;
992− }
993989 }
994990
995991 if (lock) {
@@ -999,6 +995,11 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q, · 3 unmodified lines
999995 if (!test_bit(bit_nr, &page->flags))
1000996 break;
1001997 }
998+
999+ if (unlikely(signal_pending_state(state, current))) {
1000+ ret = -EINTR;
1001+ break;
1002+ }
10021003 }
10031004
10041005 finish_wait(q, wait);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t