What should I do if the memory of the Linux server is not enough?

As the server runs longer, its memory usage will gradually increase. If the server's memory is small, it is easy for the memory to become full, the system slows down, or even stuck. One way is to increase physical memory, but this involves costs, downtime, opening the case, and so on. Here is a solution for reference. If the effect is good, you don't need to buy a memory stick haha.

If you analyze the memory occupied by each process, and then add them together, you find that it is not equal to the total memory occupied. So why does the free -m command show that the remaining memory is so small? What is the memory used for?

It turns out that when the operating system is running, some data will be cached in the memory by itself, and in the result of free -m

-/+ buffers/cache: The following statistics are the status of cached data

image

The physical memory used by the cache plus the physical memory occupied by the process is the total physical memory.

In order to protect the service from being stuck due to high physical memory usage, you can schedule the crontab to clear the cache data of the operating system every hour. The configuration is as follows. Indicates that every time it reaches 45 minutes on the hour, execute

echo 3> /proc/sys/vm/drop_caches command to clear the operating system cache.

[root@localhost ~]# crontab -l

45 * * * * echo 3 > /proc/sys/vm/drop_caches

Facts have shown that clearing the cache not only does not reduce the speed of the system, but also significantly improves the speed. Of course, my experimental scenario is that the physical memory is originally small and only 8G, and the system access users are not large. There is no data to support whether other systems are applicable.


Guess you like

Origin blog.51cto.com/15080029/2642965