{"id":119737,"date":"2026-10-30T08:19:09","date_gmt":"2026-10-30T00:19:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/119737.html"},"modified":"2026-10-30T08:19:09","modified_gmt":"2026-10-30T00:19:09","slug":"io_uring-%e7%9a%84%e5%bc%82%e6%ad%a5%e4%ba%8b%e4%bb%b6%e8%bd%ae%e8%af%a2%ef%bc%88ioring_op_poll_add%ef%bc%89%ef%bc%9a%e6%9e%84%e5%bb%ba%e7%99%be%e4%b8%87%e5%b9%b6%e5%8f%91%e9%95%bf%e8%bf%9e%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/119737.html","title":{"rendered":"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030001908-6ae3e27c965a2.webp\" alt=\"\u5c01\u9762\u4fe1\u606f\u56fe\" \/><\/p>\n<p>\u5728\u5373\u65f6\u901a\u8baf&#xff08;IM&#xff09;\u3001\u957f\u8fde\u63a5\u7f51\u5173\u3001\u7269\u8054\u7f51&#xff08;IoT&#xff09;\u4f20\u611f\u5668\u6c47\u805a\u8282\u70b9\u7b49\u6d77\u91cf\u5e76\u53d1\u63a5\u5165\u573a\u666f\u4e0b&#xff0c;\u5355\u53f0\u7269\u7406\u673a\u901a\u5e38\u9700\u8981\u540c\u65f6\u7ef4\u6301\u6570\u5341\u4e07\u4e43\u81f3\u6570\u767e\u4e07\u6761\u5904\u4e8e\u95f2\u7f6e\u72b6\u6001&#xff08;Idle&#xff09;\u7684 TCP \u957f\u8fde\u63a5\u3002\u5728\u8fc7\u53bb\u7684\u67b6\u6784\u4f53\u7cfb\u4e2d&#xff0c;\u552f\u4e00\u7684\u6807\u51c6\u89e3\u6cd5\u662f\u57fa\u4e8e epoll \u7684\u4e8b\u4ef6\u591a\u8def\u590d\u7528\u3002\u7136\u800c&#xff0c;\u968f\u7740\u5e76\u53d1\u8fde\u63a5\u6570\u7a81\u7834 100 \u4e07\u5927\u5173&#xff0c;epoll \u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u4e0e\u63a7\u5236\u6d41\u8bbe\u8ba1\u9010\u6e10\u663e\u9732\u51fa\u5176\u56fa\u6709\u7684\u6027\u80fd\u5929\u82b1\u677f&#xff1a;\u57fa\u4e8e\u7ea2\u9ed1\u6811\u7684\u4e8b\u4ef6\u76d1\u542c\u8868\u5728\u9ad8\u9891\u589e\u5220\u65f6\u4f34\u968f\u7740\u5168\u5c40\u4e92\u65a5\u9501\u7ade\u4e89&#xff0c;\u9891\u7e41\u7684 epoll_ctl \u7cfb\u7edf\u8c03\u7528\u5728\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u4e4b\u95f4\u6495\u626f&#xff0c;\u5bfc\u81f4\u7cfb\u7edf\u65e0\u6cd5\u81ea\u62d4\u5730\u9677\u5165\u7279\u6743\u7ea7\u5207\u6362\u5f00\u9500\u4e2d\u3002<\/p>\n<p>io_uring \u63d0\u4f9b\u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\u64cd\u4f5c\u7b26\u2014\u2014IORING_OP_POLL_ADD&#xff08;\u4ee5\u53ca\u73b0\u4ee3\u5185\u6838\u652f\u6301\u7684 IORING_POLL_ADD_MULTI&#xff09;&#xff0c;\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f7b\u5e95\u89e3\u8026\u4e14\u6027\u80fd\u66f4\u5f3a\u52b2\u7684\u66ff\u4ee3\u67b6\u6784\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u50cf\u63d0\u4ea4\u666e\u901a\u5f02\u6b65\u8bfb\u5199\u8bf7\u6c42\u4e00\u6837&#xff0c;\u5411\u73af\u5f62\u65e0\u9501\u63d0\u4ea4\u961f\u5217&#xff08;SQ&#xff09;\u6295\u9012\u7f51\u7edc\u5957\u63a5\u5b57\u7684\u4e8b\u4ef6\u76d1\u542c\u610f\u56fe&#xff0c;\u5185\u6838\u5168\u6743\u63a5\u7ba1\u7b49\u5f85\u961f\u5217\u9a71\u52a8&#xff0c;\u5e76\u5728\u4e8b\u4ef6\u5c31\u7eea\u65f6\u5c06\u7ed3\u679c\u7edf\u4e00\u8f93\u51fa\u81f3\u5b8c\u6210\u961f\u5217&#xff08;CQ&#xff09;\u3002\u8fd9\u4e0d\u4ec5\u62b9\u5e73\u4e86\u6587\u4ef6 I\/O \u4e0e\u7f51\u7edc\u4e8b\u4ef6\u4e4b\u95f4\u7684\u5272\u88c2&#xff0c;\u66f4\u4e3a\u767e\u4e07\u7ea7\u5e76\u53d1\u670d\u52a1\u5668\u8d4b\u4e88\u4e86\u524d\u6240\u672a\u6709\u7684\u541e\u5410\u80fd\u529b\u3002<\/p>\n<h4>\u5e95\u5c42\u673a\u7406\u900f\u89c6&#xff1a;IORING_OP_POLL_ADD vs epoll_ctl<\/h4>\n<p>\u8981\u7406\u89e3 IORING_OP_POLL_ADD \u7684\u5a01\u529b&#xff0c;\u5fc5\u987b\u4ece\u5185\u6838\u7b49\u5f85\u961f\u5217&#xff08;Wait Queue&#xff09;\u7684\u6302\u8f7d\u8def\u5f84\u5207\u5165&#xff1a;<\/p>\n<li>epoll \u7684\u6811\u72b6\u7ba1\u7406\u4e0e\u63a7\u5236\u6d41\u635f\u8017&#xff1a;\u5f53\u8c03\u7528 epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &amp;ev) \u65f6&#xff0c;\u5185\u6838\u5fc5\u987b\u5148\u901a\u8fc7\u54c8\u5e0c\u8868\u67e5\u627e\u76ee\u6807 struct file&#xff0c;\u7136\u540e\u5c06\u5176\u63d2\u5165\u7ea2\u9ed1\u6811&#xff08;ep-&gt;rbr&#xff09;&#xff0c;\u540c\u65f6\u8fd8\u8981\u83b7\u53d6\u81ea\u65cb\u9501\u6216\u4e92\u65a5\u9501&#xff08;ep-&gt;lock&#xff09;\u3002\u5f53\u5927\u91cf\u5ba2\u6237\u7aef\u53d1\u751f\u9891\u7e41\u65ad\u8fde\u91cd\u8fde\u65f6&#xff0c;\u7ea2\u9ed1\u6811\u7684\u65cb\u8f6c\u5e73\u8861\u4e0e\u9501\u7b49\u5f85\u5f00\u9500\u6025\u5267\u98d9\u5347\u3002<\/li>\n<li>io_uring \u7684\u76f4\u63a5\u56de\u8c03\u6302\u8f7d&#xff08;Direct Callback Insertion&#xff09;&#xff1a;IORING_OP_POLL_ADD \u5c06\u6bcf\u6b21\u76d1\u542c\u8bf7\u6c42\u5efa\u6a21\u4e3a\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u63d0\u4ea4\u961f\u5217\u9879&#xff08;SQE&#xff09;\u3002\u5f53 SQE \u88ab\u5185\u6838\u6d88\u8d39\u65f6&#xff0c;\u5185\u6838\u76f4\u63a5\u8c03\u7528\u76ee\u6807\u5957\u63a5\u5b57\u5e95\u5c42\u6587\u4ef6\u64cd\u4f5c\u96c6\u4e2d\u7684 file-&gt;f_op-&gt;poll()&#xff0c;\u5e76\u5c06\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u7b49\u5f85\u961f\u5217\u6761\u76ee&#xff08;struct io_poll_iocb&#xff09;\u6302\u5165\u5957\u63a5\u5b57\u81ea\u8eab\u7684\u7b49\u5f85\u5934&#xff08;sk_sleep(sk)&#xff09;\u3002\u8fd9\u91cc\u5b8c\u5168\u6ca1\u6709\u5168\u5c40\u7ea2\u9ed1\u6811\u7684\u5f00\u9500&#xff0c;\u6240\u6709\u72b6\u6001\u5747\u4f9d\u6258 io_uring \u81ea\u8eab\u7684\u65e0\u9501\u73af\u5f62\u7f13\u51b2\u533a\u8fdb\u884c\u95ed\u73af\u7ba1\u7406\u3002<\/li>\n<li>\u591a\u91cd\u8f6e\u8be2\u6a21\u5f0f&#xff08;IORING_POLL_ADD_MULTI&#xff09;&#xff1a;\u5728\u65e9\u671f\u7684 io_uring \u4e2d&#xff0c;IORING_OP_POLL_ADD \u662f\u201c\u4e00\u6b21\u6027\u89e6\u53d1&#xff08;One-shot&#xff09;\u201d\u7684&#xff0c;\u4e8b\u4ef6\u5c31\u7eea\u5e76\u4ea7\u751f CQE \u540e\u76d1\u542c\u81ea\u52a8\u6ce8\u9500&#xff0c;\u5fc5\u987b\u91cd\u65b0\u63d0\u4ea4 SQE\u3002\u81ea Linux 5.13 \u8d77&#xff0c;\u5f15\u5165\u4e86 IORING_POLL_ADD_MULTI \u6807\u5fd7&#xff0c;\u4f7f\u8f6e\u8be2\u8f6c\u53d8\u4e3a\u201c\u6301\u4e45\u5316\u6301\u7eed\u76d1\u542c\u201d&#xff1a;\u53ea\u8981\u6ca1\u6709\u88ab\u663e\u5f0f\u53d6\u6d88\u6216\u5bf9\u7aef\u5173\u95ed&#xff0c;\u53ea\u8981\u5e95\u5c42\u4ea7\u751f\u65b0\u7684\u53ef\u8bfb\u5199\u4e8b\u4ef6&#xff0c;\u5185\u6838\u5c31\u4f1a\u6e90\u6e90\u4e0d\u65ad\u5730\u751f\u6210\u643a\u5e26 IORING_CQE_F_MORE \u6807\u5fd7\u7684 CQE&#xff0c;\u5f7b\u5e95\u6d88\u9664\u4e86\u6d77\u91cf\u957f\u8fde\u63a5\u5728\u8fd0\u884c\u65f6\u7684\u4efb\u4f55\u91cd\u6ce8\u518c\u6210\u672c\u3002<\/li>\n<p>[\u767e\u4e07\u5ba2\u6237\u7aef TCP \u8fde\u63a5\u6c60]<br \/>\n        |<br \/>\n[\u63d0\u4ea4 IORING_OP_POLL_ADD \u6279\u91cf\u4efb\u52a1] (\u901a\u8fc7\u7528\u6237\u6001\u65e0\u9501\u73af\u5f62\u961f\u5217 SQ \u96f6\u62f7\u8d1d\u63d0\u4ea4)<br \/>\n        |<br \/>\n[\u5185\u6838\u9a71\u52a8\u5c42] &#8212;&gt; \u76f4\u63a5\u5c06 io_poll_iocb \u6ce8\u518c\u8fdb sk-&gt;sk_sleep<br \/>\n        |<br \/>\n   (\u7f51\u7edc\u6570\u636e\u5305\u5230\u8fbe \/ \u5524\u9192\u4e2d\u65ad)<br \/>\n        v<br \/>\n[\u5185\u6838\u7b49\u5f85\u961f\u5217\u56de\u8c03 io_poll_wake] &#8212;&gt; \u751f\u6210\u5c31\u7eea\u4e8b\u4ef6<br \/>\n        |<br \/>\n        &#043;&#8212;&gt; \u82e5\u914d\u7f6e\u4e86 MULTI: \u4fdd\u6301\u6302\u8f7d&#xff0c;\u4ea7\u751f CQE (\u8bbe\u7f6e IORING_CQE_F_MORE)<br \/>\n        &#043;&#8212;&gt; \u82e5\u672a\u914d\u7f6e MULTI: \u89e3\u9664\u6302\u8f7d&#xff0c;\u4ea7\u751f\u5355\u6b21 CQE<br \/>\n        |<br \/>\n[\u7528\u6237\u6001\u73af\u5f62\u961f\u5217 CQ] &lt;&#8212; \u5e94\u7528\u7a0b\u5e8f\u6279\u91cf\u6279\u91cf\u635e\u53d6&#xff0c;0 \u6b21\u7cfb\u7edf\u8c03\u7528\u7cfb\u7edf\u9677\u5165<\/p>\n<h4>C23 \u6807\u51c6\u5b9e\u6218&#xff1a;\u767e\u4e07\u957f\u8fde\u63a5\u4e8b\u4ef6\u8f6e\u8be2\u9a71\u52a8\u6838\u5fc3<\/h4>\n<p>\u4e0b\u9762\u7ed9\u51fa\u7b26\u5408 C23 \u6807\u51c6\u7684\u9ad8\u6027\u80fd\u7f51\u7edc\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u6838\u5fc3\u5b9e\u73b0\u3002\u4ee3\u7801\u8fd0\u7528\u4e86\u663e\u5f0f\u5e38\u91cf\u3001\u5185\u5b58\u5bf9\u9f50\u4e0e\u7cfb\u7edf\u8c03\u7528\u5305\u88c5\u5668&#xff0c;\u6f14\u793a\u5982\u4f55\u6279\u91cf\u6ce8\u518c\u4e0a\u4e07\u4e2a\u5957\u63a5\u5b57\u7684\u4e8b\u4ef6\u76d1\u542c\u5e76\u5b9e\u73b0\u6301\u4e45\u5316\u8f6e\u8be2\u3002<\/p>\n<p>#define _GNU_SOURCE<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;stdint.h&gt;<br \/>\n#include &lt;stdbool.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;fcntl.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include &lt;poll.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include &lt;netinet\/in.h&gt;<br \/>\n#include &lt;linux\/io_uring.h&gt;<br \/>\n#include &lt;sys\/syscall.h&gt;<br \/>\n#include &lt;sys\/mman.h&gt;<\/p>\n<p>constexpr size_t QUEUE_DEPTH &#061; 4096;<br \/>\nconstexpr size_t BATCH_SUBMIT &#061; 64;<\/p>\n<p>static inline int io_uring_setup(uint32_t entries, struct io_uring_params *p) {<br \/>\n    return (int)syscall(__NR_io_uring_setup, entries, p);<br \/>\n}<\/p>\n<p>static inline int io_uring_enter(int fd, uint32_t to_submit, uint32_t min_complete,<br \/>\n                                 uint32_t flags, sigset_t *sig) {<br \/>\n    return (int)syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags, sig);<br \/>\n}<\/p>\n<p>\/\/ \u73af\u5f62\u961f\u5217\u6307\u9488\u7ba1\u7406\u7ed3\u6784\u4f53<br \/>\ntypedef struct {<br \/>\n    int ring_fd;<br \/>\n    uint32_t *sq_head;<br \/>\n    uint32_t *sq_tail;<br \/>\n    uint32_t *sq_ring_mask;<br \/>\n    uint32_t *sq_array;<br \/>\n    struct io_uring_sqe *sqes;<\/p>\n<p>    uint32_t *cq_head;<br \/>\n    uint32_t *cq_tail;<br \/>\n    uint32_t *cq_ring_mask;<br \/>\n    struct io_uring_cqe *cqes;<br \/>\n} UringContext;<\/p>\n<p>\/\/ \u6ce8\u518c\u5957\u63a5\u5b57\u7684\u6301\u4e45\u5316\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2 (Poll Add Multi)<br \/>\nbool add_socket_poll_multishot(UringContext *ctx, int socket_fd, uint32_t poll_mask) {<br \/>\n    uint32_t tail &#061; *ctx-&gt;sq_tail;<br \/>\n    uint32_t head &#061; *ctx-&gt;sq_head;<br \/>\n    uint32_t mask &#061; *ctx-&gt;sq_ring_mask;<\/p>\n<p>    if (tail &#8211; head &gt;&#061; QUEUE_DEPTH) {<br \/>\n        return false; \/\/ \u961f\u5217\u6ea2\u51fa<br \/>\n    }<\/p>\n<p>    uint32_t index &#061; tail &amp; mask;<br \/>\n    struct io_uring_sqe *sqe &#061; &amp;ctx-&gt;sqes[index];<br \/>\n    memset(sqe, 0, sizeof(*sqe));<\/p>\n<p>    sqe-&gt;opcode &#061; IORING_OP_POLL_ADD;<br \/>\n    sqe-&gt;fd &#061; socket_fd;<br \/>\n    sqe-&gt;poll_events &#061; poll_mask;          \/\/ \u5982 POLLIN | POLLRDHUP<br \/>\n    sqe-&gt;len &#061; IORING_POLL_ADD_MULTI;      \/\/ \u5173\u952e&#xff1a;\u5f00\u542f\u6301\u4e45\u5316\u6301\u7eed\u76d1\u542c<br \/>\n    sqe-&gt;user_data &#061; (uint64_t)socket_fd;  \/\/ \u643a\u5e26\u4e0a\u4e0b\u6587\u53e5\u67c4<\/p>\n<p>    ctx-&gt;sq_array[index] &#061; index;<br \/>\n    __atomic_store_n(ctx-&gt;sq_tail, tail &#043; 1, __ATOMIC_RELEASE);<br \/>\n    return true;<br \/>\n}<\/p>\n<p>\/\/ \u6279\u91cf\u6536\u5272\u5df2\u5c31\u7eea\u4e8b\u4ef6\u5e76\u6267\u884c\u96f6\u62f7\u8d1d I\/O \u8c03\u5ea6<br \/>\nsize_t reap_ready_events(UringContext *ctx, size_t max_events) {<br \/>\n    uint32_t head &#061; *ctx-&gt;cq_head;<br \/>\n    uint32_t tail &#061; __atomic_load_n(ctx-&gt;cq_tail, __ATOMIC_ACQUIRE);<br \/>\n    uint32_t mask &#061; *ctx-&gt;cq_ring_mask;<br \/>\n    size_t reaped &#061; 0;<\/p>\n<p>    while (head !&#061; tail &amp;&amp; reaped &lt; max_events) {<br \/>\n        uint32_t index &#061; head &amp; mask;<br \/>\n        struct io_uring_cqe *cqe &#061; &amp;ctx-&gt;cqes[index];<\/p>\n<p>        int socket_fd &#061; (int)cqe-&gt;user_data;<br \/>\n        int res &#061; cqe-&gt;res;<\/p>\n<p>        if (res &lt; 0) {<br \/>\n            fprintf(stderr, &#034;[-] \u5957\u63a5\u5b57 %d \u8f6e\u8be2\u5f02\u5e38: %s\\\\n&#034;, socket_fd, strerror(-res));<br \/>\n        } else {<br \/>\n            uint32_t revents &#061; (uint32_t)res;<br \/>\n            if (revents &amp; POLLIN) {<br \/>\n                \/\/ \u5957\u63a5\u5b57\u53ef\u8bfb&#xff0c;\u5728\u6b64\u5904\u53ef\u8054\u52a8\u63d0\u4ea4 IORING_OP_RECV \u6216\u6267\u884c\u7528\u6237\u6001\u534f\u8bae\u89e3\u6790<br \/>\n                \/\/ \u6b64\u65f6\u6570\u636e\u5df2\u5c31\u7eea&#xff0c;\u65e0\u9700\u518d\u8c03\u7528 epoll_wait<br \/>\n            }<br \/>\n            if (revents &amp; (POLLERR | POLLHUP | POLLRDHUP)) {<br \/>\n                \/\/ \u8fde\u63a5\u65ad\u5f00\u6216\u5f02\u5e38&#xff0c;\u5173\u95ed\u5957\u63a5\u5b57<br \/>\n                close(socket_fd);<br \/>\n            }<br \/>\n        }<\/p>\n<p>        \/\/ \u68c0\u67e5\u662f\u5426\u4ecd\u7136\u5177\u5907\u591a\u91cd\u76d1\u542c\u6548\u529b<br \/>\n        if (!(cqe-&gt;flags &amp; IORING_CQE_F_MORE)) {<br \/>\n            \/\/ \u82e5\u672a\u8bbe\u7f6e F_MORE&#xff0c;\u8bf4\u660e\u8be5\u5957\u63a5\u5b57\u5355\u6b21\u76d1\u542c\u5df2\u5931\u6548\u6216\u9047\u5230\u7ec8\u6b62\u9519\u8bef<br \/>\n        }<\/p>\n<p>        head&#043;&#043;;<br \/>\n        reaped&#043;&#043;;<br \/>\n    }<\/p>\n<p>    __atomic_store_n(ctx-&gt;cq_head, head, __ATOMIC_RELEASE);<br \/>\n    return reaped;<br \/>\n}<\/p>\n<h4>\u767e\u4e07\u5e76\u53d1\u5b9e\u6218\u4e2d\u7684\u67b6\u6784\u8c03\u4f18\u4e0e\u5185\u5b58\u8fb9\u754c<\/h4>\n<p>\u5728\u5b9e\u9645\u538b\u6d4b 100 \u4e07\u957f\u8fde\u63a5\u5e76\u53d1\u73af\u5883\u65f6&#xff0c;\u5fc5\u987b\u7279\u522b\u6ce8\u610f\u4ee5\u4e0b\u4e24\u9879\u7cfb\u7edf\u7ea7\u8c03\u4f18&#xff1a;<\/p>\n<li>\u5185\u6838\u6587\u4ef6\u63cf\u8ff0\u7b26\u9650\u5236\u4e0e\u56fa\u5b9a\u8868\u4f18\u5316&#xff1a;\u767e\u4e07\u5e76\u53d1\u8fde\u63a5\u9700\u8981\u5c06\u7cfb\u7edf\u7684 file-max \u4ee5\u53ca\u8fdb\u7a0b\u7684 rlimit_nofile \u8c03\u6574\u81f3 150 \u4e07\u4ee5\u4e0a\u3002\u540c\u65f6&#xff0c;\u5e94\u5f53\u5c06\u5957\u63a5\u5b57\u4e0e IORING_REGISTER_FILES \u7ed3\u5408\u4f7f\u7528&#xff0c;\u4f7f\u5f97\u4e8b\u4ef6\u901a\u77e5\u76f4\u63a5\u4f7f\u7528\u6574\u578b\u69fd\u4f4d\u7d22\u5f15\u5b9a\u4f4d\u5185\u90e8\u5185\u6838\u53e5\u67c4&#xff0c;\u907f\u514d\u767e\u4e07\u7ea7 FD \u5e26\u6765\u7684\u539f\u5b50\u5f15\u7528\u4e89\u7528\u3002<\/li>\n<li>CQ \u73af\u5f62\u6ea2\u51fa\u9632\u62a4&#xff08;CQ Ring Overflow&#xff09;&#xff1a;\u7531\u4e8e\u5f00\u542f\u4e86 IORING_POLL_ADD_MULTI&#xff0c;\u5f53\u7a81\u53d1\u7f51\u7edc\u6d2a\u5cf0\u5230\u8fbe\u65f6&#xff0c;\u5982\u679c\u7528\u6237\u6001\u4e8b\u4ef6\u6d88\u8d39\u4e0d\u591f\u53ca\u65f6&#xff0c;\u5927\u91cf\u6d8c\u73b0\u7684 CQE \u53ef\u80fd\u4f1a\u8fc5\u901f\u586b\u6ee1\u5b8c\u6210\u961f\u5217\u3002\u5728\u521d\u59cb\u5316 io_uring \u65f6&#xff0c;\u5fc5\u987b\u914d\u7f6e params.flags |&#061; IORING_SETUP_CQSIZE \u5c06 CQ \u5927\u5c0f\u6269\u5bb9\u81f3 SQ \u7684\u4e24\u500d\u4ee5\u4e0a&#xff08;\u4f8b\u5982 8192 \u6216\u66f4\u5927&#xff09;&#xff0c;\u6216\u8005\u5f00\u542f\u5185\u6838\u7f13\u51b2\u4fdd\u62a4&#xff0c;\u9632\u6b62\u56e0 CQ \u6ea2\u51fa\u4e22\u5931\u5173\u952e\u7f51\u7edc\u72b6\u6001\u4e8b\u4ef6\u3002<\/li>\n<p>\u901a\u8fc7\u5c06\u7f51\u7edc\u4e8b\u4ef6\u611f\u77e5\u5f7b\u5e95\u878d\u4e3a io_uring \u7edf\u4e00\u73af\u5f62\u7ba1\u9053\u7684\u4e00\u90e8\u5206&#xff0c;\u6211\u4eec\u6210\u529f\u6452\u5f03\u4e86\u4f20\u7edf\u7f51\u7edc\u670d\u52a1\u4e2d\u201cepoll \u76d1\u542c &#043; \u540c\u6b65\/\u975e\u963b\u585e\u8bfb\u5199\u201d\u7684\u53cc\u9636\u6bb5\u5272\u88c2\u67b6\u6784&#xff0c;\u771f\u6b63\u5b9e\u73b0\u4e86\u9762\u5411\u767e\u4e07\u8fde\u63a5\u7684\u6781\u7b80\u3001\u6781\u901f\u5e95\u5c42\u6570\u636e\u9a71\u52a8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5373\u65f6\u901a\u8baf&#xff08;IM&#xff09;\u3001\u957f\u8fde\u63a5\u7f51\u5173\u3001\u7269\u8054\u7f51&#xff08;IoT&#xff09;\u4f20\u611f\u5668\u6c47\u805a\u8282\u70b9\u7b49\u6d77\u91cf\u5e76\u53d1\u63a5\u5165\u573a\u666f\u4e0b&#xff0c;\u5355\u53f0\u7269\u7406\u673a\u901a\u5e38\u9700\u8981\u540c\u65f6\u7ef4\u6301\u6570\u5341\u4e07\u4e43\u81f3\u6570\u767e\u4e07\u6761\u5904\u4e8e\u95f2\u7f6e\u72b6\u6001&#xff08;Idle&#xff09;\u7684 TCP \u957f\u8fde\u63a5\u3002\u5728\u8fc7\u53bb\u7684\u67b6\u6784\u4f53\u7cfb\u4e2d&#xff0c;\u552f\u4e00\u7684\u6807\u51c6\u89e3\u6cd5\u662f\u57fa\u4e8e epoll \u7684\u4e8b\u4ef6\u591a\u8def\u590d\u7528\u3002\u7136\u800c&#xff0c;\u968f\u7740\u5e76\u53d1\u8fde\u63a5\u6570\u7a81\u7834 100 \u4e07\u5927\u5173&#xff0c;epoll \u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u4e0e\u63a7\u5236\u6d41\u8bbe\u8ba1\u9010\u6e10\u663e\u9732\u51fa\u5176\u56fa\u6709\u7684<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13665,13666,13668,13667,3884],"topic":[],"class_list":["post-119737","post","type-post","status-publish","format-standard","hentry","category-server","tag-io_uring","tag-ioring_op_poll_add","tag-13668","tag-13667","tag-epoll"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/119737.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5728\u5373\u65f6\u901a\u8baf&#xff08;IM&#xff09;\u3001\u957f\u8fde\u63a5\u7f51\u5173\u3001\u7269\u8054\u7f51&#xff08;IoT&#xff09;\u4f20\u611f\u5668\u6c47\u805a\u8282\u70b9\u7b49\u6d77\u91cf\u5e76\u53d1\u63a5\u5165\u573a\u666f\u4e0b&#xff0c;\u5355\u53f0\u7269\u7406\u673a\u901a\u5e38\u9700\u8981\u540c\u65f6\u7ef4\u6301\u6570\u5341\u4e07\u4e43\u81f3\u6570\u767e\u4e07\u6761\u5904\u4e8e\u95f2\u7f6e\u72b6\u6001&#xff08;Idle&#xff09;\u7684 TCP \u957f\u8fde\u63a5\u3002\u5728\u8fc7\u53bb\u7684\u67b6\u6784\u4f53\u7cfb\u4e2d&#xff0c;\u552f\u4e00\u7684\u6807\u51c6\u89e3\u6cd5\u662f\u57fa\u4e8e epoll \u7684\u4e8b\u4ef6\u591a\u8def\u590d\u7528\u3002\u7136\u800c&#xff0c;\u968f\u7740\u5e76\u53d1\u8fde\u63a5\u6570\u7a81\u7834 100 \u4e07\u5927\u5173&#xff0c;epoll \u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u4e0e\u63a7\u5236\u6d41\u8bbe\u8ba1\u9010\u6e10\u663e\u9732\u51fa\u5176\u56fa\u6709\u7684\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/119737.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-30T00:19:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030001908-6ae3e27c965a2.webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119737.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/119737.html\",\"name\":\"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-30T00:19:09+00:00\",\"dateModified\":\"2026-10-30T00:19:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/119737.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/119737.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119737.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/119737.html","og_locale":"zh_CN","og_type":"article","og_title":"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5728\u5373\u65f6\u901a\u8baf&#xff08;IM&#xff09;\u3001\u957f\u8fde\u63a5\u7f51\u5173\u3001\u7269\u8054\u7f51&#xff08;IoT&#xff09;\u4f20\u611f\u5668\u6c47\u805a\u8282\u70b9\u7b49\u6d77\u91cf\u5e76\u53d1\u63a5\u5165\u573a\u666f\u4e0b&#xff0c;\u5355\u53f0\u7269\u7406\u673a\u901a\u5e38\u9700\u8981\u540c\u65f6\u7ef4\u6301\u6570\u5341\u4e07\u4e43\u81f3\u6570\u767e\u4e07\u6761\u5904\u4e8e\u95f2\u7f6e\u72b6\u6001&#xff08;Idle&#xff09;\u7684 TCP \u957f\u8fde\u63a5\u3002\u5728\u8fc7\u53bb\u7684\u67b6\u6784\u4f53\u7cfb\u4e2d&#xff0c;\u552f\u4e00\u7684\u6807\u51c6\u89e3\u6cd5\u662f\u57fa\u4e8e epoll \u7684\u4e8b\u4ef6\u591a\u8def\u590d\u7528\u3002\u7136\u800c&#xff0c;\u968f\u7740\u5e76\u53d1\u8fde\u63a5\u6570\u7a81\u7834 100 \u4e07\u5927\u5173&#xff0c;epoll \u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u4e0e\u63a7\u5236\u6d41\u8bbe\u8ba1\u9010\u6e10\u663e\u9732\u51fa\u5176\u56fa\u6709\u7684","og_url":"https:\/\/www.wsisp.com\/helps\/119737.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-30T00:19:09+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030001908-6ae3e27c965a2.webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/119737.html","url":"https:\/\/www.wsisp.com\/helps\/119737.html","name":"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-30T00:19:09+00:00","dateModified":"2026-10-30T00:19:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/119737.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/119737.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/119737.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"io_uring \u7684\u5f02\u6b65\u4e8b\u4ef6\u8f6e\u8be2\uff08IORING_OP_POLL_ADD\uff09\uff1a\u6784\u5efa\u767e\u4e07\u5e76\u53d1\u957f\u8fde\u63a5\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u7684\u5e95\u5c42\u89e3\u5bc6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=119737"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119737\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=119737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=119737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=119737"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=119737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}