- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
Images
Kernel fine-tuning
Modifying net.ipv4.udp_mem parameter in Linux operating system
Kernel fine-tuning
Modifying net.ipv4.udp_mem parameter in Linux operating system
Modifying net.ipv4.udp_mem parameter in Linux operating system
By modifying the net.ipv4.udp_mem parameter, you can adjust UDP memory management policies of the kernel, thereby controlling UDP packet caching and processing capabilities of the system.
About the net.ipv4.udp_mem parameter
net.ipv4.udp_mem is a 3-integer array structured as [min pressure max]. These values represent memory usage limits for the UDP protocol stack under different states, respectively. The three values define memory thresholds, with the unit being Page (kernel page; typically, 1 kernel page equals 4 KiB). Their meanings are as follows:
- min: The threshold at which the kernel starts reclaiming memory. When the UDP memory usage of the system reaches this value, the kernel starts reclaiming memory to prevent overuse.
- pressure: The soft limit for kernel memory usage. When this value is exceeded, UDP adjusts its memory consumption and enters memory pressure mode. When memory consumption drops below the value specified by min, UDP exits memory pressure mode.
- max: The hard limit for kernel memory usage. That is, the maximum number of pages allowed for all UDP sockets to queue and buffer datagrams. When this value is exceeded, the system refuses to allocate new sockets.
Applicable scenario
- Scenarios with heavy network load
- In scenarios that require processing a large number of UDP packets, such as real-time video streaming or large-scale data transmission, servers may encounter packet loss. This happens because the total memory of UDP sockets reaches the upper limit. In such cases, you can refer to the following adjustment plan:
- min: Set this parameter to a relatively high value to reduce the impact of frequent memory reclamation on high-traffic requests.
- pressure: Set this parameter to 4/3 times the value of the min parameter.
- max: Set this parameter to twice the value of the pressure parameter.
- Scenarios with light network load
- In scenarios involving basic internal network services with low UDP usage, such as file transfer and printing services, servers may experience unnecessary memory usage due to a high memory reclamation threshold. In such cases, you can refer to the following adjustment plan:
- min: Set this parameter to a relatively low value to lower the threshold for triggering memory reclamation and avoid unnecessary memory usage.
- pressure: Set this parameter to 4/3 times the value of the min parameter.
- max: Set this parameter to twice the value of the pressure parameter.
Procedure
Configuration by using the proc interface
Configuration by using the net_udp.conf file
You can use this method to temporarily modify the parameter value while the operating system is running. Each time the instance restarts, you need to configure the parameter again.
- Execute the following command on the target Linux instance to view the current value of the net.ipv4.udp_mem parameter.
-
- Execute the following command to configure the net.ipv4.udp_mem parameter.
You can use this method to permanently modify the parameter value while the operating system is running. You do not need to configure the parameter again after the instance restarts.
- Execute the following command to view the current parameter value.
-
- Modify the net.ipv4.udp_mem parameter value.
- Execute the following command to create the net_udp.conf file.
- Press the i key to enter edit mode and add the following content to the end of the file.
- Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to make the configuration take effect.
Last updated: 2025.11.03 16:31:20