[linux] lock_kernel()

sergey_m

Я правильно догадываюсь, что эта фукнция означает взятие Giant lock?

Marinavo_0507

Да.

sergey_m

А это спинлок или слип?

Marinavo_0507

Это хитрый лок, я детали не знаю.
Ты читал unreliable locking guide, там вроде есть про него.
Можно например спать, пока его держишь.

sergey_m

Оттуда я почерпнул, что в ядре Linux есть спинлоки и семафоры. Скорее всего это спинлок.

Marinavo_0507

Вот немного про него нашёл:
The Big Kernel Lock
Linux contains a global kernel lock, kernel_flag, that was originally introduced in kernel 2.0 as the only SMP lock. During 2.2 and 2.4, much work went into removing the global lock from the kernel and replacing it with finer-grained localized locks. Today, the global lock's use is minimal. It still exists, however, and developers need to be aware of it.
The global kernel lock is called the big kernel lock or BKL. It is a spinning lock that is recursive; therefore two consecutive requests for it will not deadlock the process (as they would for a spinlock). Further, a process can sleep and even enter the scheduler while holding the BKL. When a process holding the BKL enters the scheduler, the lock is dropped so other processes can obtain it. These attributes of the BKL helped ease the introduction of SMP during the 2.0 kernel series. Today, however, they should provide plenty of reason not to use the lock.
Use of the big kernel lock is simple. Call lock_kernel to acquire the lock and unlock_kernel to release it. The routine kernel_locked will return nonzero if the lock is held, zero if not. For example:
lock_kernel;
/* critical region ... */
unlock_kernel;
Оставить комментарий
Имя или ник:
Комментарий: