Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to optimize Linux server swap memory is too high

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to optimize the Linux server swap memory is too high, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Overview

I received a zabbix alarm today. It's a bit strange that swap uses a lot of memory, but it doesn't actually use much memory. Let's take a look at it:

1. View server memory usage

You can find that there is a lot of memory left, but swap has used 90% of it.

two。 View processes that take up too much swap

Normally, the use of swap should be 0, so when the remaining swap is less than 80%, we need to pay attention to which process takes up too much.

View the processes that consume too much swap with the following command:

For i in `cd / proc;ls | grep "^ [0-9]" | awk'$0 > 100' `; do awk'/ Swap:/ {aa=a+$2} END {print'"$I", a proc/$i/smaps 1024 "M"}'/ proc/$i/smaps; done | sort-k2nr

3. View the process

Check the pg database for no anomalies and no tasks running.

4. Configure kernel parameters to reduce swap usage

If the memory is large enough, you don't need to use SWAP partitions too much, you can change the value of swappiness. Swappiness=0 means to maximize the use of physical memory, followed by swap space, and swappiness=100 means to actively use swap partitions and move the data in memory to swap space in time.

In linux, the default setting of swappiness is equal to 60.

Now, in general, 1 G of memory can be modified to 10, 2 GB can be changed to 5, or even 0. Specifically, do this:

-- use memory as much as possible without swap echo "vm.swappiness=1" > > / etc/sysctl.conf sysctl-p-- refresh SWAP-- refresh SWAP (dump data in SWAP back to memory and empty data in SWAP) swapoff-a & & swapon-a-- Clean cache sync echo 3 > / proc/sys/vm/drop_caches

5. The result after processing

You can find that the problem has been solved.

This is the answer to the question about how to optimize the high memory of Linux server swap. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report