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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29DA2C433F5 for ; Wed, 1 Dec 2021 14:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349964AbhLAOe5 (ORCPT ); Wed, 1 Dec 2021 09:34:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349954AbhLAOey (ORCPT ); Wed, 1 Dec 2021 09:34:54 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABFA1C061574; Wed, 1 Dec 2021 06:31:33 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id 133so20614047wme.0; Wed, 01 Dec 2021 06:31:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to; bh=AVSg4/WN9KI8amUAzB706KjrJrTp7yyBXe9FwK3kyEQ=; b=jM7QXIwvMqX3kHlGHv5N+rmn6xt53uznFdzJZwVuS0WcaCp7zGUlviB+xhqQNShEfm g4RufN4aZSwg3eSgZ4IhG6DFcRU/RqEv8a47sK5s9n2SdcENBFrOgrGS5OCOmF99bMrI IhmjYYB5Wr5fr4J9VtzbKzGGT4rJHuUBBkj9OwPBEsVz+KVeYHhI4EGBP66oQQzICbaa uATXTrOHX2+6mLW+wg1oy8QxNRWdIvfjLsp/HPCMwthDAHKfYUbmnJ7puc1pi4OCbwwQ WbEhg6hLQFK/Kj+uaKD1P/QC+3WiLjnwDJeZzYzs4YKitNj63WT7hiqckKyaLK1iS/aK fnqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to; bh=AVSg4/WN9KI8amUAzB706KjrJrTp7yyBXe9FwK3kyEQ=; b=D8zjFHI4MSjPZesVFmKZZkSDTfJuIBTSCbsKvqer0WG1byWVyCniVGOn8MGzrj8E5s KNbohMw+1ko8SfjbKcYC/UqNT40rJd4evPGYgqIaZXCAz2KWcoSgfNLIk3Sz08nRhqPZ m1ddThVC/el6haesZrHY8C2UTIQ98Fp30VmTtFmbYr9rkp+hl4dFxov6ULvopkZeT5Mf h/fH3Zt77x3URpVlBcI+ImfapzuI/JRZ04HsxNsTmqb2pKQHTD026romkSWbehLrMTr/ tvz9s7N14MKOiFKLNq2GZuTjZkrmWz+DrVP9lQ1Q+ovJebMw7KAkg1rKIXHS47QeDvqQ EeQw== X-Gm-Message-State: AOAM530ve6wb88JrtlHhzEHRg6SxunHLK2wDmb7Qub6uKnzYt8c21HJW ERd4uOQ8SStgbpy7Cj7+cS4w5p8TdWM= X-Google-Smtp-Source: ABdhPJyEsh7sxNG9cVMfb5cRd33/ulVTF1vMZohIgFAzPJSaJTNv9sV4bGcriuctKUR1IHuWJvIZ3w== X-Received: by 2002:a05:600c:4f87:: with SMTP id n7mr7272120wmq.168.1638369091506; Wed, 01 Dec 2021 06:31:31 -0800 (PST) Received: from [192.168.43.77] (82-132-231-182.dab.02.net. [82.132.231.182]) by smtp.gmail.com with ESMTPSA id y7sm19250476wrw.55.2021.12.01.06.31.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Dec 2021 06:31:30 -0800 (PST) Content-Type: multipart/mixed; boundary="------------d3uoUfKURQRySJ6dIsw8imz5" Message-ID: <4c0170fa-5b6f-ff76-0eff-a83ffec9864d@gmail.com> Date: Wed, 1 Dec 2021 14:31:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [RFC 00/12] io_uring zerocopy send Content-Language: en-US To: io-uring@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jakub Kicinski , Jonathan Lemon , "David S . Miller" , Willem de Bruijn , Eric Dumazet , Hideaki YOSHIFUJI , David Ahern , Jens Axboe References: From: Pavel Begunkov In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This is a multi-part message in MIME format. --------------d3uoUfKURQRySJ6dIsw8imz5 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/30/21 15:18, Pavel Begunkov wrote: > Early proof of concept for zerocopy send via io_uring. This is just > an RFC, there are details yet to be figured out, but hope to gather > some feedback. For larger audience, registered buffers is an io_uring feature where it pins in advance the userspace memory and keeps it as an array of pages (bvec in particular). There is extra logic to make sure the pages stay referenced when there are inflight requests using it, so they can avoid grabbing extra page references. Also, as was asked, attaching a standalone .c version of the benchmark. Requires any relatively up-to-date liburing installed. gcc -luring -O2 -o send-zc ./send-zc.c There are also a couple of options added: ./send-zc [options] [-r ] [-f] udp -r is @nr_reqs from the cover-letter, 8 by default, -f sets @flush to true, false by default. > Benchmarking udp (65435 bytes) with a dummy net device (mtu=0xffff): > The best case io_uring=116079 MB/s vs msg_zerocopy=47421 MB/s, > or 2.44 times faster. > > № | test: | BW (MB/s) | speedup > 1 | msg_zerocopy (non-zc) | 18281 | 0.38 > 2 | msg_zerocopy -z (baseline) | 47421 | 1 > 3 | io_uring (@flush=false, nr_reqs=1) | 96534 | 2.03 > 4 | io_uring (@flush=true, nr_reqs=1) | 89310 | 1.88 > 5 | io_uring (@flush=false, nr_reqs=8) | 116079 | 2.44 > 6 | io_uring (@flush=true, nr_reqs=8) | 109722 | 2.31 > > Based on selftests/.../msg_zerocopy but more limited. You can use > msg_zerocopy -r as usual for receive side. > [...] -- Pavel Begunkov --------------d3uoUfKURQRySJ6dIsw8imz5 Content-Type: text/x-csrc; charset=UTF-8; name="send-zc.c" Content-Disposition: attachment; filename="send-zc.c" Content-Transfer-Encoding: base64 LyogU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVCAqLwovKiBiYXNlZCBvbiBsaW51eC1r ZXJuZWwvdG9vbHMvdGVzdGluZy9zZWxmdGVzdHMvbmV0L21zZ196ZXJvY29weS5jICovCi8q IGdjYyAtbHVyaW5nIC1PMiAtbyBzZW5kLXpjIC4vc2VuZC16Yy5jICovCiNpbmNsdWRlIDxz dGRpby5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzdGRpbnQuaD4KI2luY2x1 ZGUgPGFzc2VydC5oPgoKI2luY2x1ZGUgPGVycm5vLmg+CiNpbmNsdWRlIDxmY250bC5oPgoj aW5jbHVkZSA8dW5pc3RkLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNpbmNsdWRlIDxz eXMvdGltZS5oPgojaW5jbHVkZSA8c3lzL3Jlc291cmNlLmg+CiNpbmNsdWRlIDxzeXMvdW4u aD4KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4KI2luY2x1ZGUgPGFycGEvaW5ldC5oPgojaW5j bHVkZSA8ZXJyb3IuaD4KI2luY2x1ZGUgPGxpbWl0cy5oPgojaW5jbHVkZSA8bGludXgvZXJy cXVldWUuaD4KI2luY2x1ZGUgPGxpbnV4L2lmX3BhY2tldC5oPgojaW5jbHVkZSA8bGludXgv aXB2Ni5oPgojaW5jbHVkZSA8bGludXgvc29ja2V0Lmg+CiNpbmNsdWRlIDxsaW51eC9zb2Nr aW9zLmg+CiNpbmNsdWRlIDxuZXQvZXRoZXJuZXQuaD4KI2luY2x1ZGUgPG5ldC9pZi5oPgoj aW5jbHVkZSA8bmV0aW5ldC9pcC5oPgojaW5jbHVkZSA8bmV0aW5ldC9pcDYuaD4KI2luY2x1 ZGUgPG5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