官术网_书友最值得收藏!

Handling Linux/Unix memory parameters

In this topic, let's discuss various kernel memory settings, and see the recommended configuration values.

Getting ready

The kernel provides various memory settings based on its distribution. Using these parameters, we can control the kernel behavior, which provides the necessary resources to the applications. PostgreSQL is a database software application, which needs to communicate to kernel with its system calls, to get its required resources.

How to do it...

Let us discuss about, how to tune few major kernel memory components in Linux:

kernel.shmmax

This setting defines the maximum size limit of a shared memory segment, which limits the processes required segment size. We need to specify the maximum allowed segment size in bytes. It is recommended to set this value as half of the RAM size in the form of bytes.

kernel.shmall

This setting defines the limit on the available shared memory in the system. In general, we need to set this parameter in the form of pages. While the PostgreSQL server is starting, it will calculate the amount of shared memory that is required based on postgresql.conf settings such as max_connections, autovacuum_max_workers, and so on. It is generally recommended to set this value as half of the RAM size in the form of pages.

kernel.shmmni

This setting defines the limit of the number of segments, which the kernel needs to allow in the system. The default value of 4096 is sufficient for a standalone PostgreSQL server. We can also get the number of shared memory segments in the system, by using the ipcs Linux utility command.

vm.swappiness

This setting defines the aggressiveness of kernel, in clearing the system cache. If we define this value as 100, then kernel will be in busy paging out the application into the swap file, and it also drops the cached data. Once the kernel drops the cache then it's a major performance hit to the database server, and also a major performance problem for the applications, where it needs to load its content from swap into the memory. The recommended value for this parameter is any value that is less than 10. In general, the kswapd Linux OS daemon process will start dumping all the pages into swap, if we have less free memory available.

vm.overcommit_memory

This setting defines the overcommit behavior, which will try to control the system stability by preventing OOM (Out Of Memory) issues. The suggested values for this parameter are either 0 or 2 (recommended). The setting value 2 will control the memory allocation, and will try to allocate the memory for the processes, by using swap size, and a percentage of the overcommit_ratio from the RAM size. The setting value 0 follows a heuristic approach, which allocates more address space (virtual memory) than the physical memory, which does not guarantee system stability.

vm.overcommit_ratio

This setting defines how much physical memory kernel needs to allocate for the processes. The suggested value for this parameter is 80. That is, 80% of the physical memory will be considered to allocate the memory for the requested processes. This parameter plays a major role in utilizing the memory to the full extent.

vm.dirty_background_ratio

This setting defines what percentage of the system memory can be dirtied before flushing it to disk. The suggested value for this parameter is less than 5, based on RAM size. Once the system memory fills with dirty data, then kernel will push all the modified content into the disk storage, by blocking the incoming I/O requests to system memory.

vm.dirty_ratio

This setting defines what percentage of the system memory can be dirtied before flushing it to disk. The suggested value for this parameter is 10 to 15 percent based on RAM size, and the configured RAID levels. When the system memory fills with dirty data, then the process that generated the dirty data is responsible for flushing the contents to disk, by blocking incoming I/O requests to the user memory space.

How it works...

These kernel parameters play a vital role for all the Linux applications, including the database server. Based on these configuration settings, we can indirectly control the PostgreSQL behavior, by controlling the operating system kernel.

Note

For more information about kernel parameters, check out the following URL: https://www.kernel.org/doc/Documentation/sysctl/.

主站蜘蛛池模板: 樟树市| 周宁县| 弋阳县| 泰来县| 沈阳市| 东港市| 牙克石市| 拜城县| 新丰县| 吉安市| 陇南市| 平顶山市| 应用必备| 兴安县| 长阳| 邛崃市| 南城县| 六盘水市| 修水县| 弥勒县| 寻甸| 浙江省| 泸溪县| 金川县| 黎城县| 浦城县| 宜宾市| 宁河县| 福州市| 崇州市| 临武县| 永城市| 桂林市| 西吉县| 张北县| 阿拉善右旗| 仪征市| 莱阳市| 扎赉特旗| 历史| 隆子县|