Linux Tune Network Stack (Buffers Size) To Increase Networking Performance

The networking performance of a Linux system can be improved by tuning the network stack buffers sizes. The buffer sizes can be adjusted using the sysctl command.

Here are the steps to tune the network stack buffers size:

  1. Open a terminal or shell prompt on your Linux system.
  2. Verify that the net.core.rmem_max, net.core.wmem_max, net.ipv4.tcp_rmem, and net.ipv4.tcp_wmem values are set to the maximum buffer size:
    sysctl net.core.rmem_max
    sysctl net.core.wmem_max
    sysctl net.ipv4.tcp_rmem
    sysctl net.ipv4.tcp_wmem

    If any of these values are set to a lower value, you can increase them. For example, to increase the net.core.rmem_max value to 16MB, you can run:

    sysctl -w net.core.rmem_max=16777216
  3. Set the minimum buffer size for the network stack. The minimum buffer size is set to the maximum buffer size multiplied by the number of buffers. For example, to set the minimum buffer size to 32MB for the net.core.rmem_max and net.core.wmem_max values, and to 16MB for the net.ipv4.tcp_rmem and net.ipv4.tcp_wmem values, you can run:
    sysctl -w net.core.rmem_max=33554432
    sysctl -w net.core.wmem_max=33554432
    sysctl -w net.ipv4.tcp_rmem="16384 33554432 33554432"
    sysctl -w net.ipv4.tcp_wmem="16384 33554432 33554432"

    This will set the minimum buffer size to 32MB for the net.core.rmem_max and net.core.wmem_max values, and to 16MB for the net.ipv4.tcp_rmem and net.ipv4.tcp_wmem values.

  4. Verify that the changes have been applied:
    sysctl net.core.rmem_max
    sysctl net.core.wmem_max
    sysctl net.ipv4.tcp_rmem
    sysctl net.ipv4.tcp_wmem
  5. Save the changes so that they are applied at boot time. You can add the sysctl commands to the /etc/sysctl.conf file:
    echo "net.core.rmem_max = 33554432" >> /etc/sysctl.conf
    echo "net.core.wmem_max = 33554432" >> /etc/sysctl.conf
    echo "net.ipv4.tcp_rmem = 16384 33554432 33554432" >> /etc/sysctl.conf
    echo "net.ipv4.tcp_wmem = 16384 33554432 33554432" >> /etc/sysctl.conf

    This will add the sysctl commands to the end of the /etc/sysctl.conf file.

That’s it! You have tuned the network stack buffers size to increase the networking performance of your Linux system.

Leave a Comment