|
|
Subscribe / Log in / New account

Might 2.6.35 be BKL-free?

By Jonathan Corbet
April 27, 2010
The removal of the big kernel lock (BKL) has been one of the longest-running projects in kernel development history. The BKL has been a clear scalability and maintainability problem since its addition in the 1.3 development series; efforts to move away from it began in the 2.1 cycle. But the upcoming 2.6.34 kernel will still feature a big kernel lock, despite all the work that has been done to get rid of it. The good news is that 2.6.35 might just work without the BKL - at least, for a number of configurations.

Over the years, use of the BKL has been pushed down into ever lower levels of the kernel. Once a lock_kernel() call has been pushed into an individual device driver, for example, it is relatively easy to determine whether it is really necessary and, eventually, get rid of it altogether. There is, however, one significant BKL acquisition left in the core kernel: the ioctl() implementation. The kernel has supported a BKL-free unlocked_ioctl() operation for years, but there are still many drivers which depend on the older, BKL-protected version.

Clearly, fixing the ioctl() problem is a key part of the overall BKL solution. To that end, Frederic Weisbecker and Arnd Bergmann posted a patch to prepare the ground for change. This patch adds yet another ioctl() variant called locked_ioctl() to the file_operations structure. The idea was to have both ioctl() and locked_ioctl() in place for long enough to change all of the code which still requires the BKL, after which ioctl() could be removed. This new function was also made dependent on a new CONFIG_BKL configuration option.

That patch did not get very far; Linus strongly disliked both locked_ioctl() and CONFIG_BKL. So the search for alternatives began. In the end, it looks like locked_ioctl() may never happen, but the configuration option will eventually exist.

Linus's suggestion was to not bother with locked_ioctl(). Instead, every ioctl() operation should just be renamed to bkl_ioctl() in one big patch. That would allow code which depends on the BKL to be easily located with grep without adding yet another function to struct file_operations even temporarily. A patch which does this renaming has been posted; this patch may well be merged for 2.6.35.

Or perhaps not. Arnd has taken a more traditional approach with his patch which simply pushes the BKL down into every remaining ioctl() function which needs it. Once a specific ioctl() function handles BKL acquisition itself, it can be called from the core kernel as an unlocked_ioctl() function instead. When all such functions have been converted, the locked version of ioctl() can go away, and the BKL can be removed from that bit of core code. The pushdown is a bigger job than the renaming, but it accomplishes a couple of important goals.

One of those goals is simply getting the BKL closer to the code which depends on it, facilitating its eventual removal. The other is to get that much closer to a point where the BKL can simply be configured out of the kernel altogether. That is where the CONFIG_BKL option comes in. Turning that option off will remove BKL support, causing any code which depends on it to fail to compile. That code can be annotated with its BKL dependency, again making it easier to find and fix.

On the face of it, configuring out the BKL may not seem like a hugely desirable thing to do; it takes little space, and the overhead seems small if nobody is actually using it. But there is small - but significant - savings to be had: currently the scheduler must check, at every context switch, whether the BKL must be released by the outgoing process and/or reacquired by the incoming process. Context switches happen often enough that it's worth making them as fast as possible; eliminating the BKL outright will make a small contribution toward that goal.

Making the BKL configurable will also be a motivating factor for anybody who finds that their BKL-free kernel build is blocked by one crufty old driver. Most of the remaining BKL-dependent drivers are unloved and unmaintained; many of them may be entirely unused. Those which are still being used may well be fixed once a suitably-skilled developer realizes that a small amount of work will suffice to banish the BKL from a specific system forevermore.

In the end, 2.6.35 will not be, as a whole, a BKL-free kernel. But, if this work gets in, and if some other core patches are accepted, it may just become possible to build a number of configurations without the big kernel lock. That, certainly, is an achievement worth celebrating.

Index entries for this article
KernelBig kernel lock
Kernellock_kernel()


to post comments

Might 2.6.35 be BKL-free?

Posted Apr 29, 2010 7:26 UTC (Thu) by cyrus (subscriber, #36858) [Link] (2 responses)

What about the BKL usage in the TTY-Layer? Hasn't Alan Cox promised to get rid of it for years?

Might 2.6.35 be BKL-free?

Posted Apr 29, 2010 18:15 UTC (Thu) by chad.netzer (subscriber, #4257) [Link] (1 responses)

Might 2.6.35 be BKL-free?

Posted Apr 30, 2010 1:09 UTC (Fri) by chantecode (subscriber, #54535) [Link]

Yeah, well, he actually continues to work on it :)

Might 2.6.35 be BKL-free?

Posted Apr 29, 2010 9:16 UTC (Thu) by arnd (subscriber, #8866) [Link] (1 responses)

There is a wiki page at http://wiki.kernelnewbies.org/BigKernelLock describing the other things that still need to be fixed before we can build a kernel without the BKL. We have patches for all of them, but there are still complications in the block, tty and fs/locks areas.

Note that the idea of the new ->locked_ioctl() operations was to replace the existing ->ioctl() one before 2.6.35-rc1, they were not meant to exist in parallel beyond that.

Pushing the BKL down with the new patches achieves everything that this would have done, and more, so the extra work was well worth it.

Might 2.6.35 be BKL-free?

Posted May 8, 2010 17:50 UTC (Sat) by pixelpapst (guest, #55301) [Link]

> Pushing the BKL down with the new patches achieves everything that this would have done, and more, so the extra work was well worth it.

Is seems however there is some resistance to this on Linus' part:
http://article.gmane.org/gmane.linux.kernel/978691

Or maybe Linus is only referring to 2.6.34 here, not entirely sure.

Might 2.6.35 be BKL-free?

Posted Apr 30, 2010 2:37 UTC (Fri) by RogerOdle (subscriber, #60791) [Link] (1 responses)

Why keep something around that is not really wanted? That only invites developers to periodically introduce new dependencies. You will eliminate in one release only to have to put it back in later.

It might be desirable to have an init option to enable or disable the BKL. It could make testing easier and faster.

Might 2.6.35 be BKL-free?

Posted May 1, 2010 1:42 UTC (Sat) by chantecode (subscriber, #54535) [Link]

>> Why keep something around that is not really wanted?

Because it might protect datas from concurrent accesses.

>> That only invites developers to periodically introduce new dependencies. >> You will eliminate in one release only to have to put it back in later

Not really. Most of the time, a new driver that uses the bkl will be spotted
and won't be merged, except may be for the llseek case, which is a bit particular.

>> It might be desirable to have an init option to enable or disable the BKL. It could make testing easier and faster.

The problem is not here. You don't catch every possible races by just testing without the bkl. When you kill the bkl at some places, you need to prove that what you are doing is safe, by explaining the locking involved and so. Testing is not sufficient.

Is 2.6.35 BKL-free?

Posted Aug 2, 2010 12:29 UTC (Mon) by jmayer (guest, #595) [Link] (1 responses)

So now that 2.6.35 has been released, what is the status of the BKL?

Is 2.6.35 BKL-free?

Posted Aug 2, 2010 12:54 UTC (Mon) by johill (subscriber, #25196) [Link]

$ git grep lock_kernel
...

evidently not.


Copyright © 2010, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds