FreeBSD: A Faster Platform For Linux Gaming Than Linux?

Written by Michael Larabel in Operating Systems on 7 September 2011 at 06:00 AM EDT. Page 1 of 6. 102 Comments.

FreeBSD provides a Linux binary compatibility layer that allows 32-bit Linux binaries to be natively executed on this BSD operating system. Linux binary compatibility on FreeBSD allows Linux-only applications to be executed in a near seamless manner on this alternative platform, even for games. New tests have revealed that the modern FreeBSD operating system (via PC-BSD 8.2) can actually outperform Linux when it comes to running OpenGL Linux game binaries.

This Linux binary compatibility support for FreeBSD is commonly referred to as "Linux emulation", but it is not emulating Linux in a traditional sense nor is it acting like Wine in user-space. This is a Linux ABI implementation for the FreeBSD kernel.

The FreeBSD Handbook covers Linux binary compatibility with how to enable the support under FreeBSD. Enabling the support requires loading a Linux KDO (kernel module) and altering the /etc/rc.conf. Linux run-time libraries also need to be installed, which can easily be done by using FreeBSD ports.

For this Phoronix benchmarking, PC-BSD 8.2 was used since its focus is on providing a pleasant FreeBSD desktop experience, complete with the KDE4 desktop environment by default. PC-BSD ships with Linux binary compatibility support enabled by default and a number of the Linux run-time libraries. During this testing only a few extra Linux run-time libraries had to be installed from FreeBSD ports like libvorbis, libasound, and SDL.

This support is available to users of FreeBSD on i386 and AMD64, but currently in mainline FreeBSD, it is limited to only supporting 32-bit Linux binaries. There has been experimental work on Linux x86_64 binary support, but nothing has yet been merged in stable form. Right now in FreeBSD 8.2 ports is an implementation based on the Linux 2.6 kernel and the user-space libraries are from Fedora 10.

There is this advanced page of the FreeBSD handbook covering the Linux emulation at a more in-depth level. The key section:

"When a system call is called by the Linux binary, the trap code dereferences the system call function pointer off the proc structure, and gets the Linux, not the FreeBSD, system call entry points.

In addition, the Linux mode dynamically reroots lookups; this is, in effect, what the union option to file system mounts (not the unionfs file system type!) does. First, an attempt is made to lookup the file in the /compat/linux/original-path directory, then only if that fails, the lookup is done in the /original-path directory. This makes sure that binaries that require other binaries can run (e.g., the Linux toolchain can all run under Linux ABI support). It also means that the Linux binaries can load and execute FreeBSD binaries, if there are no corresponding Linux binaries present, and that you could place a uname(1) command in the /compat/linux directory tree to ensure that the Linux binaries could not tell they were not running on Linux.

In effect, there is a Linux kernel in the FreeBSD kernel; the various underlying functions that implement all of the services provided by the kernel are identical to both the FreeBSD system call table entries, and the Linux system call table entries: file system operations, virtual memory operations, signal delivery, System V IPC, etc... The only difference is that FreeBSD binaries get the FreeBSD glue functions, and Linux binaries get the Linux glue functions (most older OS's only had their own glue functions: addresses of functions in a static global sysent[] structure array, instead of addresses of functions dereferenced off a dynamically initialized pointer in the proc structure of the process making the call)."


Related Articles