From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8E92606A320 for ; Thu, 19 Nov 2026 15:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b7pFSSAx Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D0ACC10E8AC; Thu, 19 Nov 2026 15:13:17 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id E515610E8AC for ; Thu, 19 Nov 2026 15:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795101191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aUaUnGVOD0AnB0qQi2tHlDtmvMhT+a6tdGKKo0EDxDI=; b=b7pFSSAxI+E9EaZtsEfbolehGk2Tu+XE3olI4Vs/ypKruP6HT5txdO/AAW6Kw6DOBoGuQD KjM+SJ9zqBvEX0Tf2YD1b2Ppz8GrMZzCjINvDF5x6gQW6ncfqjiD7zXGFlsYZrAVw3vo4j GJuplVbUUZPlYyzsJRv6NkbPDFHGjvI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-g8CXRMNVN3mYO7YTR1O6mQ-1; Thu, 19 Nov 2026 10:13:08 -0500 X-MC-Unique: g8CXRMNVN3mYO7YTR1O6mQ-1 X-Mimecast-MFC-AGG-ID: g8CXRMNVN3mYO7YTR1O6mQ_1795101186 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a35db2d6b3so17129585e9.3 for ; Thu, 19 Nov 2026 07:13:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795101186; x=1795705986; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=aUaUnGVOD0AnB0qQi2tHlDtmvMhT+a6tdGKKo0EDxDI=; b=s6qYSk4d0MxZezKreLlUiQikVoc1zIm6bXQFQiHW6K5sSI6q2UbHFirLrdt2/NzqzK CJYU/yUXYTUKqlLCh8UU5gmTJnJx2io101Tg0yQ5EO2odA6D1l5bshP3vDDOnyVqQNfi ox2rpZ3dXAxggRNBbqIL3JnuXlD03PMbybqWJ1b6tkIDX24ON1deBds4YS/dRmC1JMbS F7FyBfQd2iUkn0S2M1EVhgXfrB9ZLR3FsqXmdBrDj3VCpUYfCX+1dHj0L0IAGmBMu8ZR cFB2qlD3OgvRj7Q1buzafwW1zp8wH2LfRffN0UcuJ1i3U2RcDKq8FitMt7BlCb2mc1Lq fBEg== X-Forwarded-Encrypted: i=1; AL+hErEp3AnZYkNyq3VpLvrK+x/gGM/8UNB0J9tmL4jMDwjlE4IFue0XrtsK5iB/LXySV9hojMirzWbvuKc=@lists.freedesktop.org X-Gm-Message-State: APuU4Z/q+eDv+WNDMkh54Z+K9xT9pDJulyXnWNtITC6Rpo36pt07T9lL lDMzMM/5cSLFH3NYUTIK30+ix9OiSqOrDV0n84wAQ51UH8r3ryJ/nNvSI4jOdSGufe5HPl4vrkD yoapQdXX3IQ2hqIq5fEKD+71TVnZT7R315xg/bruCFs91KUsYXrNEDC+mHJ3wwVXliZVuZw== X-Gm-Gg: AYBFou2KiUKl5FmzYbIJMO0zL7my6DisNZKDyXWxUtG0V1YZkj7xNsPli34h4s5ucCl W+zPNSBVM7B/n4Ye5GD+8ejA4lmrbwHd4xeieax9PErpiMlNED717/bXeIu3doydsXe49cWkvft DQIVNUuo6uSnfCnm0mXxwa7gfWwuEvJNUhTKyMYElI6qFEb8UfjbTG+vZYkl3+oSGPybxgOn2Ek OvScNYJhpgaVRkmOk4viEK10rAztaskJbXXt4PDI3RpJIgs8tNQhuPUbrNL3oUM5kaTP0SA2g5G GKtUErbP4CA96lKkj/Uk/vFi1xkaEzxS3OB7vNhRrQNOIRAtNwg+7cWBL2TpIeIduPf/gpROAON 0kSjBMobcixmbyLXM/wMjgHLsTr0pXEK895y4K7UwpQ== X-Received: by 2002:a05:600c:3107:b0:4ba:eb:eb9b with SMTP id 5b1f17b1804b1-4bb7da1272cmr124141945e9.8.1795101185770; Thu, 19 Nov 2026 07:13:05 -0800 (PST) X-Received: by 2002:a05:600c:3107:b0:4ba:eb:eb9b with SMTP id 5b1f17b1804b1-4bb7da1272cmr124141275e9.8.1795101185168; Thu, 19 Nov 2026 07:13:05 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:1522:6500:ac93:c62:f076:48c6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884a3a3dsm3221365e9.10.2026.11.19.07.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 07:13:04 -0800 (PST) Date: Thu, 19 Nov 2026 10:12:58 -0500 From: "Michael S. Tsirkin" To: Tao Cui Cc: 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 Message-ID: <20261119101239-mutt-send-email-mst@kernel.org> References: <20261106131829.3228926-1-cui.tao@linux.dev> <20261106131829.3228926-4-cui.tao@linux.dev> X-Archived-By: MIME-Version: 1.0 In-Reply-To: <20261106131829.3228926-4-cui.tao@linux.dev> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RVNzvQW6xTrvLRr5cuqKzdkMaldno2yHpTax_OjjtEI_1795101186 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, Nov 06, 2026 at 09:18:25PM +0800, Tao Cui wrote: > From: Tao Cui > > 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 Acked-by: Michael S. Tsirkin should each patch be merged individually? > --- > 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