KernelNewbies:

The big kernel lock (BKL) is an old serialization method that we are trying to get rid of, replacing it with more fine-grained locking, in particular mutex, spinlock and RCU, where appropriate.

The BKL is a recursive lock, meaning that you can take it from a thread that already holds it. This may sound convenient, but easily introduces all sorts of bugs. Another problem is that the BKL is automatically released when a thread sleeps. This avoids lock order problems with mutexes in some circumstances, but also creates more problems because it makes it really hard to track what code is executed under the lock.

A number of areas need to take care of independently:

llseek

The problem is in the llseek callback of the struct file_operations. Drivers and filesystems implement it to move the file pointer.

The problem arises when it's not implemented by a driver or a filesystem. In this case, the vfs layer calls a default one called default_llseek() that just change the file pointer and does nothing else. But to protect against concurrent calls to llseek on a same file, default_llseek() protects protects this file pointer change using the BKL.

The thing is rather evil because not only do we have a lot of existing drivers that don't implement llseek, but also every new driver/filesystem that gets merged and that don't implement llseek falls back to the default_llseek() implementation.

It means two things: It can't stop bleeding and it does more and more. And we can't remove the bkl (or at least making it modular) until we get rid of default_llseek() (or at least making it modular :-).

So the strategy is to give a sane llseek implementation to these drivers, once there is no llseek stub, we can start punching default_llseek() (ie: making it modular => build it only if drivers depend on the bkl, or may be an even more granular dependency).

The sane existing implementations are the following:

ioctl

Like llseek, file_operations can contain a .ioctl callback. This is always called with the BKL held. In order to remove the BKL from the core VFS code, all file_operations should be converted to use the .unlocked_ioctl callback instead. This can be done in one of three ways:

TTY layer

Block layer

File locking (fs/flock.c)

super block operations

init/main.c


CategoryKernelProjects

KernelNewbies: BigKernelLock (last edited 2010-04-24 10:27:36 by arnd)