Configure system memory capacity

These kernel parameters may help improve the memory utilization of the system. These parameters are temporarily set for testing purposes by changing the values ​​of the corresponding files in the /proc file system. After determining the best performance values ​​for the use case, you can use the sysctl command to set them permanently.

Usually configure the memory usage by setting the value of one or more kernel parameters. You can temporarily set these parameters by changing the contents of the files in the /proc file system, or you can use the sysctl tool provided by the procps-ng software package Set these parameters permanently.

For example, to temporarily set the overcommit_memory parameter to 1:

1
echo 1> /proc/sys/vm/overcommit_memory

To set this value permanently, add vm.overcommit_memory=1 to the /etc/sysctl.conf file and then run:

Temporary setting of parameters is very useful for determining the impact of parameters on the system. Then, when it is determined that the value of the parameter has the desired effect, the parameter can be set permanently.

virtual memory parameters

Unless otherwise specified, the listed parameters are located in /proc/sys/vm< /code>in.

  • dirty_ratio

    Percentage value. When the percentage of total system memory is modified, the system starts to use pdflush The operation writes the modification to the disk. The default is 20%.

  • dirty_background_ratio

    Percentage value. When the percentage of the total system memory is modified, the system starts to write the modification to the disk in the background. The default value is 20%.

  • overcommit_memory

    Define the conditions for accepting or rejecting large memory requests.

    The default value is 0. By default, the kernel performs heuristic memory overcommitment processing by estimating the amount of available memory and excessive request failures. However, because memory is allocated using heuristics rather than precise algorithms, memory can be reloaded with this setting.

    When this parameter is set to 1, the kernel does not perform memory overcommitment processing. Increases the possibility of memory overload, but improves the performance of memory-intensive tasks.

    When this parameter is set to 2, the kernel rejects memory requests equal to or greater than the total available SWAP space and overcommit_ratio The sum of the percentages of the specified physical RAM. This can reduce the risk of overuse of memory, but it is recommended only for systems where the swap area is larger than the physical memory.

  • overcommit_ratio

    Specify the percentage of physical RAM considered when overcommit_memory is set to 2. The default is 50%.

  • max_map_conut

    Define the maximum number of memory mapping areas that the process can use. The default is 65545, which is suitable for most situations. If the program needs to map more than this number of files, increase this value.

  • min_free_kbytes

    Specify the minimum number of kilobytes to remain free in the system. This is used to determine the appropriate value for each low-memory area, each low-memory area is allocated multiple reserved memory free pages in proportion to its size.

Extreme values ​​may damage the system. Setting min_free_kbytes to a very low value can prevent the system from reclaiming memory, but this may cause the system to hang and OOM to terminate the process. However, setting min_free_kbytes too high (for example, occupying 5%-10% of the system's total memory) will cause the system to immediately enter a state of insufficient memory, which will cause the system to spend too much time to reclaim the memory.

  • oom_adj

    If the system memory is insufficient and the panic_on_oom parameter is set to 0, the oom_killer function will terminate the process, knowing that the system can recover from the process with the highest oom_score.

    The oom_adj parameter helps to determine the oom_score of the process. This parameter is set according to the process identifier. Set to 17 to disable the process oom_killer. Other valid values ​​are from -16 to 15.

    The process generated by the adjusted process will be integrated with the process Large column oom_score that configures the system memory capacity.

  • swappiness

    swappiness value (0-100) control system support The degree of anonymous memory or page caching. Higher values ​​can improve file system performance while actively swapping less active processes from RAM. A lower value can avoid swapping processes into memory, which usually reduces latency, but at the cost of I/O performance. The default is 60.

    Setting swappiness==0 will be very active to avoid swapping. This increases the risk of OOM being killed under strong memory and I/O pressure.

?

file system parameters

The parameters listed are in /proc/sys/fs.

  • aio-max-nr

    Define all activities asynchronous The maximum number of events allowed in the input/output context. The default value is 65535. Modifying this value will not pre-allocate or adjust the size of any kernel data structures.

  • file-max

    Determine the maximum number of file handles for the entire system. The default maximum value is 8192 or one-tenth of the available memory pages.

    Increase this value to solve errors caused by lack of available file handles.

kernel parameter

The default of the following parameters is located in /oroc/sys/kernel, It can be calculated by the kernel based on the available system resources at boot time.

  • msgmax

    Defines the maximum allowable size (in bytes) of any single message in the message queue. The value must not exceed the size of the queue (msgmnb). To determine the current msgmax value on the system, use:

1

< /td>

sysctl -p
1
sysctl kernel.msgmax
  • msgmnb

    Define the maximum value of a single message queue (in bytes). To determine the current msgmnb value on the system, use:

    < table>

    1
    sysctl kernel.msgmnb
  • msgmni

    Define the maximum number of message queue identifiers (and the maximum number of queues), to determine the current msgmin on the system code>Value, use:

    1
    sysctl kernel.msgmni
  • shmall

    Define the total number of shared memory pages that can be used on the system at one time. For example, a page on the x86_64 architecture is 4096 bytes.

    To determine the current value of shmall in the system, use:

    1
    sysctl kernel.shmall
  • shmmax

    Defines the maximum size (in bytes) of a single shared memory segment allowed by the kernel. To determine the current shmmax value on the system, use:

    span>
    1
    sysctl kernel.shmmax
  • shmmni

    Define the system-wide maximum number of shared memory segments. The default value on all systems is 4096.

  • threads-max

    Define the maximum number of threads in the system valve that can be used in the kernel at one time. To determine the current threads-max value on the system, use:

    1
    sysctl kernel.threads -max

    The default result is:

    1
    mempages/(8*THREAD_SIZE/PAGESIZE)

    < /figure>

  • WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
    SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2687 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

    Leave a Comment

    Your email address will not be published.