Boost system performance with Linux kernel recompilation/optimisation

1
27081

Are you facing performance issues with your old system, but don’t want to spend money buying a new one? The techniques mentioned in this article could boost your system’s performance by just making a few minor changes in the Linux operating system. 

Linux is growing by the day, through the development of yet more distributions and new features. It is being used by almost all companies, and these firms need good system performance to efficiently achieve their goals. Currently, Linux distributors provide generic operating systems for different types of computer hardware specifications. We get good performance when there is a combination of good hardware and software. In case hardware is costly for the system, we need to focus on software. The aim of this article is to increase the performance and booting time of a specific system, as well as to ensure kernel optimisation and proper utilisation of system resources.

To boost the performance of a system, we just need its hardware and software components to operate efficiently. Linux is an open source operating system and anyone can modify its core components. Linux distributors provide a generic operating system for all the hardware. In that OS, some packages are not useful for some users and unnecessarily take up system resources, reducing its performance. We can improve a system’s performance by focusing on both the hardware and software components.

If we consider hardware resources, we may need to buy new, powerful hardware, which can be expensive and will make the old hardware useless. Not only will we incur additional costs, but also unnecessarily generate e-waste.
On the other hand, software is an important parameter for performance enhancement. Software coding improves hardware performance and removes unnecessary stuff from the system. Hardware can be optimised only up to a certain level to improve a system’s performance. But with the use of the appropriate software, the performance levels of hardware can be increased and much greater performance can be extracted from it.

A word of caution here, though. Once the hardware is optimised (by using the right software) to operate at a higher level, the performance of the system will be enhanced but can affect the hardware. The hardware may heat up and, in the worst cases, this could damage the whole system.

Good performance = Good software + Good hardware 
The following are the parameters on which the performance of the system depends:
1. CPU frequency and architecture, along with the number of cores
2. Cache memory
3. File system
· EXT2
· EXT3
· ReiserFS
· EXT4
· BTRFS
4. Data structure
5. Kernel recompilation
6. Network parameters
· I/O
· TCP/IPs
7. Disk and memory usage optimisation
8. Information about graphics operations and performance
9. System logs
10. Boot process
11. Power consumption

The performance of different hardware varies based on the operating systems. But on the same hardware, the major Linux OSs like Ubuntu, Red Hat, Debian, Solaris, etc, perform differently because they have their own process execution techniques and methods. OS performance depends on internal architecture, system calls, context switching, file reading/creating/deleting, kernel compilation, system version, file system, etc.

System information

Figure 1 shows the processing parameters for system configuration, on which testing is done.

Figure 1
Figure 1: System configuration

Parameters that reduce system performance

CPU frequency and number of cores

Processor families like Intel, AMD, SPARC, etc, have various process architectures with a range of frequencies. Processors with a good frequency and architecture give the best performance. Nowadays, processors have specific frequency units in GHz, which was not the case earlier. Earlier generations of processors had processing frequencies measured in MHz, so gaps in the performance of the CPU unit could be seen and analysed easily. CPU performance metrics are based on the following parameters.

i. Response time

  • Processing speed
  • Channel capacity
  • Latency
  • Bandwidth
  • Throughput

ii. Power consumption

iii. Environmental impact

The amount of time taken by any processor or task can be termed as ‘performance’, which does not mean clock frequency alone or the number of instructions executed per clock cycle, but is the combination of clock frequency and instructions per clock cycle:

P = I * F
…where, P = performance, I = instructions executed per clock cycle and F= frequency

Performance testing on the cores of the CPU: A system has two cores, and when one core is being used and the other is disabled, the command for this process is:

nano /sys/devices/system/cpu/cpu1/online

Case 1, when both cores are enabled, is shown in Figure 2.

Figure 2
Figure 2: When both cores are enabled

The execution times of Gzip and Apache server are 455.71 and 73.78 seconds, respectively, as shown in Figures 4 and 6.
Case 2, when only one core is enabled, is shown in Figure 3.

Figure 3
Figure 3: When only one core is enabled
Figure 4
Figure 4: Compression of Apache when two cores are enabled

The execution times of Gzip and Apache server are 847.36 and 175.55 seconds, respectively, as shown in Figures 5 and 7.

Figure 5
Figure 5: Compression of Apache when one core is enabled
Figure 6
Figure 6: Compression of Apache when one core is enabled
Figure 7
Figure 7: Compression of Apache when one core is enabled

Apache build testing: This test shows how long it takes to build the Apache HTTP server.
Gzip compression testing: This test shows how long it takes to do Gzip compression of files.

File systems

In the file system, it is important to know how to handle the file and its allocation within the memory. In the file system, the memory is fully responsible for resource management, its usage, processing and retrieval whenever the file is needed by the user. Without the file management, the hardware is simply a bunch of circuits with no knowledge of the file’s location, its starting address and ending address.

Different types of file systems like Ext2, Ext3, Ext4, ReiserFS, FAT and NTFS have various performance levels.
Figure 8 shows the read/write process on the respective file systems. In this graph, Ext versions perform differently on the same hardware. In this figure, it can be seen that the reading/writing speed changes based on the Ext version. Reading and writing speed is measured in Mb/second.

Figure 8
Figure 8: File system performance chart

Boot time

Boot speed matters a lot in the case of operating systems, and problems often arise during booting. The application that one chooses to be configured on the system start-up dictates the boot speed of Linux based systems.
Some applications are not useful for the average user. Often, these applications reduce the boot time of the system. Set these applications on a manual mode, which means they will not be starting up at the boot time. The default boot time of the system is approximately one minute, which is shown in Figure 9. If you need these applications, start them manually from the command line. The unnecessary applications are:

  • Bluetooth
  • Cups and Cups-browser
  • Console
  • irqbalance
  • cron, etc
Figure 9
Figure 9: Default OS boot processes

The correct way to disable an upstart service is as follows:

echo ”manual” >> /etc/init/myjob.conf

Now, the upstart services will not start automatically.
When the unnecessary applications mentioned above were closed, the boot time recorded was approximately 45 seconds, which is shown in Figure 10.

Figure 10
Figure 10: Modified boot processes

Kernel recompilation/optimisation

The kernel provided by all distros is probably the best one for almost everybody. The Linux kernel is compiled in many different ways. Recompiling the kernel can decrease kernel size and its overall behaviour. Changing certain parameters in the source code might also yield some change in the system’s performance. Recompile the Linux kernel with different options, install it and then boot the system from it.

Kernel recompilation steps: Download the kernel from the official site, as follows:

linux-4.2.1.tar 
cd /usr/src/ 
tar xf /path/to/linux-4.2.1.tar

Clear the old object files or configuration information, as follows:

make mrproper

In the kernel configure menu list, choose which features and drivers you need to compile, as follows:

make menu config make clean
make depend

After configuring the kernel, make a compressed image of the kernel, as shown below:

make bzImage 
ls -l arch/x86/boot/bzImage

Compile the kernel modules, as follows:

make modules

Runnable kernels are expected to be in the /boot directory.

cp arch/x86/boot/bzImage /boot/vmlinuz-4.2.1

To install kernel modules in the /lib/modules/ directory, use the following command:

make modules install

Set the initrd image of the kernel that provides the initial file systems that get loaded into memory during the Linux startup process, as follows:

mkinitrd or initramfs /boot/initrd-4.2.1.img 4.2.1

After installing the kernel, the GRUB file has to be modified because it contains the details of the kernel’s local directory and version:

sudo update-grub

Power consumption

For power saving in the Linux kernel, TLP can be used. Again, for every kernel job, root privileges are needed. TLP will increase the battery life using the default configuration with the AC and electric battery mode enabled. In AC mode, performance is the most well-liked, whereas in battery mode, power savings is a major concern. TLP accomplishes power saving with the help of dynamic, varied states and timeouts of assorted system devices to scale back the power they draw.

System logging activity

In a default distro installation, complete system logging is regularly arranged. This is suitable for a server or multi-client system. In any case, on a single client system with steady composition, the numerous system log documents will bring about decreasingly intuitive system execution, and lower logging movement will be advantageous for execution and the lifetime of the flash memory. Similar kernel messages are signed in both kern.log and syslog.

Tools to help you analyse performance
Phoronix Test Suite: The Phoronix Test Suite (PTS) is a free, open source benchmark software for Linux and other operating systems. It is the most comprehensive testing and benchmarking platform available and provides an extensible framework for testing.

Bootchart: Bootchart is a tool for performance analysis and visualisation of GNU/Linux.
Jmeter: This is a 100 per cent pure Java application for load and performance testing. Jmeter is designed to cover categories of tests like load, functional, performance, regression, etc, and requires JDK 5 or higher version.
top: This displays a listing of the most CPU-intensive tasks on the system, and can provide an interactive interface for manipulating processes. It can sort the tasks by CPU usage, memory usage and runtime.
IOzone: IOzone is a file system benchmark tool. The benchmark generates and measures a variety of file operations. It has been ported to many machines and runs under many operating systems.

1 COMMENT

  1. Nice optimization tips, The CPU optimization technique is really good with simply enabling the core settings, but on software level apache needs to be optimized as apache manage sessions served by threads with Multi-Processing Module (aka MPM).

LEAVE A REPLY

Please enter your comment!
Please enter your name here