From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795101192; b=WeKz/QKzjHPqTg4bb5w8VDFava5z8MMhVp2U4E6FBC3RTCvenqJaStCG5cWBUeZ2Pyuc ovo6HWC4u+09fM3qh2K+n2ylDltXkblnuNSSE7co1mPbeL1Kae2GRHFtuhr3LoIVuDBU1 bikfce0FB9pc2gjZbqhAC1BVsjFIKWp85/xAu8WfYnyy18zH3ICSxm9+eGZJIymyZAAh9 4rTgLHLrdzFn3ySUVVycQJaLEC4Sfz23keoCGRqQotQ/nCnUXxZAx8JKKPS0+cT4KOogC G1z8TOziP/M1RToczAmdubHkhFbX2tnX8AzEKj8YjgtqLYskNo3P18wo4zl9CY+JxUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795101192; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:In-Reply-To:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition; bh=aUaUnGVOD0AnB0qQi2tHlDtmvMhT+a6tdGKKo0EDxDI=; b=bkfSvdLCKPQm0AVtEk79K1FSqaGnAoapLUa3tuB6FPdJmYBFk1ZZPBlZiBUAbN8fyVAd nQKyMqPakWMsU0s8jJHkqAUdfTqWnjDaH4tj91xAnJ7oafG/HrMIA9IsiN3tv4aJBPdxs gnfB+6o1nqxpv+a78yAbU7rPO3eZ4uvRRc0cnApANWFL/L0PnOKJc3MjOjMc5sjJ9ihgs NwxTBeUFuZ+U+4c4XePZV7czSs7ch6LVF/80XF/l5dXCs0xvlYRY+J/85iR/7fEiTre4s PrTUG5QCK3wLfPY/dMnB8tyrDt2XUYezcKsNr3zDf45jG7DT5eC2ANo11MucqD0FZEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b7pFSSAx; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 D10F0606A333 for ; Thu, 19 Nov 2026 15:13:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D10F0606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com 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 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-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-E_A4ciWbNp2A1hHzcD5cMQ-1; Thu, 19 Nov 2026 10:13:08 -0500 X-MC-Unique: E_A4ciWbNp2A1hHzcD5cMQ-1 X-Mimecast-MFC-AGG-ID: E_A4ciWbNp2A1hHzcD5cMQ_1795101186 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a35db2d6b3so17129535e9.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=ZaXfEYFiBYujxX/tPSbvtm6CHeiB81pzDWfV4N912VF37sLBwqaRgOCRfouU3Gm1Fg 4ahlzrAVSArB0tzQj/LFxF35IHCs6tqHTeT6ckIOe1qbh81C6yM7/rAXiiKJpyX+3puL FgDDPHk7eDc5e7KGFjUn8MBJ9TTnyPutOwRrfXk/RhmakwqMMh9PQW0YufzYez+U4GmO cYUYory+wcGJNchr27hJ56jMs0FSO2E/K7jgBoGomxDe2R9e05y4eMhJatGgikCy+bmh C1cbb7u3vaxwbX9N3Qwt4moeML5cJd1GsbcnpNZIyCdZHoCJ8RfqFcn3cwKMmKlNQaPo e8rA== X-Forwarded-Encrypted: i=1; AL+hErFwIKoc5qhrOHeLOKpFKMT6JTYdfeF351sBTAi5jxCZmDo4obfOWCCldCnTNjYFtqLbt5xBJ6AY9TgJYncY9kDjFQk=@vger.kernel.org X-Gm-Message-State: APuU4Z9vH4+RRhLV4bC9s80eYnA1gk3anqiwk1qNSXpuUNVZjvjKBzFz 7ulHQNv8uCEAkkyvf22xZTI8pvwR9cZ0gE+6jqCOz3/UW9xkMWYJeOsjsYOvsHvSvuni/LHTi4H pXP5/+Vh/AWlDbRoXHg7sSInhNay66AOMGMdk0q5dSgEkKKT9aN62lEwZzAqpvmKDaO2CGZl+5w == X-Gm-Gg: AYBFou2JRQfEbSjyvzvwytexXSy1dhl4JJlKen1I6rAYMU7rJ0gp8mg0ZxblCKjKEQQ dvj03Zmvejp3O8vlUcu12WfF7aO2zwh+fK2YI6Syf4AQcx1kIFHOcbOhYrFG83RxyriXucpKeR3 0oNP/NckXzL5UtuCpHi2RwKVpQBq6qc/19Kbw88dSNPgsWITkpWH9WIcVViSqITwNvSuugH6mYU GDLq7jcEw8hG/X+X9Sz2ImBtJEcOR8qc2KD8Aco64Tz4RZSnsSuTmogcrcpLA0fiAoKHLbngtZH UbBb3Raa/VhfL7iBg8E40LcxSgD/v3hEsXBNSynq5cM/e2EtHO9DSBOjrNQctkeo7MHsCxMCW5k WCmUe3nFVBCiFYRLHqJOGLLSNuwXfjy5ffSbFWsWgpA== X-Received: by 2002:a05:600c:3107:b0:4ba:eb:eb9b with SMTP id 5b1f17b1804b1-4bb7da1272cmr124142055e9.8.1795101185792; 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-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: <20261106131829.3228926-4-cui.tao@linux.dev> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: N5osKCv1RhTyuq3jOiDBvP0JY7odsoL9Xmdv8rmO8JA_1795101186 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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