Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

關於 CentOS 6.7 中一個 TCP 重傳細節的證實

如果你真的讀完了《packetdrill 框架點滴剖析以及 TCP 重傳的一個細節》,心裡應該會留下一個疑問:RH 發行版所用的 2.6.32 內核,真的採用了 PRR 降窗演算法嗎?為此,我把整個故事再梳理一遍。

按照標準的 2.6.32 內核,第一次收到 SACK 時,在進入重傳之前,擁塞視窗的值應該是 in_flight+1,也就是 2+1=3 個段,換句話說只該重傳 1 個段。但抓包卻發現重傳了 2 個段,tcpprobe 也證實在進入重傳之前擁塞視窗的值是 4,而 in_flight 為 2,完全對不上 tcp_cwnd_down 函數的邏輯。

此時我以為一定是自己哪裡理解錯了,應該只是個小問題,於是試圖用 tcpprobe 去探測這個降窗函數,結果載入模組失敗,也就是說系統找不到 tcp_cwnd_down 這個符號。這隱約讓我覺得 RH 對內核打過 patch。以前用 Debian 時發生過類似的事,畢竟每一類發行版、甚至同一發行版的不同版本,本質上都是一次定製。於是我在 /proc/kallsyms 裡翻找名字相近的降窗函數,卻一無所獲。接著,我決定到 https://vault.centos.org/6.7/updates/Source/SPackages/ 上一探究竟。

我的系統發行版版本是:CentOS release 6.7 (Final)。

於是我下載了 kernel-2.6.32-573.1.1.el6.src.rpm,安裝後查看源碼,重點是 tcp_fastretrans_alert 的最後幾行:

if (do_lost || (tcp_is_fack(tp) && tcp_head_timedout(sk))) tcp_update_scoreboard(sk, fast_rexmit); tp->prr_delivered += newly_acked_sacked; tcp_update_cwnd_in_recovery(sk, newly_acked_sacked, fast_rexmit, flag); tcp_xmit_retransmit_queue(sk);

請注意,在重傳之前並沒有呼叫社群版本內核的 tcp_cwnd_down 來執行 Rate Halving 降窗演算法。我於是產生了看看 tcp_update_cwnd_in_recovery 的衝動:

/* This function implements the PRR algorithm, specifcally the PRR-SSRB * (proportional rate reduction with slow start reduction bound) as described in *https://www.ietf.org/id/draft-mathis-tcpm-proportional-rate-reduction-01.txt. * It computes the number of packets to send (sndcnt) based on packets newly * delivered: * 1) If the packets in flight is larger than ssthresh, PRR spreads the * cwnd reductions across a full RTT. * 2) If packets in flight is lower than ssthresh (such as due to excess * losses and/or application stalls), do not perform any further cwnd * reductions, but instead slow start up to ssthresh. */ static void tcp_update_cwnd_in_recovery(struct sock *sk, int newly_acked_sacked, int fast_rexmit, int flag) { struct tcp_sock *tp = tcp_sk(sk); int sndcnt = 0; int delta = tp->snd_ssthresh - tcp_packets_in_flight(tp); if (tcp_packets_in_flight(tp) > tp->snd_ssthresh) { u64 dividend = (u64)tp->snd_ssthresh * tp->prr_delivered + tp->prior_cwnd - 1; sndcnt = div_u64(dividend, tp->prior_cwnd) - tp->prr_out; } else { sndcnt = min_t(int, delta, max_t(int, tp->prr_delivered - tp->prr_out, newly_acked_sacked) + 1); } sndcnt = max(sndcnt, (fast_rexmit ? 1 : 0)); tp->snd_cwnd = tcp_packets_in_flight(tp) + sndcnt; }

這就是 PRR。對比 rpm 套件的發布時間與 PRR 草案正式成為標準的時間,就能看出 RH 對這個 PRR patch 的反應有多即時。

Copyright © Linux教程網 All Rights Reserved