Linux free Memory Script

Source: Internet
Author: User

Tag: Free memory script    mysql out of memory   

VI recover_mem.sh#!/bin/bash  #系统分配的区总量  mem_total= ' free-m |grep mem | awk ' {print $  } '  #当前剩余的free大小  mem_free= ' free-m |grep mem | awk ' {print  $4} '  #当前已使用的used大小  mem_used= ' free-m |grep mem | awk ' {print
   $3} '   if ($mem _used!=0),  then #如果已被使用 calculates the percentage of the total amount currently remaining free, expressed in decimal notation, to complement an integer digit 0 mem_per=0 ' before the decimal point     echo "scale=2; $mem _free/$mem _total" | BC '  data= ' $ (date-d "Today" + "%y-%m-%d-%h-%m") Free percent is: $mem _per "Echo $DATA >>/var/log/mem_ The alarm value set by the detect.log# is 20% (i.e. alarm when using more than 80%).     mem_warn=0.20  #当前剩余百分比与告警值进行比较 (1 is returned when it is greater than the alarm value (that is, more than 20% remaining), and 0 is returned when it is less than (that is, less than 20%)     mem_now= ' expr $mem _per \ > $mem _warn '  #如果当前使用超过80% (i.e. the remainder is less than 20%, the above return value equals 0), free the Memory  if (($mem _now = = 0)); then       sync       Sync       echo 1 >/proc/sys/vm/drop_caches       # to free dentries and inodes:       echo 2 >/proc/sys/vm/drop_caches< c23/># to free Pagecache, dentries andinodes:       echo 3 >/proc/sys/vm/drop_caches  Fifi









Before Sh-x recover_mem.sh

[[email protected]]# free -M
              total       used       free      shared    buffers     Cached
mem:          15948      14774       1173           0         130       7926
-/+ buffers/cache:       6717        9231
swap:            0           0          0



After Sh-x recover_mem.sh

[[Email protected]]# free-m
Total used free shared buffers Cached
mem:15948 660393440 1 -
-/+ buffers/cache:6582 9365
swap:0 0 0



As you can see, the cache has been freed. It is important to note that after the cache is released, the impact on MySQL performance is more obvious, because MySQL needs to re-cache, so the script is only for emergency purposes, only when the remaining memory in free is less than 10%, the script will be executed to prevent oom kill the MySQL process, The most direct way is to add memory.

This article is from the "Age volt" blog, please make sure to keep this source http://suifu.blog.51cto.com/9167728/1828050

Linux free Memory Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.