From: Tao Cui <cui.tao@linux.dev>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: cui.tao@linux.dev, akpm@linux-foundation.org,
dgilbert@interlog.com, mkp@kernel.org, loberman@redhat.com,
jmeneghi@redhat.com, kraxel@redhat.com,
vivek.kasireddy@intel.com, jasowangio@gmail.com,
eperezma@redhat.com, stefanha@redhat.com, sgarzare@redhat.com,
rostedt@goodmis.org, vdonnefort@google.com, mhiramat@kernel.org,
jgg@ziepe.ca, kevin.tian@intel.com, axboe@kernel.dk,
linux-mm@kvack.org, James.Bottomley@hansenpartnership.com,
sumit.semwal@linaro.org, christian.koenig@amd.com,
phasta@kernel.org, joro@8bytes.org, will@kernel.org,
linux-scsi@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
kvm@vger.kernel.org, virtualization@lists.linux.dev,
linux-trace-kernel@vger.kernel.org, iommu@lists.linux.dev,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
bobbyeshleman@meta.com, mathieu.desnoyers@efficios.com,
robin.murphy@arm.com, mason@kernel.org, aesteve@redhat.com,
tjmercier@google.com, harry@kernel.org, vbabka@suse.cz,
cuitao@kylinos.cn
Subject: Re: [PATCH 3/7] vhost: account the per-device kernel allocations to memcg
Date: Fri, 20 Nov 2026 07:53:53 +0800 [thread overview]
Message-ID: <1ea66d73-4d40-4d95-855f-4235cbd1d809@linux.dev> (raw)
In-Reply-To: <20261119101239-mutt-send-email-mst@kernel.org>
Hello, Michael,
在 2026/11/19 23:12, Michael S. Tsirkin 写道:
> On Fri, Nov 06, 2026 at 09:18:25PM +0800, Tao Cui wrote:
>> From: Tao Cui <cuitao@kylinos.cn>
>>
>> Everything except the worker struct is allocated with plain GFP_KERNEL:
>> the per-vq iovec and log arrays at VHOST_SET_OWNER, the memory table at
>> VHOST_SET_MEM_TABLE whose size follows the user supplied region count,
>> the pending message nodes, and the vhost_net/vhost_vsock device structs
>> with their fallback to vmalloc. The worker has been accounted since the
>> vhost_task conversion.
>>
>> A container that can open /dev/vhost-net or /dev/vhost-vsock, which
>> device plugins hand out with passthrough, holds roughly 150KB of
>> resident kernel memory per device after SET_OWNER. Charge the rest the
>> same way the worker already is.
>>
>> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>
> should each patch be merged individually?
>
Yes, I think merging them individually is the cleaner path here: the series spans six subsystems, and each maintainer taking their own piece keeps things simple. Jason has already taken patch 5 into iommufd. Please feel free to take patch 3 through your tree.
Thanks,
Tao
>
>> ---
>> drivers/vhost/net.c | 14 ++++++++------
>> drivers/vhost/vhost.c | 16 ++++++++++------
>> drivers/vhost/vsock.c | 5 +++--
>> 3 files changed, 21 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
>> index 4570a4ffbab2..bab6597c696d 100644
>> --- a/drivers/vhost/net.c
>> +++ b/drivers/vhost/net.c
>> @@ -249,7 +249,7 @@ vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy)
>> /* No zero copy backend? Nothing to count. */
>> if (!zcopy)
>> return NULL;
>> - ubufs = kmalloc_obj(*ubufs);
>> + ubufs = kmalloc_obj(*ubufs, GFP_KERNEL_ACCOUNT);
>> if (!ubufs)
>> return ERR_PTR(-ENOMEM);
>> atomic_set(&ubufs->refcount, 1);
>> @@ -302,7 +302,8 @@ static int vhost_net_set_ubuf_info(struct vhost_net *n)
>> if (!zcopy)
>> continue;
>> n->vqs[i].ubuf_info =
>> - kmalloc_objs(*n->vqs[i].ubuf_info, UIO_MAXIOV);
>> + kmalloc_objs(*n->vqs[i].ubuf_info, UIO_MAXIOV,
>> + GFP_KERNEL_ACCOUNT);
>> if (!n->vqs[i].ubuf_info)
>> goto err;
>> }
>> @@ -1344,17 +1345,18 @@ static int vhost_net_open(struct inode *inode, struct file *f)
>> struct xdp_buff *xdp;
>> int i;
>>
>> - n = kvmalloc_obj(*n, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
>> + n = kvmalloc_obj(*n, GFP_KERNEL | __GFP_RETRY_MAYFAIL |
>> + __GFP_ACCOUNT);
>> if (!n)
>> return -ENOMEM;
>> - vqs = kmalloc_objs(*vqs, VHOST_NET_VQ_MAX);
>> + vqs = kmalloc_objs(*vqs, VHOST_NET_VQ_MAX, GFP_KERNEL_ACCOUNT);
>> if (!vqs) {
>> kvfree(n);
>> return -ENOMEM;
>> }
>>
>> queue = kmalloc_array(VHOST_NET_BATCH, sizeof(void *),
>> - GFP_KERNEL);
>> + GFP_KERNEL_ACCOUNT);
>> if (!queue) {
>> kfree(vqs);
>> kvfree(n);
>> @@ -1362,7 +1364,7 @@ static int vhost_net_open(struct inode *inode, struct file *f)
>> }
>> n->vqs[VHOST_NET_VQ_RX].rxq.queue = queue;
>>
>> - xdp = kmalloc_objs(*xdp, VHOST_NET_BATCH);
>> + xdp = kmalloc_objs(*xdp, VHOST_NET_BATCH, GFP_KERNEL_ACCOUNT);
>> if (!xdp) {
>> kfree(vqs);
>> kvfree(n);
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index ea127af58ada..d1274106ad5d 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -526,11 +526,14 @@ static long vhost_dev_alloc_iovecs(struct vhost_dev *dev)
>>
>> for (i = 0; i < dev->nvqs; ++i) {
>> vq = dev->vqs[i];
>> - vq->indirect = kmalloc_objs(*vq->indirect, UIO_MAXIOV);
>> - vq->log = kmalloc_objs(*vq->log, dev->iov_limit);
>> - vq->heads = kmalloc_objs(*vq->heads, dev->iov_limit);
>> + vq->indirect = kmalloc_objs(*vq->indirect, UIO_MAXIOV,
>> + GFP_KERNEL_ACCOUNT);
>> + vq->log = kmalloc_objs(*vq->log, dev->iov_limit,
>> + GFP_KERNEL_ACCOUNT);
>> + vq->heads = kmalloc_objs(*vq->heads, dev->iov_limit,
>> + GFP_KERNEL_ACCOUNT);
>> vq->nheads = kmalloc_array(dev->iov_limit, sizeof(*vq->nheads),
>> - GFP_KERNEL);
>> + GFP_KERNEL_ACCOUNT);
>> if (!vq->indirect || !vq->log || !vq->heads || !vq->nheads)
>> goto err_nomem;
>> }
>> @@ -2053,7 +2056,8 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
>> return -E2BIG;
>> if (max_iotlb_entries <= 0)
>> return -EINVAL;
>> - newmem = kvzalloc_flex(*newmem, regions, mem.nregions);
>> + newmem = kvzalloc_flex(*newmem, regions, mem.nregions,
>> + GFP_KERNEL_ACCOUNT);
>> if (!newmem)
>> return -ENOMEM;
>>
>> @@ -3405,7 +3409,7 @@ EXPORT_SYMBOL_GPL(vhost_disable_notify);
>> struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type)
>> {
>> /* Make sure all padding within the structure is initialized. */
>> - struct vhost_msg_node *node = kzalloc_obj(*node);
>> + struct vhost_msg_node *node = kzalloc_obj(*node, GFP_KERNEL_ACCOUNT);
>> if (!node)
>> return NULL;
>>
>> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>> index 0cb87971d749..600daeb05e7b 100644
>> --- a/drivers/vhost/vsock.c
>> +++ b/drivers/vhost/vsock.c
>> @@ -721,11 +721,12 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file)
>> /* This struct is large and allocation could fail, fall back to vmalloc
>> * if there is no other way.
>> */
>> - vsock = kvmalloc_obj(*vsock, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
>> + vsock = kvmalloc_obj(*vsock, GFP_KERNEL | __GFP_RETRY_MAYFAIL |
>> + __GFP_ACCOUNT);
>> if (!vsock)
>> return -ENOMEM;
>>
>> - vqs = kmalloc_objs(*vqs, ARRAY_SIZE(vsock->vqs));
>> + vqs = kmalloc_objs(*vqs, ARRAY_SIZE(vsock->vqs), GFP_KERNEL_ACCOUNT);
>> if (!vqs) {
>> ret = -ENOMEM;
>> goto out;
>> --
>> 2.43.0
>
next prev parent reply other threads:[~2026-11-19 23:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:18 [PATCH 0/7] memcg: account the remaining uncharged kernel allocations Tao Cui
2026-11-06 13:18 ` [PATCH 1/7] scsi: sg and st: account the command buffer memory to memcg Tao Cui
2026-11-06 13:18 ` [PATCH 2/7] dma-buf/udmabuf: account the page array metadata " Tao Cui
2026-11-06 13:23 ` Christian König
2026-11-06 17:25 ` T.J. Mercier
2026-11-09 2:32 ` Tao Cui
2026-11-09 10:56 ` Christian König
2026-11-09 13:44 ` Albert Esteve
2026-11-06 13:18 ` [PATCH 3/7] vhost: account the per-device kernel allocations " Tao Cui
2026-11-19 15:12 ` Michael S. Tsirkin
2026-11-19 23:53 ` Tao Cui [this message]
2026-11-06 13:18 ` [PATCH 4/7] tracing: account ring buffer pages and trace_array metadata " Tao Cui
2026-11-11 16:47 ` Vincent Donnefort
2026-11-11 23:14 ` Steven Rostedt
2026-11-19 23:47 ` Tao Cui
2026-11-06 13:18 ` [PATCH 5/7] iommufd: account the hw_queue page array " Tao Cui
2026-11-16 19:52 ` Jason Gunthorpe
2026-11-16 20:33 ` Jason Gunthorpe
2026-11-06 13:18 ` [PATCH 6/7] io_uring: account the ring context and SQPOLL thread data " Tao Cui
2026-11-06 13:18 ` [PATCH 7/7] io_uring: account the remaining per-object allocations " Tao Cui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1ea66d73-4d40-4d95-855f-4235cbd1d809@linux.dev \
--to=cui.tao@linux.dev \
--cc=James.Bottomley@hansenpartnership.com \
--cc=aesteve@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bobbyeshleman@meta.com \
--cc=christian.koenig@amd.com \
--cc=cuitao@kylinos.cn \
--cc=dgilbert@interlog.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eperezma@redhat.com \
--cc=harry@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jasowangio@gmail.com \
--cc=jgg@ziepe.ca \
--cc=jmeneghi@redhat.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=loberman@redhat.com \
--cc=mason@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mkp@kernel.org \
--cc=mst@redhat.com \
--cc=phasta@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rostedt@goodmis.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.com \
--cc=vbabka@suse.cz \
--cc=vdonnefort@google.com \
--cc=virtualization@lists.linux.dev \
--cc=vivek.kasireddy@intel.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®