# \[PATCH 1/1\] virtio/vsock: Make vsock virtio packet buff size configurable

- Subsystems: VIRTIO AND VHOST VSOCK DRIVER, VIRTIO CORE, VM SOCKETS (AF\_VSOCK), NETWORKING \[GENERAL\], THE REST
- Maintainers: Stefan Hajnoczi, Stefano Garzarella, "Michael S. Tsirkin", Jason Wang, Eugenio Pérez, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
- List: virtualization
- 2 messages, 2 authors
- Page: https://ratatoskr.run/virtualization/2021/07/1453484/t

## \[PATCH 1/1\] virtio/vsock: Make vsock virtio packet buff size configurable

- From: Lee Jones \<hidden\>
- Date: 2021-07-21 14:30:23 
- Message: https://ratatoskr.run/virtualization/2021/07/1453484.md

```text
From: Ram Muthiah <redacted>

After a virtual device has been running for some time, the SLAB
sustains ever increasing fragmentation. Contributing to this
fragmentation are the virtio packet buffer allocations which
are a drain on 64Kb compound pages. Eventually these can't be
allocated due to fragmentation.

To enable successful allocations for this packet buffer, the
packet buffer's size needs to be reduced.

In order to enable a reduction without impacting current users,
this variable is being exposed as a command line parameter.

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <redacted>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Stefano Garzarella <sgarzare@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: <redacted>
Cc: <redacted>
Cc: <redacted>
Signed-off-by: Ram Muthiah <redacted>
Signed-off-by: Lee Jones <redacted>
---
 include/linux/virtio_vsock.h            | 4 +++-
 net/vmw_vsock/virtio_transport_common.c | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index 35d7eedb5e8e4..8c77d60a74d34 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -7,9 +7,11 @@
 #include <net/sock.h>
 #include <net/af_vsock.h>
 
+extern uint virtio_transport_max_vsock_pkt_buf_size;
+
 #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE	(1024 * 4)
 #define VIRTIO_VSOCK_MAX_BUF_SIZE		0xFFFFFFFFUL
-#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE		(1024 * 64)
+#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE		virtio_transport_max_vsock_pkt_buf_size
 
 enum {
 	VSOCK_VQ_RX     = 0, /* for host to guest data */
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 169ba8b72a630..d0d913afec8b6 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -26,6 +26,10 @@
 /* Threshold for detecting small packets to copy */
 #define GOOD_COPY_LEN  128
 
+uint virtio_transport_max_vsock_pkt_buf_size = 1024 * 64;
+module_param(virtio_transport_max_vsock_pkt_buf_size, uint, 0444);
+EXPORT_SYMBOL_GPL(virtio_transport_max_vsock_pkt_buf_size);
+
 static const struct virtio_transport *
 virtio_transport_get_ops(struct vsock_sock *vsk)
 {
-- 
2.32.0.402.g57bb445576-goog

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
```

## Re: \[PATCH 1/1\] virtio/vsock: Make vsock virtio packet buff size configurable

- From: Stefano Garzarella \<sgarzare@redhat.com\>
- Date: 2021-07-22 12:55:32 
- Message: https://ratatoskr.run/virtualization/2021/07/1454509.md

```text
On Wed, Jul 21, 2021 at 03:30:00PM +0100, Lee Jones wrote:
>From: Ram Muthiah <redacted>
>
>After a virtual device has been running for some time, the SLAB
>sustains ever increasing fragmentation. Contributing to this
>fragmentation are the virtio packet buffer allocations which
>are a drain on 64Kb compound pages. Eventually these can't be
>allocated due to fragmentation.
>
>To enable successful allocations for this packet buffer, the
>packet buffer's size needs to be reduced.
>
>In order to enable a reduction without impacting current users,
>this variable is being exposed as a command line parameter.
>
>Cc: "Michael S. Tsirkin" <mst@redhat.com>
>Cc: Jason Wang <redacted>
>Cc: Stefan Hajnoczi <stefanha@redhat.com>
>Cc: Stefano Garzarella <sgarzare@redhat.com>
>Cc: "David S. Miller" <davem@davemloft.net>
>Cc: Jakub Kicinski <kuba@kernel.org>
>Cc: <redacted>
>Cc: <redacted>
>Cc: <redacted>
>Signed-off-by: Ram Muthiah <redacted>
>Signed-off-by: Lee Jones <redacted>
>---
> include/linux/virtio_vsock.h            | 4 +++-
> net/vmw_vsock/virtio_transport_common.c | 4 ++++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
>diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>index 35d7eedb5e8e4..8c77d60a74d34 100644
>--- a/include/linux/virtio_vsock.h
>+++ b/include/linux/virtio_vsock.h
>@@ -7,9 +7,11 @@
> #include <net/sock.h>
> #include <net/af_vsock.h>
>
>+extern uint virtio_transport_max_vsock_pkt_buf_size;
>+
> #define VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE	(1024 * 4)
> #define VIRTIO_VSOCK_MAX_BUF_SIZE		0xFFFFFFFFUL
>-#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE		(1024 * 64)
>+#define VIRTIO_VSOCK_MAX_PKT_BUF_SIZE		virtio_transport_max_vsock_pkt_buf_size
>
> enum {
> 	VSOCK_VQ_RX     = 0, /* for host to guest data */
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index 169ba8b72a630..d0d913afec8b6 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -26,6 +26,10 @@
> /* Threshold for detecting small packets to copy */
> #define GOOD_COPY_LEN  128
>
>+uint virtio_transport_max_vsock_pkt_buf_size = 1024 * 64;
>+module_param(virtio_transport_max_vsock_pkt_buf_size, uint, 0444);
>+EXPORT_SYMBOL_GPL(virtio_transport_max_vsock_pkt_buf_size);
>+

Maybe better to add an entry under sysfs similar to what Jiang proposed here:
https://lists.linuxfoundation.org/pipermail/virtualization/2021-June/054769.html

Thanks,
Stefano

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
```
