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 deal with Linux memory exception

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces how to deal with Linux memory exception problem, the article is very detailed, has a certain reference value, interested friends must read it!

1. Check the usage of system memory

From it, we can see that the total memory size of the system is 31g, 21G has been used, and 2G Magi swap of the free 9G memory cache is not in use yet.

Click (here) to collapse or open

Free-g

Total used free shared buffers cached

Mem: 31 21 9 0 0 2

-/ + buffers/cache: 19 11

Swap: 3 0 3

2. Check the memory usage of the system process.

Sorted by top simple M according to memory usage, the largest memory usage of the system is 245m, and the overall use will not exceed 19G.

Click (here) to collapse or open

Top-17:59:04 up 6:44, 1 user, load average: 0.00,0.00,0.00

Tasks: 199 total, 1 running, 197 sleeping, 0 stopped, 1 zombie

Cpu (s): 0.1%us, 0.2%sy, 0.0%ni, 99.6%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

Mem: 32864556k total, 22515836k used, 10348720k free, 71220k buffers

Swap: 4128760k total, 0k used, 4128760k free, 2101028k cached

PID USER PR NI VIRT RES SHR S CPU MEM TIME+ COMMAND

2892 oracle 20 0 211m 13m 9888 S 0.0 0.0 0:01.16 tnslsnr

2978 oracle 20 0 211m 13m 9888 S 0.0 0.0 0:01.17 tnslsnr

1353 root 20 0 53088 9312 6396 S 0.0 0.0 0:00.02 VGAuthService

1332 root 20 0 164m 7784 4572 S 0.0 0.0 0:12.95 vmtoolsd

1423 root 20 0 199m 5244 4344 S 0.0 0.0 0:07.58 ManagementAgent

72153 root 20 0 98.1m 4016 3028 S 0.0 0.0 0:00.24 sshd

72157 root 20 0 105m 1960 1544 S 0.0 0.0 0:00.14 bash

1550 root 20 0 245m 1744 1104 S 0.0 0.0 0:00.11 rsyslogd

3. Further check the memory usage of the system through the script

View the maximum memory used by all PID and the current value

Click (here) to collapse or open

For pid in `ls / proc/ | grep "^ [0-9]" `; do echo $pid;cat / proc/$ {pid} / status | grep VmPeak | awk-fanglu'{print $2}'| grep-v "^ $| ^ #" | sort-nk 1; done

For pid in `ls / proc/ | grep "^ [0-9]" `; do echo $pid;cat / proc/$ {pid} / status | grep RSS | awk-fanglu'{print $2}'| grep-v "^ $| ^ #" | sort-nk 1; done

4. Through the above two memory views, we can basically rule out that the process takes up a lot of system memory, so what else can we think of that will lead to a large amount of system memory?

Since these servers are virtual machines, I wonder if it is the memory footprint caused by the sharing of physical memory. (since I don't have the host, this is not easy to troubleshoot.)

Or is it possible that some memory is occupied and the system memory is occupied due to unreleased memory? (after rebooting the server, it is found that there is a startup in the system and 19G is occupied)

Or is it a system parameter setting that causes the system memory to be allocated when it is started? (thinking of hugepage may cause this kind of problem)

5. Check whether hugepage is enabled.

# cat / sys/kernel/mm/redhat_transparent_hugepage/enabled (other non-rhel linux can use cat / sys/kernel/mm/transparent_hugepage/enabled)

[always] madvise never

It is found that the system has opened a large transparent page, and further confirm it with the following command

# cat / proc/meminfo | grep-I huge

AnonHugePages: 0 kB

HugePages_Total: 9732

HugePages_Free: 9732

HugePages_Rsvd: 0

HugePages_Surp: 0

Hugepagesize: 2048 kB

6. Close Hugepage and free memory

Vi / etc/sysctl.conf

# vm.nr_hugepages = 9732 comment out or delete the configuration with a large number of pages, and then make it effective through sysctl-p

Vi / etc/security/limits.conf

# oracle soft memlock unlimited # # user memory lock limit is commented out

# oracle hard memlock unlimited

Restart OS to check whether the system memory is normal and whether the big page is closed.

Free-g

Cat / sys/kernel/mm/redhat_transparent_hugepage/enabled

Cat / proc/meminfo | grep-I huge

7. Hugepage Appendix

(1) advantages and disadvantages of enabling hugepage

Advantages: improve the hit rate of TLB, take advantage of the feature that HugePages will not be Swap to ensure that memory will not be swapped into Swap

Disadvantages: take up a large amount of system memory, even if you can't afford any application, it will also take up a fixed size of system memory.

(2) use to open large page scenarios

The shared memory is set to more than 8 gigabytes and needs to be processed by big data to ensure that the data is not frequently swap in memory.

(3) View system page size and system block size

Getconf PAGESIZE

Tune2fs-l / dev/sda1 | grep 'Block size'

(4) default size and quantity settings for large pages

The default size of large pages is 2m, and the number of large pages can be set with / etc/sysctl.conf vm.nr_hugepages = 9732. The total size of large pages is 9732mm 2ax 1024mm 19G.

These are all the contents of the article "how to deal with Linux memory anomalies". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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