在此步骤中,你将学习如何检查和修改网络卸载功能。这些是高级网卡功能,允许硬件执行原本由 CPU 处理的任务,例如计算校验和或分段数据。卸载这些任务可以提高网络性能。
首先,让我们使用 -k(或 --show-features)标志来查看接口的当前卸载设置。
ethtool -k eth0
你将看到一个功能列表,其中一些是 on(开启),一些是 off(关闭)。[fixed] 状态表示该设置无法由用户更改。
Features for eth0:
rx-checksumming: on [fixed]
tx-checksumming: on
tx-checksum-ipv4: off [fixed]
tx-checksum-ip-generic: on
tx-checksum-ipv6: off [fixed]
tx-checksum-fcoe-crc: off [fixed]
tx-checksum-sctp: off [fixed]
scatter-gather: on
tx-scatter-gather: on
tx-scatter-gather-fraglist: off [fixed]
tcp-segmentation-offload: on
tx-tcp-segmentation: on
tx-tcp-ecn-segmentation: on
tx-tcp-mangleid-segmentation: off
tx-tcp6-segmentation: on
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
... (输出很长,可能会有所不同)
现在,让我们练习修改其中一个设置。我们将暂时禁用 TX 校验和。此操作需要管理员权限,因此你必须使用 sudo 和 -K(或 --features)标志。
sudo ethtool -K eth0 tx-checksumming off
该命令现在会报告它所做的更改。请注意,禁用 tx-checksumming 会自动禁用其他相关功能。这是因为某些功能依赖于其他功能。
Actual changes:
tx-checksum-ip-generic: off
tx-tcp-segmentation: off [not requested]
tx-tcp-ecn-segmentation: off [not requested]
tx-tcp6-segmentation: off [not requested]
要验证完整列表中的更改,你可以再次运行 ethtool -k eth0。
现在,让我们重新启用它以恢复默认的、增强性能的行为。
sudo ethtool -K eth0 tx-checksumming on
同样,输出显示了实际的更改。你可能会看到,即使你请求某个功能 on,如果硬件将其固定,它仍然会保持 off。它还会显示相关功能被自动重新启用。
Actual changes:
tx-checksum-ipv4: off [requested on]
tx-checksum-ip-generic: on
tx-checksum-ipv6: off [requested on]
tx-tcp-segmentation: on [not requested]
tx-tcp-ecn-segmentation: on [not requested]
tx-tcp6-segmentation: on [not requested]
tx-checksum-fcoe-crc: off [requested on]
tx-checksum-sctp: off [requested on]
通过完成此步骤,你已学会如何检查和修改网卡的硬件卸载功能,并了解了功能依赖关系和硬件限制如何影响结果。