{"id":208406,"date":"2025-09-12T20:45:30","date_gmt":"2025-09-12T12:45:30","guid":{"rendered":"https:\/\/www.server.hk\/blog\/?p=208406"},"modified":"2025-09-12T20:45:30","modified_gmt":"2025-09-12T12:45:30","slug":"%e6%b7%b1%e5%85%a5%e5%89%96%e6%9e%90-linux-tcp-ip-%e5%8d%8f%e8%ae%ae%e6%a0%88%ef%bc%9a%e6%9e%b6%e6%9e%84%e4%b8%8e%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208406\/","title":{"rendered":"\u6df1\u5165\u5256\u6790 Linux TCP\/IP \u534f\u8bae\u6808\uff1a\u67b6\u6784\u4e0e\u5b9e\u73b0"},"content":{"rendered":"<p dir=\"auto\">\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u4e86 Linux \u64cd\u4f5c\u7cfb\u7edf\u4e2d TCP\/IP \u534f\u8bae\u6808\u7684\u5b9e\u73b0\u539f\u7406\uff0c\u91cd\u70b9\u5206\u6790\u5176\u67b6\u6784\u3001\u6838\u5fc3\u6570\u636e\u7ed3\u6784\u4ee5\u53ca\u6570\u636e\u5904\u7406\u6d41\u7a0b\u3002\u672c\u6587\u9762\u5411 IT \u4e13\u4e1a\u4eba\u58eb\u548c\u6280\u672f\u5f00\u53d1\u8005\uff0c\u5185\u5bb9\u7ecf\u8fc7 SEO \u4f18\u5316\uff0c\u786e\u4fdd\u6280\u672f\u51c6\u786e\u6027\u3001\u903b\u8f91\u6e05\u6670\uff0c\u5e76\u4ee5 WordPress \u7ecf\u5178\u7f16\u8f91\u5668\u517c\u5bb9\u7684 Markdown \u683c\u5f0f\u5448\u73b0\u3002<\/p>\n<h2 dir=\"auto\">Linux \u5185\u6838\u7f51\u7edc\u5b50\u7cfb\u7edf\u7b80\u4ecb<\/h2>\n<p dir=\"auto\">Linux \u5185\u6838\u662f\u64cd\u4f5c\u7cfb\u7edf\u6838\u5fc3\uff0c\u8d1f\u8d23\u7ba1\u7406\u5305\u62ec\u7f51\u7edc\u901a\u4fe1\u5728\u5185\u7684\u5173\u952e\u529f\u80fd\u3002TCP\/IP \u534f\u8bae\u6808\u4f5c\u4e3a\u7f51\u7edc\u901a\u4fe1\u7684\u57fa\u77f3\uff0c\u5728\u5185\u6838\u7684\u7f51\u7edc\u5b50\u7cfb\u7edf\u4e2d\u5b9e\u73b0\u3002\u672c\u6587\u5c06\u4ece\u6280\u672f\u89d2\u5ea6\u8be6\u7ec6\u89e3\u6790 Linux \u5185\u6838\u7f51\u7edc\u5b50\u7cfb\u7edf\u7684\u67b6\u6784\u3001\u5173\u952e\u7ec4\u4ef6\u53ca\u6570\u636e\u5904\u7406\u6d41\u7a0b\uff0c\u4e3a\u5f00\u53d1\u8005\u548c\u7cfb\u7edf\u7ba1\u7406\u5458\u63d0\u4f9b\u5b9e\u7528\u53c2\u8003\u3002<\/p>\n<h3 dir=\"auto\">Linux \u5185\u6838\u67b6\u6784\u6982\u89c8<\/h3>\n<p dir=\"auto\">Linux \u5185\u6838\u91c7\u7528\u6a21\u5757\u5316\u8bbe\u8ba1\uff0c\u5206\u4e3a\u4ee5\u4e0b\u4e94\u4e2a\u4e3b\u8981\u90e8\u5206\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u8fdb\u7a0b\u7ba1\u7406<\/strong>\uff1a\u8d1f\u8d23 CPU \u8c03\u5ea6\u548c\u8fdb\u7a0b\u63a7\u5236\u3002<\/li>\n<li><strong>\u5185\u5b58\u7ba1\u7406<\/strong>\uff1a\u7ba1\u7406\u7cfb\u7edf\u5185\u5b58\u8d44\u6e90\u7684\u5206\u914d\u548c\u8bbf\u95ee\u3002<\/li>\n<li><strong>\u6587\u4ef6\u7cfb\u7edf<\/strong>\uff1a\u5c06\u78c1\u76d8\u6247\u533a\u7ec4\u7ec7\u4e3a\u6587\u4ef6\u7cfb\u7edf\uff0c\u652f\u6301\u8bfb\u5199\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u8bbe\u5907\u7ba1\u7406<\/strong>\uff1a\u63a7\u5236\u5916\u90e8\u8bbe\u5907\u53ca\u5176\u9a71\u52a8\u7a0b\u5e8f\u3002<\/li>\n<li><strong>\u7f51\u7edc\u7ba1\u7406<\/strong>\uff1a\u7ba1\u7406\u7f51\u7edc\u8bbe\u5907\u5e76\u5b9e\u73b0\u534f\u8bae\u6808\uff0c\u652f\u6301\u4e0e\u5176\u4ed6\u7cfb\u7edf\u901a\u8fc7\u7f51\u7edc\u901a\u4fe1\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u8fd9\u4e9b\u6a21\u5757\u76f8\u4e92\u534f\u4f5c\uff0c\u5171\u540c\u5b8c\u6210\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\uff0c\u5176\u4e2d\u7f51\u7edc\u7ba1\u7406\u6a21\u5757\u662f TCP\/IP \u534f\u8bae\u6808\u5b9e\u73b0\u7684\u6838\u5fc3\u3002<\/p>\n<h2 dir=\"auto\">Linux \u7f51\u7edc\u5b50\u7cfb\u7edf\u7ed3\u6784<\/h2>\n<p dir=\"auto\">Linux \u7f51\u7edc\u5b50\u7cfb\u7edf\u8bbe\u8ba1\u4e0a\u6ce8\u91cd\u534f\u8bae\u5b9e\u73b0\u4e0e\u786c\u4ef6\u4ea4\u4e92\u7684\u5206\u79bb\uff0c\u5206\u4e3a\u4e94\u5c42\u7ed3\u6784\uff0c\u4e0e TCP\/IP \u6a21\u578b\u5bf9\u5e94\uff0c\u786e\u4fdd\u6570\u636e\u5904\u7406\u7684\u9ad8\u6548\u6027\uff1a<\/p>\n<ol dir=\"auto\">\n<li><strong>\u7cfb\u7edf\u8c03\u7528\u63a5\u53e3<\/strong>\uff1a\u7528\u6237\u6001\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528\uff08\u5982 sys_* \u51fd\u6570\uff09\u8bbf\u95ee\u5185\u6838\u3002<\/li>\n<li><strong>\u534f\u8bae\u65e0\u5173\u63a5\u53e3<\/strong>\uff1a\u901a\u8fc7 socket \u7ed3\u6784\u5b9e\u73b0\uff0c\u63d0\u4f9b\u901a\u7528\u7684\u51fd\u6570\u652f\u6301\u591a\u79cd\u534f\u8bae\u3002<\/li>\n<li><strong>\u7f51\u7edc\u534f\u8bae<\/strong>\uff1a\u652f\u6301\u591a\u79cd\u534f\u8bae\uff08\u5982 TCP\u3001UDP\uff09\uff0c\u901a\u8fc7 net_proto_family \u7ed3\u6784\u5b58\u50a8\u5728 net_family[] \u6570\u7ec4\u4e2d\u3002<\/li>\n<li><strong>\u8bbe\u5907\u65e0\u5173\u63a5\u53e3<\/strong>\uff1a\u7531 net_device \u7ed3\u6784\u5b9e\u73b0\uff0c\u4e3a\u786c\u4ef6\u901a\u4fe1\u63d0\u4f9b\u7edf\u4e00\u63a5\u53e3\u3002<\/li>\n<li><strong>\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f<\/strong>\uff1a\u4f4d\u4e8e\u6700\u5e95\u5c42\uff0c\u7ba1\u7406\u7269\u7406\u7f51\u7edc\u8bbe\u5907\u3002<\/li>\n<\/ol>\n<p dir=\"auto\">\u8fd9\u79cd\u5206\u5c42\u8bbe\u8ba1\u786e\u4fdd\u4e86\u6a21\u5757\u5316\u4e0e\u7075\u6d3b\u6027\u3002<\/p>\n<h3 dir=\"auto\">TCP\/IP \u534f\u8bae\u6808\u67b6\u6784<\/h3>\n<p dir=\"auto\">Linux \u7684 TCP\/IP \u534f\u8bae\u6808\u4e0e Internet \u6a21\u578b\u4e00\u81f4\uff0c\u5305\u542b\u4ee5\u4e0b\u5c42\u6b21\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u5e94\u7528\u5c42<\/strong>\uff1a\u8fd0\u884c\u4e8e\u7528\u6237\u6001\uff0c\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528\u4e0e\u5185\u6838\u4ea4\u4e92\u3002<\/li>\n<li><strong>\u4f20\u8f93\u5c42<\/strong>\uff1a\u5728\u5185\u6838\u6001\u5b9e\u73b0 TCP\u3001UDP \u7b49\u534f\u8bae\u3002<\/li>\n<li><strong>\u7f51\u7edc\u5c42<\/strong>\uff1a\u5904\u7406 IP \u8def\u7531\u548c\u6570\u636e\u5305\u5904\u7406\u3002<\/li>\n<li><strong>\u6570\u636e\u94fe\u8def\u5c42<\/strong>\uff1a\u7ba1\u7406\u8bbe\u5907\u9a71\u52a8\u548c\u7269\u7406\u63a5\u53e3\u3002<\/li>\n<li><strong>\u7269\u7406\u5c42<\/strong>\uff1a\u4e0e\u786c\u4ef6\u4ea4\u4e92\uff0c\u5b8c\u6210\u6570\u636e\u4f20\u8f93\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u6570\u636e\u901a\u8fc7 <strong>\u5957\u63a5\u5b57\u7f13\u51b2\u533a\uff08SKB\uff09<\/strong> \u5728\u5404\u5c42\u4e4b\u95f4\u4f20\u9012\uff0cSKB \u5c01\u88c5\u4e86\u6570\u636e\u5305\uff0c\u4f18\u5316\u4e86\u5c42\u95f4\u901a\u4fe1\u6548\u7387\u3002<\/p>\n<h2 dir=\"auto\">TCP\/IP \u534f\u8bae\u6808\u7684\u5173\u952e\u6570\u636e\u7ed3\u6784<\/h2>\n<p dir=\"auto\">Linux TCP\/IP \u534f\u8bae\u6808\u4f9d\u8d56\u51e0\u4e2a\u6838\u5fc3\u6570\u636e\u7ed3\u6784\uff0c\u786e\u4fdd\u6570\u636e\u5305\u9ad8\u6548\u5904\u7406\u548c\u534f\u8bae\u7ba1\u7406\u3002<\/p>\n<h3 dir=\"auto\">1. \u5957\u63a5\u5b57\u7ed3\u6784\uff08Socket\uff09<\/h3>\n<p dir=\"auto\">socket \u7ed3\u6784\u8868\u793a\u901a\u4fe1\u7aef\u70b9\uff0c\u5b58\u50a8\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u534f\u8bae\u7c7b\u578b\uff08\u5982 TCP\u3001UDP\uff09\u3002<\/li>\n<li>\u8fde\u63a5\u72b6\u6001\uff08\u6e90\/\u76ee\u6807\u5730\u5740\u3001\u7aef\u53e3\uff09\u3002<\/li>\n<li>\u6570\u636e\u7f13\u51b2\u533a\u548c\u64cd\u4f5c\u6807\u5fd7\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u5173\u952e\u5b57\u6bb5\u5305\u62ec\uff1a<\/p>\n<ul dir=\"auto\">\n<li>sk\uff1a\u6307\u5411\u4f20\u8f93\u63a7\u5236\u5757\uff08\u5982 TCP \u7684 tcp_sock\uff09\u3002<\/li>\n<li>ops\uff1a\u6307\u5411\u534f\u8bae\u7279\u5b9a\u7684\u64cd\u4f5c\u96c6\u5408\uff08\u5982 TCP \u7684 inet_stream_ops\uff09\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">2. \u5957\u63a5\u5b57\u7f13\u51b2\u533a\uff08SKB\uff09<\/h3>\n<p dir=\"auto\"><strong>SKB<\/strong>\uff08sk_buff\uff09\u662f\u6570\u636e\u5305\u7ba1\u7406\u7684\u6838\u5fc3\u7ed3\u6784\uff0c\u8bbe\u8ba1\u4e0a\u907f\u514d\u6570\u636e\u590d\u5236\u3002\u5176\u4e3b\u8981\u5b57\u6bb5\u5305\u62ec\uff1a<\/p>\n<ul dir=\"auto\">\n<li>head\uff1a\u5206\u914d\u5185\u5b58\u7684\u8d77\u59cb\u5730\u5740\u3002<\/li>\n<li>data\uff1a\u6570\u636e\u5305\u5185\u5bb9\u7684\u8d77\u59cb\u5730\u5740\u3002<\/li>\n<li>tail\uff1a\u6570\u636e\u5305\u5185\u5bb9\u7684\u7ed3\u675f\u5730\u5740\u3002<\/li>\n<li>end\uff1a\u5206\u914d\u5185\u5b58\u7684\u7ed3\u675f\u5730\u5740\u3002<\/li>\n<li>len\uff1a\u6570\u636e\u957f\u5ea6\u3002<\/li>\n<li>headroom\uff1a\u5b58\u50a8\u534f\u8bae\u5934\u90e8\uff08\u5982 TCP\u3001IP\u3001\u4ee5\u592a\u7f51\u5934\u90e8\uff09\u7684\u7a7a\u95f4\u3002<\/li>\n<li>tailroom\uff1a\u672a\u4f7f\u7528\u7684\u6570\u636e\u7a7a\u95f4\u3002<\/li>\n<li>skb_shared_info\uff1a\u5b58\u50a8\u5206\u7247\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u5e38\u7528 SKB \u64cd\u4f5c\u51fd\u6570\u5305\u62ec\uff1a<\/p>\n<ul dir=\"auto\">\n<li>alloc_skb\uff1a\u5206\u914d\u65b0\u7684 SKB\u3002<\/li>\n<li>skb_reserve\uff1a\u9884\u7559\u5934\u90e8\u7a7a\u95f4\u3002<\/li>\n<li>skb_put\uff1a\u6dfb\u52a0\u7528\u6237\u6570\u636e\u3002<\/li>\n<li>skb_push\uff1a\u6dfb\u52a0\u534f\u8bae\u5934\u90e8\u3002<\/li>\n<li>skb_pull\uff1a\u79fb\u9664\u5934\u90e8\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">3. \u7f51\u7edc\u8bbe\u5907\uff08net_device\uff09<\/h3>\n<p dir=\"auto\">net_device \u7ed3\u6784\u62bd\u8c61\u4e86\u7f51\u7edc\u786c\u4ef6\uff0c\u63d0\u4f9b\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>\u786c\u4ef6\u5c5e\u6027<\/strong>\uff1a\u4e2d\u65ad\u4fe1\u606f\u3001\u7aef\u53e3\u5730\u5740\u548c\u9a71\u52a8\u51fd\u6570\u3002<\/li>\n<li><strong>\u534f\u8bae\u914d\u7f6e<\/strong>\uff1aIP \u5730\u5740\u3001\u5b50\u7f51\u63a9\u7801\u548c\u8def\u7531\u4fe1\u606f\u3002<\/li>\n<li><strong>\u51fd\u6570\u6307\u9488<\/strong>\uff1a\u5b9e\u73b0\u534f\u8bae\u4e0e\u786c\u4ef6\u7684\u7edf\u4e00\u63a5\u53e3\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">dev.c \u6587\u4ef6\u63d0\u4f9b\u4e86\u8bbe\u5907\u65e0\u5173\u7684\u51fd\u6570\uff0c\u786e\u4fdd\u534f\u8bae\u4e0e\u786c\u4ef6\u4ea4\u4e92\u7684\u7edf\u4e00\u6027\u3002<\/p>\n<h2 dir=\"auto\">\u6570\u636e\u5305\u5904\u7406\u6d41\u7a0b<\/h2>\n<p dir=\"auto\">Linux TCP\/IP \u534f\u8bae\u6808\u901a\u8fc7\u63a5\u6536\uff08recv\uff09\u548c\u53d1\u9001\uff08send\uff09\u64cd\u4f5c\u5904\u7406\u6570\u636e\u5305\uff0c\u4ee5\u4e0b\u4ece\u6570\u636e\u94fe\u8def\u5c42\u3001\u7f51\u7edc\u5c42\u548c\u4f20\u8f93\u5c42\u5206\u6790\u5176\u6d41\u7a0b\u3002<\/p>\n<h3 dir=\"auto\">\u6570\u636e\u5305\u63a5\u6536\uff08recv\uff09<\/h3>\n<h4 dir=\"auto\">\u6570\u636e\u94fe\u8def\u5c42<\/h4>\n<ol dir=\"auto\">\n<li><strong>\u6570\u636e\u5305\u5230\u8fbe<\/strong>\uff1a\u7f51\u7edc\u6570\u636e\u5305\u5230\u8fbe\u7f51\u5361\uff0c\u7f51\u5361\u901a\u8fc7\u76f4\u63a5\u5185\u5b58\u8bbf\u95ee\uff08DMA\uff09\u5c06\u6570\u636e\u4f20\u8f93\u5230\u5185\u6838\u7684 rx_ring \u7f13\u51b2\u533a\u3002<\/li>\n<li><strong>\u4e2d\u65ad\u89e6\u53d1<\/strong>\uff1a\u7f51\u5361\u53d1\u8d77\u786c\u4ef6\u4e2d\u65ad\uff0c\u8c03\u7528\u9a71\u52a8\u7684\u4e2d\u65ad\u5904\u7406\u51fd\u6570\uff08\u5982 Intel \u7f51\u5361\u7684 igb_msix_ring\uff09\u3002<\/li>\n<li><strong>\u8f6f\u4e2d\u65ad\u8c03\u5ea6<\/strong>\uff1a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u901a\u8fc7 napi_schedule \u89e6\u53d1\u8f6f\u4e2d\u65ad\uff08NET_RX_SOFTIRQ\uff09\uff0c\u5c06\u8bbe\u5907\u6dfb\u52a0\u5230 CPU \u7684 poll_list\u3002<\/li>\n<li><strong>NAPI \u5904\u7406<\/strong>\uff1aksoftirqd \u5185\u6838\u7ebf\u7a0b\u5904\u7406\u8f6f\u4e2d\u65ad\uff0c\u8c03\u7528 net_rx_action \u4ece rx_ring \u83b7\u53d6\u6570\u636e\u5305\u3002<\/li>\n<li><strong>\u6570\u636e\u5305\u9a8c\u8bc1<\/strong>\uff1a\u9a71\u52a8\uff08\u5982 igb_poll\uff09\u9a8c\u8bc1\u6570\u636e\u5305\uff0c\u5206\u914d SKB\uff0c\u5e76\u8bbe\u7f6e\u65f6\u95f4\u6233\u3001\u534f\u8bae\u7c7b\u578b\u7b49\u5b57\u6bb5\u3002<\/li>\n<li><strong>\u534f\u8bae\u4f20\u9012<\/strong>\uff1a\u901a\u8fc7 netif_receive_skb \u5c06\u6570\u636e\u5305\u4f20\u9012\u5230\u7f51\u7edc\u5c42\uff0c\u6839\u636e\u534f\u8bae\u7c7b\u578b\uff08\u5982 IP\u3001ARP\uff09\u5206\u53d1\u3002<\/li>\n<\/ol>\n<h4 dir=\"auto\">\u7f51\u7edc\u5c42<\/h4>\n<ol dir=\"auto\">\n<li><strong>IP \u5904\u7406<\/strong>\uff1aip_rcv \u51fd\u6570\u6267\u884c\u6821\u9a8c\u548c\u9a8c\u8bc1\uff0c\u5fc5\u8981\u65f6\u8fdb\u884c\u5206\u7247\u91cd\u7ec4\u3002<\/li>\n<li><strong>\u8def\u7531\u51b3\u7b56<\/strong>\uff1aip_rcv_finish \u8c03\u7528 ip_route_input \u5224\u65ad\u6570\u636e\u5305\u662f\u53d1\u5f80\u672c\u5730\u3001\u8f6c\u53d1\u8fd8\u662f\u4e22\u5f03\u3002<\/li>\n<li><strong>\u672c\u5730\u6295\u9012<\/strong>\uff1a\u672c\u5730\u6570\u636e\u5305\u7531 ip_local_deliver \u5904\u7406\u5206\u7247\u91cd\u7ec4\uff0c\u5e76\u5206\u53d1\u81f3\u4f20\u8f93\u5c42\u534f\u8bae\uff08\u5982 tcp_v4_rcv\u3001udp_rcv\uff09\u3002<\/li>\n<li><strong>\u8f6c\u53d1\u5904\u7406<\/strong>\uff1a\u8f6c\u53d1\u6570\u636e\u5305\u8c03\u6574\u751f\u5b58\u65f6\u95f4\uff08TTL\uff09\uff0c\u5fc5\u8981\u65f6\u5206\u7247\uff0c\u901a\u8fc7 dst_output \u4f20\u9012\u81f3\u6570\u636e\u94fe\u8def\u5c42\u3002<\/li>\n<\/ol>\n<h4 dir=\"auto\">\u4f20\u8f93\u5c42<\/h4>\n<ol dir=\"auto\">\n<li><strong>\u7cfb\u7edf\u8c03\u7528<\/strong>\uff1arecv \u64cd\u4f5c\u8c03\u7528 __sys_recvfrom\uff0c\u8fdb\u800c\u8c03\u7528 sock_recvmsg\u3002<\/li>\n<li><strong>\u6570\u636e\u83b7\u53d6<\/strong>\uff1a\u5bf9\u4e8e TCP\uff0ctcp_recvmsg \u68c0\u67e5 sk_receive_queue\u3002\u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u901a\u8fc7 sk_busy_loop \u7b49\u5f85\u3002<\/li>\n<li><strong>\u6570\u636e\u62f7\u8d1d<\/strong>\uff1a\u6570\u636e\u5230\u8fbe\u540e\uff0cskb_copy_datagram_msg \u5c06\u6570\u636e\u62f7\u8d1d\u5230\u7528\u6237\u6001\uff0c\u5206\u522b\u5904\u7406\u5934\u90e8\u548c\u6709\u6548\u8f7d\u8377\u3002<\/li>\n<\/ol>\n<h3 dir=\"auto\">\u6570\u636e\u5305\u53d1\u9001\uff08send\uff09<\/h3>\n<h4 dir=\"auto\">\u4f20\u8f93\u5c42<\/h4>\n<ol dir=\"auto\">\n<li><strong>\u7cfb\u7edf\u8c03\u7528<\/strong>\uff1asend \u51fd\u6570\u8c03\u7528 __sys_sendto\uff0c\u6784\u5efa msghdr \u7ed3\u6784\u63cf\u8ff0\u6570\u636e\u3002<\/li>\n<li><strong>\u5957\u63a5\u5b57\u64cd\u4f5c<\/strong>\uff1asock_sendmsg \u8c03\u7528\u534f\u8bae\u7279\u5b9a\u64cd\u4f5c\uff08\u5982 TCP \u7684 tcp_sendmsg\uff09\u3002<\/li>\n<li><strong>\u961f\u5217\u7ba1\u7406<\/strong>\uff1atcp_sendmsg_locked \u5c06\u6570\u636e\u7ec4\u7ec7\u4e3a SKB\uff0c\u52a0\u5165 sk_write_queue\u3002<\/li>\n<li><strong>\u6570\u636e\u4f20\u8f93<\/strong>\uff1atcp_write_xmit \u5b9e\u73b0\u62e5\u585e\u63a7\u5236\uff0c\u6784\u5efa TCP \u5934\u90e8\uff0c\u901a\u8fc7 icsk-&gt;icsk_af_ops-&gt;queue_xmit \u4f20\u9012\u81f3\u7f51\u7edc\u5c42\u3002<\/li>\n<\/ol>\n<h4 dir=\"auto\">\u7f51\u7edc\u5c42<\/h4>\n<ol dir=\"auto\">\n<li><strong>IP \u5c01\u88c5<\/strong>\uff1aip_queue_xmit \u6784\u5efa IP \u5934\u90e8\uff0c\u901a\u8fc7 ip_route_output_ports \u5904\u7406\u8def\u7531\uff0c\u8bbe\u7f6e TTL \u548c QoS \u7b49\u5c5e\u6027\u3002<\/li>\n<li><strong>\u5206\u7247\u5904\u7406<\/strong>\uff1a\u82e5\u6570\u636e\u5305\u8d85\u8fc7\u6700\u5927\u4f20\u8f93\u5355\u5143\uff08MTU\uff09\uff0cip_fragment \u8fdb\u884c\u5206\u7247\u3002<\/li>\n<li><strong>\u8f93\u51fa<\/strong>\uff1aip_finish_output2 \u786e\u4fdd\u5934\u90e8\u7a7a\u95f4\u8db3\u591f\uff0c\u901a\u8fc7 neigh_output \u4f20\u9012\u81f3\u6570\u636e\u94fe\u8def\u5c42\u3002<\/li>\n<\/ol>\n<h4 dir=\"auto\">\u6570\u636e\u94fe\u8def\u5c42<\/h4>\n<ol dir=\"auto\">\n<li><strong>\u6570\u636e\u4f20\u8f93<\/strong>\uff1adev_queue_xmit \u8c03\u7528 dev_hard_start_xmit\uff0c\u901a\u8fc7\u9a71\u52a8\u53d1\u9001\u6570\u636e\u5305\u3002<\/li>\n<li><strong>\u786c\u4ef6\u4ea4\u4e92<\/strong>\uff1a\u9a71\u52a8\u5c06\u6570\u636e\u5305\u4f20\u8f93\u81f3\u7f51\u5361\uff0c\u5b8c\u6210\u7269\u7406\u53d1\u9001\u3002<\/li>\n<\/ol>\n<h2 dir=\"auto\">\u6027\u80fd\u4f18\u5316\u5efa\u8bae<\/h2>\n<ul dir=\"auto\">\n<li><strong>\u4e2d\u65ad\u5904\u7406<\/strong>\uff1aLinux \u901a\u8fc7\u8f6f\u4e2d\u65ad\u5904\u7406\u5927\u90e8\u5206\u6570\u636e\u5305\u64cd\u4f5c\uff0c\u51cf\u5c11 CPU \u5f00\u9500\u3002<\/li>\n<li><strong>\u7f13\u51b2\u533a\u7ba1\u7406<\/strong>\uff1aSKB \u4f7f\u7528\u6307\u9488\u7ba1\u7406\u5934\u90e8\u548c\u6570\u636e\uff0c\u964d\u4f4e\u5185\u5b58\u62f7\u8d1d\u5f00\u9500\u3002<\/li>\n<li><strong>\u62e5\u585e\u63a7\u5236<\/strong>\uff1atcp_write_xmit \u5b9e\u73b0 TCP \u62e5\u585e\u63a7\u5236\uff0c\u786e\u4fdd\u53ef\u9760\u4f20\u8f93\u3002<\/li>\n<li><strong>\u53c2\u6570\u8c03\u4f18<\/strong>\uff1a\u901a\u8fc7\u8c03\u6574\u5185\u6838\u53c2\u6570\uff08\u5982 net.core.rmem_max \u548c netdev_budget\uff09\u4f18\u5316\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">\u5e38\u7528\u8c03\u4f18\u547d\u4ee4<\/h3>\n<ul dir=\"auto\">\n<li><strong>\u589e\u5927\u73af\u5f62\u7f13\u51b2\u533a<\/strong>\uff1a\u4f7f\u7528 ethtool -G &lt;interface&gt; rx &lt;size&gt; \u51cf\u5c11\u56e0\u7f13\u51b2\u533a\u6ee1\u5bfc\u81f4\u7684\u4e22\u5305\u3002<\/li>\n<li><strong>\u8c03\u6574 CPU \u4eb2\u548c\u6027<\/strong>\uff1a\u901a\u8fc7 irqbalance \u6216\u624b\u52a8\u8bbe\u7f6e\u4e2d\u65ad\u4eb2\u548c\u6027\uff0c\u5c06\u4e2d\u65ad\u5206\u6563\u5230\u591a\u4e2a CPU \u6838\u5fc3\u3002<\/li>\n<li><strong>\u4f18\u5316\u5957\u63a5\u5b57\u7f13\u51b2\u533a<\/strong>\uff1a\u8c03\u6574 net.core.rmem_default \u548c net.core.wmem_default \u4f18\u5316\u5185\u5b58\u5206\u914d\u3002<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u603b\u7ed3<\/h2>\n<p dir=\"auto\">Linux TCP\/IP \u534f\u8bae\u6808\u901a\u8fc7\u6a21\u5757\u5316\u7684\u5185\u6838\u8bbe\u8ba1\u3001\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\uff08\u5982 SKB \u548c net_device\uff09\u4ee5\u53ca\u5206\u5c42\u5904\u7406\u6d41\u7a0b\uff0c\u5b9e\u73b0\u4e86\u5f3a\u5927\u7684\u7f51\u7edc\u901a\u4fe1\u529f\u80fd\u3002\u672c\u6587\u6df1\u5165\u5256\u6790\u4e86\u5176\u67b6\u6784\u3001\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5305\u5904\u7406\u6d41\u7a0b\uff0c\u4e3a\u5f00\u53d1\u8005\u4f18\u5316\u7f51\u7edc\u6027\u80fd\u548c\u6392\u67e5\u95ee\u9898\u63d0\u4f9b\u4e86\u575a\u5b9e\u57fa\u7840\u3002\u638c\u63e1 Linux TCP\/IP \u534f\u8bae\u6808\u7684\u5b9e\u73b0\u539f\u7406\uff0c\u6709\u52a9\u4e8e\u63d0\u5347\u7f51\u7edc\u7f16\u7a0b\u548c\u7cfb\u7edf\u7ba1\u7406\u7684\u4e13\u4e1a\u80fd\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u4e86 Linux \u64cd\u4f5c&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-208406","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208406"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208406\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}