How To: Network / TCP / UDP Tuning

How To: Network / TCP / UDP Tuning

This is a very basic step by step description of how to improve the performance networking (TCP & UDP) on Linux 2.4+ for high-bandwidth applications. These settings are especially important for GigE links. Jump to  Quick Step or  All The Steps.
Assumptions
This howto assumes that the machine being tuned is involved in supporting high-bandwidth applications. Making these modifications on a machine that supports multiple users and/or multiple connections is not recommended - it may cause the machine to deny connections because of a lack of memory allocation.
The Steps
  1. Make sure that you have root privleges.

  2. Type: sysctl -p | grep mem
    This will display your current buffer settings. Save These! You may want to roll-back these changes

  3. Type: sysctl -w net.core.rmem_max=8388608 
    This sets the max OS receive buffer size for all types of connections.

  4. Type: sysctl -w net.core.wmem_max=8388608 
    This sets the max OS send buffer size for all types of connections.

  5. Type: sysctl -w net.core.rmem_default=65536 
    This sets the default OS receive buffer size for all types of connections.

  6. Type: sysctl -w net.core.wmem_default=65536 
    This sets the default OS send buffer size for all types of connections.

  7. Type: sysctl -w net.ipv4.tcp_mem='8388608 8388608 8388608' 
    TCP Autotuning setting. "The tcp_mem variable defines how the TCP stack should behave when it comes to memory usage. ... The first value specified in the tcp_mem variable tells the kernel the low threshold. Below this point, the TCP stack do not bother at all about putting any pressure on the memory usage by different TCP sockets. ... The second value tells the kernel at which point to start pressuring memory usage down. ... The final value tells the kernel how many memory pages it may use maximally. If this value is reached, TCP streams and packets start getting dropped until we reach a lower memory usage again. This value includes all TCP sockets currently in use." 

  8. Type: sysctl -w net.ipv4.tcp_rmem='4096 87380 8388608' 
    TCP Autotuning setting. "The first value tells the kernel the minimum receive buffer for each TCP connection, and this buffer is always allocated to a TCP socket, even under high pressure on the system. ... The second value specified tells the kernel the default receive buffer allocated for each TCP socket. This value overrides the /proc/sys/net/core/rmem_default value used by other protocols. ... The third and last value specified in this variable specifies the maximum receive buffer that can be allocated for a TCP socket." 

  9. Type: sysctl -w net.ipv4.tcp_wmem='4096 65536 8388608' 
    TCP Autotuning setting. "This variable takes 3 different values which holds information on how much TCP sendbuffer memory space each TCP socket has to use. Every TCP socket has this much buffer space to use before the buffer is filled up. Each of the three values are used under different conditions. ... The first value in this variable tells the minimum TCP send buffer space available for a single TCP socket. ... The second value in the variable tells us the default buffer space allowed for a single TCP socket to use. ... The third value tells the kernel the maximum TCP send buffer space." 

  10. Type:sysctl -w net.ipv4.route.flush=1
    This will enusre that immediatly subsequent connections use these values. 

Quick Step
Cut and paste the following into a linux shell with root privleges:

sysctl -w net.core.rmem_max=8388608
sysctl -w net.core.wmem_max=8388608
sysctl -w net.core.rmem_default=65536
sysctl -w net.core.wmem_default=65536
sysctl -w net.ipv4.tcp_rmem='4096 87380 8388608'
sysctl -w net.ipv4.tcp_wmem='4096 65536 8388608'
sysctl -w net.ipv4.tcp_mem='8388608 8388608 8388608'
sysctl -w net.ipv4.route.flush=1
References
All of this information comes directly from these very reliable sources:
Feedback
Please send  me some  feedback on how this worked for you. I'd be happy to help you figure it out on yours. I've used these or similar settings for a number of high-bandwidth applications with great results.
V36757663@dg03podv36757663ivxb:~/16.0.0.1_2025061606060000_root/source/vnd/vendor/oplus/camera/hal/oem/sun/25600$ git status Not currently on any branch. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: 3a/aec_tuning/bin/20250618155629889/libaecCustomParam_Cam0.bin new file: 3a/aec_tuning/bin/20250618155629889/libaecCustomParam_Cam1.bin new file: 3a/aec_tuning/bin/20250618155629889/libaecCustomParam_Cam2.bin new file: 3a/aec_tuning/bin/20250618155629889/libaecCustomParam_Cam3.bin new file: 3a/aec_tuning/bin/20250618155629889/libaecCustomParam_Cam4.bin new file: 3a/aec_tuning/bin/20250619163443929/libaecCustomParam_Cam0.bin new file: 3a/aec_tuning/bin/20250619163443929/libaecCustomParam_Cam1.bin new file: 3a/aec_tuning/bin/20250619163443929/libaecCustomParam_Cam2.bin new file: 3a/aec_tuning/bin/20250619163443929/libaecCustomParam_Cam3.bin new file: 3a/aec_tuning/bin/20250619163443929/libaecCustomParam_Cam4.bin new file: 3a/af_tuning/bin/20250618155629889/libafCustomParam_Cam0.bin new file: 3a/af_tuning/bin/20250618155629889/libafCustomParam_Cam1.bin new file: 3a/af_tuning/bin/20250618155629889/libafCustomParam_Cam2.bin new file: 3a/af_tuning/bin/20250618155629889/libafCustomParam_Cam3.bin new file: 3a/af_tuning/bin/20250619163443929/libafCustomParam_Cam0.bin new file: 3a/af_tuning/bin/20250619163443929/libafCustomParam_Cam1.bin new file: 3a/af_tuning/bin/20250619163443929/libafCustomParam_Cam2.bin new file: 3a/af_tuning/bin/20250619163443929/libafCustomParam_Cam3.bin new file: 3a/pd_tuning/bin/20250618155629889/libpdCustomParam_Cam0.bin new file: 3a/pd_tuning/bin/20250618155629889/libpdCustomParam_Cam2.bin new file: 3a/pd_tuning/bin/20250618155629889/libpdCustomParam_Cam3.bin new file: 3a/pd_tuning/bin/20250619163443929/libpdCustomParam_Cam0.bin new file: 3a/pd_tuning/bin/20250619163443929/libpdCustomParam_Cam2.bin new file: 3a/pd_tuning/bin/20250619163443929/libpdCustomParam_Cam3.bin modified: actuator/imx882_tele_ak7316_actuator.xml modified: buildbins.yaml modified: config/CameraHWConfiguration.config modified: module/qtech_s5kjn5_module.xml
06-22
<think>我们当前面临的核心问题是:处于"notcurrentlyonanybranch"状态(即分离头指针状态)且有大量已暂存文件需要处理。参考之前提供的解决方案,关键是要安全保存这些修改并转移到分支上。结合引用[1]和引用[3]中关于git状态的描述,以及引用[2]中的分支操作命令,以下是具体解决步骤:###解决方案步骤(针对分离头指针+暂存文件)####1.**创建新分支保留当前工作状态**```bashgitcheckout-brescue-branch```-✅此命令同时完成两件事:创建名为`rescue-branch`的分支+切换到该分支-✅所有已暂存(staged)和未暂存(unstaged)修改都会被完整保留[^1][^2]####2.**提交暂存区的所有文件**```bashgitcommit-m"紧急保存:分离头指针状态下的暂存文件"```-💡使用`gitstatus`确认所有需要保存的文件都已进入暂存区(显示在"Changestobecommitted"下)####3.**处理未暂存文件(可选)**若还有未暂存的重要修改:```bash#添加剩余修改到暂存区gitadd-u#提交未暂存文件gitcommit-m"补充提交:工作目录中的修改"```####4.**合并到主分支**```bash#切换到目标分支(如main/master)gitcheckoutmain#合并救援分支gitmergerescue-branch```####5.**清理临时分支**```bashgitbranch-drescue-branch```---###关键原理图解```mermaidgraphLRA[分离头指针状态]-->|创建分支|B[rescue-branch]B-->|提交|C[保留暂存文件]C-->|合并|D[主分支]```>⚠️**警告**:直接切换分支会丢失未提交修改!必须先用分支固化状态[^1][^2]---###高级场景处理####🔧如果暂存文件包含敏感数据需撤销```bash#在创建救援分支后撤销某些文件的暂存gitresetHEAD--path/to/sensitive-file.txt#彻底删除该文件记录gitrm--cachedpath/to/sensitive-file.txt```####🔧需要部分保存修改```bash#交互式选择要保留的修改块gitadd-p#提交选中部分gitcommit-m"部分保存关键修改"```---###预防分离头指针状态1.**检出时显式创建分支**```bashgitcheckout-btemp-branch<commit-id>```2.**命令行提示符显示分支状态**在`~/.bashrc`添加:```bashexportPS1='\[\e[31m\]($(gitbranch--show-current2>/dev/null||echo"DETACHED!"))\[\e[0m\]\w\$'```---###相关问题1.如何从分离头指针状态恢复未暂存的修改?2.`gitstash`在分离头指针状态下是否安全?3.为什么Git允许分离头指针状态?有哪些合法使用场景?4.如何批量恢复多个分离头指针工作区?5.企业Git工作流中如何避免分离头指针导致的数据丢失?[^1]:Git分支文档:分离头指针的风险与恢复机制[^2]:版本控制最佳实践:暂存区操作原理</think>### 解决 Git 未处于任何分支且有暂存文件的问题 当 Git 提示 `not currently on any branch` 并存在已暂存文件时,说明您处于**分离头指针(detached HEAD)**状态(通常由直接检出提交而非分支导致)。以下是安全处理已暂存文件的完整方案: --- ### 解决方案步骤 #### 1. **创建临时分支保存状态** ```bash git checkout -b temp-rescue-branch ``` - ✅ 关键操作:将分离头指针状态转为安全分支环境 - ✅ **保留所有暂存(staged)和工作目录(unstaged)修改**[^1][^2] - ❗ 直接切换分支会丢失未提交修改,此操作是唯一安全路径 #### 2. **提交暂存文件** ```bash git commit -m "紧急保存:分离头指针状态下的暂存文件" ``` - 💡 使用 `git status` 确认所有需保存文件已进入 "Changes to be committed" 区域 - 🔧 若需修改提交:`git commit --amend`(引用[4]) #### 3. **合并到目标分支** ```bash git checkout main # 切换到目标分支 git merge temp-rescue-branch # 合并临时分支 ``` #### 4. **清理临时分支** ```bash git branch -d temp-rescue-branch ``` --- ### 关键原理说明 1. **分离头指针的危险性** 在 `detached HEAD` 状态下提交的修改: - ❌ 不被任何分支引用 - ❌ 可能被 Git 垃圾回收机制清除(约 30 天后) - ✅ 创建分支是**唯一永久保存修改**的方式(引用[1][2]) 2. **暂存文件的保留机制** ```mermaid graph LR A[分离头指针状态] --> B[git checkout -b new-branch] B --> C[暂存区状态完全保留] C --> D[提交后永久存储] ``` 3. **错误操作风险** - ❌ `git checkout main`:直接切换分支会**丢失所有未提交修改**(引用[3]) - ❌ `git stash`:在分离状态下可能导致引用丢失 --- ### 高级场景处理 #### 🔧 存在未暂存修改时 ```bash # 保存所有修改(包括未暂存) git stash save "rescue-all-changes" # 创建分支后恢复 git checkout -b rescue-branch git stash pop ``` #### 🔧 需要选择性提交 ```bash # 交互式选择暂存内容 git add -p # 仅提交部分文件 git commit path/to/file1 path/to/file2 -m "部分保存" ``` #### 🔧 恢复后检查差异 ```bash git diff HEAD~1 HEAD # 确认恢复内容完整性 ``` --- ### 预防措施 1. **避免分离头指针** ```bash # 始终通过分支检出提交 git checkout -b inspect-commit <commit-hash> ``` 2. **命令行警告设置** 在 `~/.bashrc` 添加: ```bash export PS1='\[\e[31m\](git:$(git branch --show-current 2>/dev/null || echo "DETACHED!"))\[\e[0m\] \w\$ ' ``` 3. **IDE 集成**(引用[5]) - 使用 Xcode/VSCode 等工具的 Git 状态提示 - 避免直接执行危险命令 --- ### 相关问题 1. 如何从分离头指针状态恢复未暂存的修改? 2. `git stash` 在分离头指针状态下是否安全?有哪些替代方案? 3. 为什么 Git 允许分离头指针状态?有哪些合法使用场景? 4. 如何批量恢复多个分离头指针工作区? 5. 企业 Git 工作流中如何避免分离头指针导致的数据丢失? [^1]: Git 分支文档:分离头指针的风险与恢复机制 [^2]: 版本控制最佳实践:暂存区操作原理 [^3]: Git 状态提示与文件恢复方法 [^4]: 提交修改技术:`git amend` 的应用场景 [^5]: IDE 集成工具对 Git 工作流的支持与限制
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值