📜 ⬆️ ⬇️

Optimization and Acceleration N900

Probably everyone who actively uses the N900, faced with situations when the system began to slow down when copying large files over the network at high speed, or when after a week of active use, the overall system slowdown was noticeable and it was not possible to identify the culprit through top / htop save by rebooting. This is certainly not a problem, but as a fact is very unpleasant - not the Linux way, as it were.

But, as it turned out, this is solved. Since the time of N8xx, people have been actively experimenting with various settings of the Linux kernel, which will get rid of such things on mobile devices, and these settings, being empirically derived and tested, really do have a very good effect on the behavior of the system. So much so that the system continues to be very responsive, even when the Transmission torrent client is choking with joy, accepting files at full speed, and after a week of uptime, the system continues to work smoothly and even with 30 browser windows open, tasks are switched as well as with two it was impossible to observe until the system optimization method described below). And now to the point.

Who is too lazy to read and understand - put the Swappolube program from the repositories (now in extras-testing ) (“grease for swap”, literally), start and enjoy life. To whom not laziness - do the same and continue to read. :)

This program is just a GUI for changing the parameters of the kernel with the possibility of permanent saving. There is also a non-GUI version - swappolube-nogui. This program does not change any system files, does not overwrite anything - it only transfers the necessary parameters to the kernel through / proc and creates, if desired, a file in /etc/event.d, which will apply these settings every time it is loaded. At any time, changes can be rolled back either through the GUI, or by killing this file and rebooting the system - but this is hardly necessary, too many N900 users have already set it up and are not tired of writing reviews on the forums with the words smooth, speed increase and brilliant.

So, what are these parameters:
echo "30" > /proc/sys/vm/swappiness
echo "0" > /proc/sys/vm/page-cluster
echo "1" > /proc/sys/vm/laptop_mode
echo "1" > /proc/sys/vm/oom_kill_allocating_task
echo "0" > /proc/sys/vm/dirty_expire_centisecs
echo "0" > /proc/sys/vm/dirty_writeback_centisecs
echo "60" > /proc/sys/vm/dirty_background_ratio
echo "95" > /proc/sys/vm/dirty_ratio
echo "0" > /proc/sys/net/ipv4/tcp_timestamps
echo "1" > /proc/sys/net/ipv4/tcp_no_metrics_save

The first one, swappiness , is set to 100 by default on Maemo, which means that the system will try to flush the memory into the swap as often as possible and more. Here we change it to 30 (these are percentages) - which allows us to reduce the number of disk accesses (more precisely, to the eMMC flash drive that hosts the swap), and it is noticeable. Perhaps there are scenarios in which this will not be the most optimal solution, but in the overwhelming majority this is exactly what led to noticeable slowdowns during active work with the N900.

Next, page-cluster - this option controls the number of pages of memory that will be written to the swap at a time. The value “0” means 1 page, “1” - 2 pages, 2 - 4 pages, etc. by the exhibitor. By default, Maemo is set to 5 (32 pages). Perhaps on desktop systems this value is better increased, but on a mobile device one such recording cycle already gives a more noticeable slowdown in responsiveness, and with swappines = 100 it manifests itself in all its beauty. We put "1" - even if it is written longer in a swap, but imperceptibly for the user and without affecting the responsiveness of the UI.

The third parameter, laptop_mode - if not set to "0", then activates the delayed write to disk. Moreover, it activates quite cleverly, trying to isolate the so-called “periods of activity” of the system in order to use disk accesses as efficiently as possible. Roughly speaking - if we have memory pages waiting to be flushed to disk (swap or “dirty” - not yet synchronized disk buffers), do not start a write operation until the disk is accessed - this allows you to “group” write operations to disk, reducing the number of disk accesses, increasing the lifetime of flash memory and reducing power consumption (as far as I do not know, but the fact).
Four more are inextricably linked with this parameter:
dirty_expire_centisecs , dirty_writeback_centisecs are separate parameters for deferred flushing of dirty buffers. Laptop_mode set to 0 - laptop_mode now takes care of postponing (by default, set to 500 cps)
dirty_background_ratio , dirty_ratio - the minimum and maximum amount of memory (as a percentage of the total memory) that can be allocated to store dirty buffers. These parameters for me remain a slightly dark spot, but I will take a word from the maemo community. The default is set to 10 and 40, we set 60 and 95.

Further, oom_kill_allocating_task - changes the behavior of the "process killer" - OOM killer. Usually, when there is a shortage of memory (I have never happened on the N900, really), it kills the processes that sit in the background and eat the memory - and this can be any process in principle. This option forces him to kill the very process that is trying to get memory now and get an out-of-memory error. It sounds sensible, but apparently it does not really affect the overall performance of the system, only on critical states.

And the last two options apply to the TCP / IP stack:
tcp_timestamps - allows you to disable the addition of timestamps in TCP packets. As if saves both the processor and the place - in one package more will get. How really helps, I do not know. Does not seem to affect security.
tcp_no_metrics_save - says stack, do not cache last connections. May be useful for 2G / 3G networks.

In short, something like that.
In general, this is a summary - before you could safely judge the degree of system load by the speed of animation and the UI reaction, now the system behaves equally smoothly at almost any load.

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

All Articles