From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02FF6C388F7 for ; Wed, 11 Nov 2020 01:00:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9061A21D93 for ; Wed, 11 Nov 2020 01:00:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tFrmibFf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730894AbgKKBAu (ORCPT ); Tue, 10 Nov 2020 20:00:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730254AbgKKBAt (ORCPT ); Tue, 10 Nov 2020 20:00:49 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74909C0613D1 for ; Tue, 10 Nov 2020 17:00:49 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id h62so495069wme.3 for ; Tue, 10 Nov 2020 17:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PfikgVvpUvXZs7DQuOy+rTzLYd8b6L/qeLd1NMfmpZI=; b=tFrmibFfidrT43C6ZlEuEgqCsHOVQpN2Q/8FdSKTAuTAtOf2St1tyw+wIL29gQenWa qnJxiQhT/QRGOXT0YQOUXtAg7QpsX3rbCI/4BK87iupISzb0odF1UdEkMtsZUK0ojKx3 kT5tb6J9DZiCGzjCRo60lpD91jsk83AXdHLklWSdtTW9tNdyO/u89wtphWLazsdiafhK LFeqWtfLcIJEUsL9oTXKQhp5G7pnWYKUl6Q/my51KtHS5DhrFVeujy75lg23cx8obcGe Id8UHULAX/zZvb+UHGPkM/on5NO75M8eV1uaM1gbrLtGuPrkO7xVvkUlMwiILAn1sTrZ mmsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:autocrypt:subject:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PfikgVvpUvXZs7DQuOy+rTzLYd8b6L/qeLd1NMfmpZI=; b=en8qvbrIuiMQw45RqGNF5K6WHQ+NKjPiviwtWeEPw+q4eHk86YWtRtQTynKIiCdPqi qMAgMkzLvJCDbrw0iEMMP2W5Bbfywbe75LSEvuApANNbxo5LD3ey0HaBofo1AdCJ+ioD bjjUwyonk/z3u6LlBI/kXwsLZJvtrwBapa3nysqOjvACKMPoyB/rvmojLyZdO48kX6Hi wknX4LqAf64EOEQF4UFMFoNYQTYtxsvxmwuKzRe7ATb8Ry6ULgkBbP7skLS6R6imB3rF Oozj8CiarQjrcIOC6Y28/rIs29eQbWnaMHZs59p9yybErH5dFPNIDKEOzSQH+X73pzFd 1EoQ== X-Gm-Message-State: AOAM5318WL3bskXYCDOLToKZ//1oCm/aZEzroQQFTpn9NxrLTZRZzv8W aaTXiPzI3l2QJJUGjLDu1NmZgz2VGAjKRQ== X-Google-Smtp-Source: ABdhPJzlugzh515bJVZcvSKwjDoA6x+yYmRpwlzraGDFEOIL4fEm7P9LR2AILqOptyCkBJKCSxWVfA== X-Received: by 2002:a1c:9dcc:: with SMTP id g195mr820921wme.113.1605056447817; Tue, 10 Nov 2020 17:00:47 -0800 (PST) Received: from [192.168.1.96] (host109-152-100-164.range109-152.btcentralplus.com. [109.152.100.164]) by smtp.gmail.com with ESMTPSA id x81sm598256wmg.5.2020.11.10.17.00.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Nov 2020 17:00:47 -0800 (PST) To: Victor Stewart , io-uring References: From: Pavel Begunkov Autocrypt: addr=asml.silence@gmail.com; prefer-encrypt=mutual; keydata= mQINBFmKBOQBEAC76ZFxLAKpDw0bKQ8CEiYJRGn8MHTUhURL02/7n1t0HkKQx2K1fCXClbps bdwSHrhOWdW61pmfMbDYbTj6ZvGRvhoLWfGkzujB2wjNcbNTXIoOzJEGISHaPf6E2IQx1ik9 6uqVkK1OMb7qRvKH0i7HYP4WJzYbEWVyLiAxUj611mC9tgd73oqZ2pLYzGTqF2j6a/obaqha +hXuWTvpDQXqcOZJXIW43atprH03G1tQs7VwR21Q1eq6Yvy2ESLdc38EqCszBfQRMmKy+cfp W3U9Mb1w0L680pXrONcnlDBCN7/sghGeMHjGKfNANjPc+0hzz3rApPxpoE7HC1uRiwC4et83 CKnncH1l7zgeBT9Oa3qEiBlaa1ZCBqrA4dY+z5fWJYjMpwI1SNp37RtF8fKXbKQg+JuUjAa9 Y6oXeyEvDHMyJYMcinl6xCqCBAXPHnHmawkMMgjr3BBRzODmMr+CPVvnYe7BFYfoajzqzq+h EyXSl3aBf0IDPTqSUrhbmjj5OEOYgRW5p+mdYtY1cXeK8copmd+fd/eTkghok5li58AojCba jRjp7zVOLOjDlpxxiKhuFmpV4yWNh5JJaTbwCRSd04sCcDNlJj+TehTr+o1QiORzc2t+N5iJ NbILft19Izdn8U39T5oWiynqa1qCLgbuFtnYx1HlUq/HvAm+kwARAQABtDFQY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kzbsuym8RVpAZbLzLPIYK/J3RTErL6Z99N2 m3J6pjwSJY/zNwuFPs9zGEnRO4g0BUbwGdbuvDzaq6/3OJLKohr5eLXNU3JkT+3HezydWm3W OPhauth7W0db74Qd49HXK0xe/aPrK+Cp+kU1HRactyNtF8jZQbhMCC8vMGukZtWaAwpjWiiH bA== Subject: Re: io_uring-only sendmsg + recvmsg zerocopy Message-ID: <3913bbb5-50ec-6ad9-13c9-d49a8b7f7e89@gmail.com> Date: Wed, 11 Nov 2020 00:57:43 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 11/11/2020 00:07, Victor Stewart wrote: > On Tue, Nov 10, 2020 at 11:26 PM Pavel Begunkov wrote: >>> we'd be looking at approx +100% throughput each on the send and recv >>> paths (per TCP_ZEROCOPY_RECEIVE benchmarks).> >>> these would be io_uring only operations given the sendmsg completion >>> logic described below. want to get some conscious that this design >>> could/would be acceptable for merging before I begin writing the code. >>> >>> the problem with zerocopy send is the asynchronous ACK from the NIC >>> confirming transmission. and you can’t just block on a syscall til >>> then. MSG_ZEROCOPY tackled this by putting the ACK on the >>> MSG_ERRQUEUE. but that logic is very disjointed and requires a double >>> completion (once from sendmsg once the send is enqueued, and again >>> once the NIC ACKs the transmission), and requires costly userspace >>> bookkeeping. >>> >>> so what i propose instead is to exploit the asynchrony of io_uring. >>> >>> you’d submit the IORING_OP_SENDMSG_ZEROCOPY operation, and then >>> sometime later receive the completion event on the ring’s completion >>> queue (either failure or success once ACK-ed by the NIC). 1 unified >>> completion flow. >> >> I though about it after your other email. It makes sense for message >> oriented protocols but may not for streams. That's because a user >> may want to call >> >> send(); >> send(); >> >> And expect right ordering, and that where waiting for ACK may add a lot >> of latency, so returning from the call here is a notification that "it's >> accounted, you may send more and order will be preserved". >> >> And since ACKs may came a long after, you may put a lot of code and stuff >> between send()s and still suffer latency (and so potentially throughput >> drop). >> >> As for me, for an optional feature sounds sensible, and should work well >> for some use cases. But for others it may be good to have 2 of >> notifications (1. ready to next send(), 2. ready to recycle buf). >> E.g. 2 CQEs, that wouldn't work without a bit of io_uring patching. >> > > we could make it datagram only, like check the socket was created with no need, streams can also benefit from it. > SOCK_DGRAM and fail otherwise... if it requires too much io_uring > changes / possible regression to accomodate a 2 cqe mode. May be easier to do via two requests with the second receiving errors (yeah, msg_control again). >>> we can somehow tag the socket as registered to io_uring, then when the >> >> I'd rather tag a request > > as long as the NIC is able to find / callback the ring about > transmission ACK, whatever the path of least resistance is is best. > >> >>> NIC ACKs, instead of finding the socket's error queue and putting the >>> completion there like MSG_ZEROCOPY, the kernel would find the io_uring >>> instance the socket is registered to and call into an io_uring >>> sendmsg_zerocopy_completion function. Then the cqe would get pushed >>> onto the completion queue.> >>> the "recvmsg zerocopy" is straight forward enough. mimicking >>> TCP_ZEROCOPY_RECEIVE, i'll go into specifics next time. >> >> Receive side is inherently messed up. IIRC, TCP_ZEROCOPY_RECEIVE just >> maps skbuffs into userspace, and in general unless there is a better >> suited protocol (e.g. infiniband with richier src/dst tagging) or a very >> very smart NIC, "true zerocopy" is not possible without breaking >> multiplexing. >> >> For registered buffers you still need to copy skbuff, at least because >> of security implications. > > we can actually just force those buffers to be mmap-ed, and then when > packets arrive use vm_insert_pin or remap_pfn_range to change the > physical pages backing the virtual memory pages submmited for reading > via msg_iov. so it's transparent to userspace but still zerocopy. > (might require the user to notify io_uring when reading is > completed... but no matter). Yes, with io_uring zerocopy-recv may be done better than TCP_ZEROCOPY_RECEIVE but 1) it's still a remap. Yes, zerocopy, but not ideal 2) won't work with registered buffers, which is basically a set of pinned pages that have a userspace mapping. After such remap that mapping wouldn't be in sync and that gets messy. >>> the other big concern is the lifecycle of the persistent memory >>> buffers in the case of nefarious actors. but since we already have >>> buffer registration for O_DIRECT, I assume those mechanics already >> >> just buffer registration, not specifically for O_DIRECT >> >>> address those issues and can just be repurposed? >> >> Depending on how long it could stuck in the net stack, we might need >> to be able to cancel those requests. That may be a problem. > > I spoke about this idea with Willem the other day and he mentioned... > > "As long as the mappings aren't unwound on process exit. But then you The pages won't be unpinned until all/related requests are gone, but for that on exit io_uring waits for them to complete. That's one of the reasons why either requests should be cancellable or short-lived and somewhat predictably time-bound. > open up to malicious applications that purposely register ranges and > then exit. The basics are straightforward to implement, but it's not > that easy to arrive at something robust." > >> >>> >>> and so with those persistent memory buffers, you'd only pay the cost >>> of pinning the memory into the kernel once upon registration, before >>> you even start your server listening... thus "free". versus pinning >>> per sendmsg like with MSG_ZEROCOPY... thus "true zerocopy". -- Pavel Begunkov