Linus Torvalds changed the page lock logic and replaced if with while

A few months ago, Linus Torvalds  rewritten the wait_on_page_bit_common() logic in Linux version 5.9 to solve the fairness of page lock competition.

Prior to this, the page lock holder would only wake up an exclusive process in the waiting queue (FIFO, and the process is executing "lock_page") when executing "unlock_page()", but the process may not be running, especially Under load conditions, it can only run if it obtains CPU time. At the same time, other running processes that have not entered the waiting queue can directly obtain page locks. Although this process still effectively uses the page, it will cause very unfairness. In case, the awakened waiting process finds that the page lock is not released after running, so it re-enters the waiting queue, and it is the last one. In extreme cases, the process may repeat the process to wait for tens of seconds.

Therefore,  Linus Torvalds is  modified to give the lock to the waiting process when it wakes up, regardless of whether it is running or not.

However, this did not completely solve the problem. Since then, BUG_ON() has occasionally occurred, because the above-mentioned "wait-to-set" process is not atomic, so the awakened process may still be "intervened by a third party". If you want to modify the "wait-to-set" process to an atomic operation, you need to modify about 50 functions. Therefore, last week, Linus Torvalds  changed the if in the wait_on_page_writeback () function to while to solve this problem. And this is basically back to the original situation, but it happens much less frequently, so it is still controllable.

However, according to foreign media reports , in the benchmark test on this version, the performance of PostgreSQL has dropped by 5%-10%. In this  regard , Linus Torvalds believes that this drop is not caused by the patch, and may be related to its test model or machine performance. related.

Linux 5.11-rc3 has been released, and interested students can conduct related tests.

For more details, see the following commit:

Guess you like

Origin www.oschina.net/news/126262/linus-torvalds-change-if-2-while