From patchwork Sat Dec 17 19:45:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13075921 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 41000C3DA6E for ; Sat, 17 Dec 2022 19:46:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbiLQTqB (ORCPT ); Sat, 17 Dec 2022 14:46:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiLQTp7 (ORCPT ); Sat, 17 Dec 2022 14:45:59 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE916478; Sat, 17 Dec 2022 11:45:57 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0A95B5FD03; Sat, 17 Dec 2022 22:45:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1671306356; bh=fRQaScZUwNSlmdqZ+Io2YTz+G50P34agK3PANG8xcpg=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=SYrU7wwJjd48bsmEyayCo3z+n3YukZqN12mu5SGqHo5v6byneL+q+3U7GIzPE7BMP hmLUetTPQpw+Xq4pT08RTy7t/sxOwMLs4tCjrK1TSwypxP6GoRAqcxmR6LglHr+wD7 CMpEOtvMSWP4l2zk7yrry12hitXe50XR/Uwwk7a+r/IhTV/qCpMQ3c4gnKKP+txJfh MyAx8n9c8v4GaquwxhFAqnxjuYDiePj0cSKs54jCxtM5uBo8p6MrT8g/0KbsUCkv9v qJnONB7m5fISmnFOsCWgv8/itgjGEX9GLyFY/IGrGmp3yMeEMY4wgcreYpN8cSd6t/ a91p7St8NxhrA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 17 Dec 2022 22:45:55 +0300 (MSK) From: Arseniy Krasnov To: Stefano Garzarella , Stefan Hajnoczi , "edumazet@google.com" , "David S. Miller" , Jakub Kicinski , Paolo Abeni CC: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" , kernel , Krasnov Arseniy , Arseniy Krasnov Subject: [RFC PATCH v1 1/2] virtio/vsock: send credit update depending on SO_RCVLOWAT Thread-Topic: [RFC PATCH v1 1/2] virtio/vsock: send credit update depending on SO_RCVLOWAT Thread-Index: AQHZElAtpIjfFhXnAkiL/v8iyYioYA== Date: Sat, 17 Dec 2022 19:45:55 +0000 Message-ID: In-Reply-To: <39b2e9fd-601b-189d-39a9-914e5574524c@sberdevices.ru> Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: <34A3F028C08A3C47A856A1176E2EEEFC@sberdevices.ru> MIME-Version: 1.0 X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/12/17 15:49:00 #20678428 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This adds extra condition to send credit update message during data read to userspace. Problem arises, when sender waits for the free space on the receiver while receiver waits in 'poll()' until 'rx_bytes' reaches SO_RCVLOWAT value of the socket. With this patch, receiver sends credit update message when number of bytes in it's rx queue is too small to avoid sleeping in 'poll()'. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index a1581c77cf84..4cf26cf8a754 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -362,6 +362,7 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, struct virtio_vsock_sock *vvs = vsk->trans; size_t bytes, total = 0; struct sk_buff *skb; + bool low_rx_bytes; int err = -EFAULT; u32 free_space; @@ -396,6 +397,8 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, } free_space = vvs->buf_alloc - (vvs->fwd_cnt - vvs->last_fwd_cnt); + low_rx_bytes = (vvs->rx_bytes < + sock_rcvlowat(sk_vsock(vsk), 0, INT_MAX)); spin_unlock_bh(&vvs->rx_lock); @@ -405,9 +408,11 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, * too high causes extra messages. Too low causes transmitter * stalls. As stalls are in theory more expensive than extra * messages, we set the limit to a high value. TODO: experiment - * with different values. + * with different values. Also send credit update message when + * number of bytes in rx queue is not enough to wake up reader. */ - if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE) + if (free_space < VIRTIO_VSOCK_MAX_PKT_BUF_SIZE || + low_rx_bytes) virtio_transport_send_credit_update(vsk); return total;