sysctl修改内核参数 重启不生效

Posted ygtff

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sysctl修改内核参数 重启不生效相关的知识,希望对你有一定的参考价值。

现象

  • 在尝试解决VM hung死问题时,需要修改内核参数 vm.dirty_ratio, 所以就遇到了在/etc/sysctl.conf中修改后,直接sysctl -p,参数修改OK:
  • 但是,重启机器后,这些参数又是默认值,并没有生效:

问题分析解决

  • Google发现tuned服务会动态调整系统参数的,那么如果我设置的参数被动态调整了所以不生效。
    所以,我们现在看看tuned配置中有没有修改上面提到的参数:

    [root@ceph2 lib]# cd /usr/lib/tuned/
    [root@ceph2 tuned]# grep "vm.dirty_ratio" * -R
    latency-performance/tuned.conf:vm.dirty_ratio=10
    throughput-performance/tuned.conf:vm.dirty_ratio = 40
    virtual-guest/tuned.conf:vm.dirty_ratio = 30


  • 有3处覆盖sysctl.conf中的参数:

    • 我们来看看virtual-guest/tuned.conf:

      #
      # tuned configuration
      #
      
      [main]
      include=throughput-performance
      
      [sysctl]
      # If a workload mostly uses anonymous memory and it hits this limit, the entire
      # working set is buffered for I/O, and any more write buffering would require
      # swapping, so it's time to throttle writes until I/O can catch up.  Workloads
      # that mostly use file mappings may be able to use even higher values.
      #
      # The generator of dirty data starts writeback at this percentage (system default
      # is 20%)
      vm.dirty_ratio = 30
      
      # Filesystem I/O is usually much more efficient than swapping, so try to keep
      # swapping low.  It's usually safe to go even lower than this on systems with
      # server-grade storage.
      vm.swappiness = 30


    • 在main域中,先加载了throught-performance,从字面来看就是提高吞吐性能的:

      #
      # tuned configuration
      #
      
      [cpu]
      governor=performance
      energy_perf_bias=performance
      min_perf_pct=100
      
      [disk]
      readahead=>4096
      
      [sysctl]
      # ktune sysctl settings for rhel6 servers, maximizing i/o throughput
      #
      # Minimal preemption granularity for CPU-bound tasks:
      # (default: 1 msec#  (1 + ilog(ncpus)), units: nanoseconds)
      kernel.sched_min_granularity_ns = 10000000
      
      # SCHED_OTHER wake-up granularity.
      # (default: 1 msec#  (1 + ilog(ncpus)), units: nanoseconds)
      #
      # This option delays the preemption effects of decoupled workloads
      # and reduces their over-scheduling. Synchronous workloads will still
      # have immediate wakeup/sleep latencies.
      kernel.sched_wakeup_granularity_ns = 15000000
      
      # If a workload mostly uses anonymous memory and it hits this limit, the entire
      # working set is buffered for I/O, and any more write buffering would require
      # swapping, so it's time to throttle writes until I/O can catch up.  Workloads
      # that mostly use file mappings may be able to use even higher values.
      #
      # The generator of dirty data starts writeback at this percentage (system default
      # is 20%)
      vm.dirty_ratio = 40
      
      # Start background writeback (via writeback threads) at this percentage (system
      # default is 10%)
      vm.dirty_background_ratio = 10
      
      # PID allocation wrap value.  When the kernel's next PID value
      # reaches this value, it wraps back to a minimum PID value.
      # PIDs of value pid_max or larger are not allocated.
      #
      # A suggested value for pid_max is 1024 * <# of cpu cores/threads in system>
      # e.g., a box with 32 cpus, the default of 32768 is reasonable, for 64 cpus,
      # 65536, for 4096 cpus, 4194304 (which is the upper limit possible).
      #kernel.pid_max = 65536
      
      # The swappiness parameter controls the tendency of the kernel to move
      # processes out of physical memory and onto the swap disk.
      # 0 tells the kernel to avoid swapping processes out of physical memory
      # for as long as possible
      # 100 tells the kernel to aggressively swap processes out of physical memory
      # and move them to swap cache
      vm.swappiness=10

       

  • 所以要想让vm.dirty_ratio这个参数成为我们想要的10,可以通过以下方法解决:
    • 在sysctl.conf中添加vm.dirty_ratio参数,并禁止tuned服务启动。
    • 直接在tuned.conf中修改vm.dirty_ratio参数
    • 在sysctl.conf中添加vm.dirty_ratio参数,然后在rc.local中增加sysctl -p使其生效

链接

http://ssdxiao.github.io/linux/2017/03/20/Sysctl-not-applay-on-boot.html

以上是关于sysctl修改内核参数 重启不生效的主要内容,如果未能解决你的问题,请参考以下文章

Linux 修改 内核参数sysctl.conf及ulimits.conf参数快速生效

Linux 修改 内核参数sysctl.conf及ulimits.conf参数快速生效

Oracle中的sysctl.conf内核参数

Linux 系统调整内核参数

linux 内核参数优化

Linux内核参数--time-wait回收--不建议设置