📜 ⬆️ ⬇️

Optimize Linux for the desktop and games

In this article, I want to share almost 10 years of experience using Linux on a home computer. During this time I spent a lot of experiments on the kernel, tried various configurations for different applications and now I want to systematize all this into a long post with recommendations on how to squeeze the maximum out of linux and achieve excellent performance without having to buy powerful hardware.

Personally, I think the part where I wrote about kernel tuning is still a bit out of date and modern hardware already gives a priori the necessary performance for normal operation, but, as I was able to notice recently, games don't care, even now, there are problems, even on powerful hardware .

Although I promised that after reading this article, it will be possible to play Metro 2033 on a calculator (no joke, this will not happen), yet it will start with a recommendation to buy something from iron, if you don’t already have it.
')

1. Buy an SSD if you don't already have one


For some reason, many people are skeptical of SSD, although this is the first and most important component of a computer that is going to work quickly.

Seriously, everything that is described further in the article will give you some gain in performance and response time, but any, even the cheapest SSD, will reduce the launch time of most programs to 0 , which, visually, will be very noticeable. In almost any computer (and server), the main brake is always a disk subsystem and no HDD will ever give you the desired search speed (which, in an SSD, tends to 0 ms). For all the time of communication with computers and their upgrade, only the transition to SSD has given a significant increase in the speed of work and response. Remember how slow the floppy disks are, what a great search time they have? Something like this perceived hard drive after SSD.

So if you don’t have an SSD, then it makes no sense to continue, your computer (even if equipped with 12-core Xeon) will still work slowly, so go shopping.

Regarding reliability: there is a myth that SSDs die a year later. We owe its birth to the first SSD on SandForce chips. Naturally, any new SSD from the store is at least more reliable and durable than modern hard drives, so you shouldn’t worry about it at all. I bought my SSD 2 years ago used, at that time it was in use for a year. Now he has 11,681 hours of use and 10% resource utilization, so with the same usage regime, I will have enough for another 27 years. I think by this time the data storage technology has already changed several times. So again, reliability problems are more than contrived.

More details about the myths SSD comrade Vadim Sterkin wrote in his blog . True, his blog is about Windows, but essentially it does not change. I strongly advise you to read, very interesting.

In Ubuntu 14.04, SSDs work out of the box, the discard option is automatically registered in fstab, except that nothing else needs to be done .
In other distributions, you need to check if the partition has this option on the SSD. It is worth mentioning that this option only supports ext4. For other filesystems, you will have to use fstrim from the scheduler.

2. Partition table


Do not divide discs into partitions.

For a home computer, it is pointless and harmful. On the SSD you should have one partition for the root, there you will have the system and all the data stored. On the HDD (if needed) you should have one partition with a mount point in / mnt (I have / mnt / data), where large, under-used data (movies, music, games) will be stored. DO NOT need to make the HDD mount point / home, since in / home 99% of the programs store their data and constantly refer to them, therefore / home must be on the SSD.

I repeat briefly: on the SSD you should have everything that the system constantly refers to (writes / reads)!

Do not listen to harmful advice on the removal of such data on the HDD, as already mentioned, the problem of wear SSD is not, it is a myth, and a large number of recording cycles does not affect the durability of SSD. Once again I refer to the article by Vadim Sterkin, there it is all described in more detail and supported by explanations.

About the SWAP section: you do not need it. If you do not have enough RAM, then OOM-killer will nail resource-intensive applications, if this happens then purchase additional RAM, since its price does not bite much. Using swap as a memory expander slows down the computer considerably . There are many opinions that without SWAP there will be some problems, but IMHO, the roots of these conversations are growing from Win9x and today they are already myths, I personally did not notice any problems from rejecting SWAP. As proof: on the VPS now rarely see the connected SWAP and work the same somehow!
You don't need suspend-to-disk either, because a cold start with an SSD is faster than restoring from hibernation from an HDD, so use suspend-to-ram or turn off the computer completely. The only advantage of a swap is the ability to go into a hybrid hibernation, this is when the system prepares for suspend-to-disk, but performs suspend-to-ram, so later, if everything is good, there is a simple way out of hibernation, and if a power failure occurs then the system will recover from the disk.

I use the ext4 file system everywhere, since with others I couldn’t get a noticeable difference in performance, and ext4 is the most common, plus there are utilities for data recovery (but don’t rely on them, but make backups). When creating, use -T largefile or largefile4.

3. Use the 64-bit kernel


Little depends on the performance of the RAM, FPS in games will not increase from it and applications will not start faster. The use of 64-bit applications also does not give any gain for ordinary tasks, only for very specific mathematical calculations and archiving operations. Also, using the 64 core is not required to address more than 4 GB of memory, PAE allows you to address up to 64 GB of memory on a 32-bit system.

But using a 64-bit kernel, applications can address more than 4 GB of memory, which is quite useful, because otherwise there can be a situation when the OOM-killer nails programs, although there is still enough RAM. Also, on a 64-bit system, you can immediately address all physical memory, while on 32-bit everything above ~ 800 MB must be constantly re-installed, which somewhat reduces the speed of page exchange, although, as I said, this does not particularly affect the speed of work.

I also noticed the effect that the OOM-killer can nail processes that seem to have not yet taken 4 GB. I had this with some games. The problem was solved by the transition to 64 bits. So, without a 64-bit kernel, it's nowhere, even though it adds a small overhead to memory usage.

4. Use the pf-kernel patch


pf-kernel is a set of patches for the linux kernel, compiled by a Ukrainian Alexander Natalenko ( pfactum ) aimed at improving the desktop experience of linux systems.

It consists of:


The most useful patches are BFS and BFQ, about which there is already a lot written. BFQ is struggling with the problem of system brakes during large disk operations (the famous bug 12309, which is corrected according to the documents, but continues to plague in fact), BFS is a planning process that is more suitable for desktop work than those in the kernel. For example, CFS, which is used by default, allows a situation where 2 processes that require real-time priority will be executed on one core, while other cores are engaged in low-priority tasks. Naturally, this behavior leads to global brakes. But "an honest planner." BFS is not so “honest”, but it is much more close to the realities of desktop computers with a small (large is 4096) number of cores.

To install, I download the necessary kernel version without kernel stabilization patches from kernel.org and impose a pf-kernel on it. In general, it looks like this:

cd /usr/src
wget ftp://ftp.kernel.org/pub/linux/kernel/v3.x/linux-3.12.tar.xz
tar -xf linux-3.12.tar.xz
cd linux-3.12
wget https://pf.natalenko.name/sources/3.12/patch-3.12.4-pf.bz2
bunzip2 patch-3.12.4-pf.bz2
patch -p1 < patch-3.12.4-pf

, , . , , , , !

, , htop Dota 2 + The Sims 3 (multiseat):

image

25% ( 5- load-average) CPU . , , :(

5. !


, linux .

make xconfig



preemption, dynticks!

! , BFS « » . — , preemption .

, , preemption , , . , , 100% CPU, - . , WinXP , XP , , , , reset. , .

, , , .

Processor type and features Preemption Model No Forced Preemption (Server). «ocasional longer delays are possible» BFS . , «raw processing power».

, , Processor family .

, Timer frequency 300 HZ. 100 , ( ), . , 300 25 30, , ( . , + vsync).

, , hot-plug cpu , ( - ).

, , CPU Frequency scaling .

. , , «» . General setup -> Timers subsystem Timer tick handling Periodic timer ticks (constant rate, no dynticks).

BFQ

BFQ .

Enable the block layer -> IO Schedulers BFQ I/O scheduler BFQ hierarchical scheduling support, Default I/O scheduler , , BFQ.

6. Prelink


, . peter23.

7.


, — «» . , , - nVidia, -.

Geekbench 3 Steam gputest, :

3.14-pf:
Single-Core Score 2421
Multi-Core Score 8209
gputest: 3720 pts, 62 FPS

3.13-generic:
Single-Core Score 2646
Multi-Core Score 8414
gputest: 3713 pts, 61 FPS

Windows:
Single-Core Score 2572
Multi-Core Score 8242
gputest: 3634 pts, 60 FPS

, - «» CPU , GPU — . , . , 3.16, , . , Windows , 3D .

Source: https://habr.com/ru/post/234653/


All Articles