Compile and Optimize the Xanmod Linux Kernel for Debian and Derivatives

article #1365, updated 15 days ago

Compiling a kernel does give you lots of added speed and memory-efficiency, if you do it right. Here’s one way way to do it right. I’m using it most joyfully on MX Linux, on two very different machines, right now. The steps below are for Debian and derivatives only. Manjaro has an AUR package called linux-xanmod.

  1. First enable sources for the kernel in the package manager. Not sure how this is done in Ubuntu. In close Debians, check /etc/apt/sources.list.d/debian.list, make sure the deb-src lines are not commented out. That means if you see any lines like this:
#deb-src http://deb.debian.org/debian buster main contrib non-free

make them look like this:

deb-src http://deb.debian.org/debian buster main contrib non-free
  1. Next step is to have apt take in all standard packages for kernel building (the third line is specified as for 64-bit Wintel hardware):
sudo apt-get update
sudo apt-get install build-essential bison flex pkg-config qtcreator qt5-default qttools5-dev-tools libssl-dev
sudo apt-get build-dep linux-image-amd64
  1. Now we create a folder and clone the current Xanmod source into it:
cd
mkdir custom-kernel-xanmod
cd custom-kernel-xanmod
git clone https://github.com/xanmod/linux.git xanmod
  1. And now we get down to business. We enter the source tree, and compile a GUI configurator, xconfig.
cd xanmod
make clean
make xconfig
  1. After xconfig has been made, it will bring up a GUI. The GUI has a search capability (thank God for his often unaware servants), you’ll want to search (Control-F) for the following:
  1. HZ_1000 is a setting which is highest of five, expressed as “1000 HZ”. It is timer interrupts per second. For non-desktop systems, 500 is often recommended. For anything desktop or multimedia, use 1000.
  1. CONFIG_MNATIVE is a setting which is bottom-most of a long list of specific CPU models. Unlike the others, this setting tells the compiler to optimize its output for the specific CPU in the very machine which this procedure is being run on. Using this will invariably get you a very, very fast kernel for this machine. Don’t try to use this kernel on a different machine, unless you know for certain that the different machine has exactly the same CPU.
  1. I have found the two above to produce really great performance. The third one I use, CC_OPTIMIZE_FOR_SIZE, is a non-default setting whose opposite is CC_OPTIMIZE_FOR_PERFORMANCE, and they mean what they say. In Debian, Ubuntu, Manjaro, and Arch Linux, I optimize for size in 8 or less gigabytes of RAM, and for performance in more; in antiX and MX Linux, I optimize for size in less than 4 gigabytes of RAM, they have been handling an amazing number of Chrome tabs (a nice practical test) in just 4G RAM. That is an amazing disparity, but as of this writing (March of 2020) this is what I have been finding.
  1. File/Save, File/Exit, or Control-S then Control-X.
  1. Run ‘htop’, to see how many apparent CPU cores are available. Add 1 to this number. Let’s say the result is 3.
  1. Compile the kernel. Notice the 3, you’ll want to replace this with the calculated number. This sets up the compilation to use all of your CPU cores at maximum efficiency, and speeds up the process according to what you have.
make -j3 deb-pkg LOCALVERSION=-xanmod-1000-native
  1. Unless it failed for some reason, the .deb packages are one level above in directories. Go there and install:
cd .. 
sudo dpkg -i linux-image*.deb linux-headers*.deb
  1. You can then boot and use Tab before the kernel loads to choose the new kernel. Or, you may want to install and use grub-customizer to choose the new kernel as standard.

Categories: