Skip to content

virtio-net: read/write multiple messages per syscall on macOS #405

@nirs

Description

@nirs

On macOS we can double read and write performance and reduce cpu usage with the private APIs:

ssize_t recvmsg_x(int s, const struct msghdr_x *msgp, unsigned int cnt, int flags);
ssize_t sendmsg_x(int s, const struct msghdr_x *msgp, unsigned int cnt, int flags);

These are like recvmmsg and sendmmsg in Linux/FreeBSD, transferring multiple messages in one syscall.

The best documentation is here:
https://github.com/nirs/vmnet-helper/blob/main/socket_x.h

Example usage in vmnet-helper:

In both case we fallback to standard read/write as a backup.

I learned about this from bun:
https://github.com/oven-sh/bun/blob/main/packages/bun-usockets/src/internal/networking/bsd.h

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions