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=1796122578; b=kkHFf3wdw74Uf6wwPYJWp/v6MfQoEjQEhqLtvASbtv4J2cPq2+gU5MV3R2XDZ4AYWjRd AxBk5EItiKtFbYuO/qPUnib41VLvogizU0yPFPXLfFxHD3tXkaRDWdwNdDXvK0JUs7Bfv cNrTPeiH2SkdnuVPe9xk+oLKbdqXh/sw7wjPIFs7xabOgbsVUQQjGjrTyMtHWjbguZ7I9 +sXl7i+vjQUpgA4MfaxLc9ncOEm8s0cS+8Pl1T/ycYKoJjaWD5V7PRv9q3zgUx5Ci7tSs l8nC0Ymr4b/pVbYnTvill3qE7mE/bQaAS1YKxF4309NVM16NzKdAKxMJwdm/uGNiY+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796122578; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature: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:Content-Type:Content-Disposition:In-Reply-To; bh=H126plEZ+WVpkORqJdgLwK1E0LMbBg2gJqshDmKlmVI=; b=W93z79Haqe2FY6r2zLQZVe98tHDfBG8DKgBT9RTEgm4sJSigIjKM3fc9meIGUixcGNSt T0nRARxMDV8kVfbv4i72X+H+jgz6PPanuPyWn2I9cYW0x4xQYXRUe37WbbbvWMTchotKe a8T9SayfYTs67NhGa4+XcqUHQ5tEGeZDzR9ViJwlTiOvzeah3aUiaTthpwGcHP0h3ihk0 SECSAhpStuApY/kdH/x5PFybS2J6HvXODRsh+Ww3APoC+COrlrskqtOAyCDlTqTLlSyPt V0aD/1dZWXpbUlhdYNYvSv5HAZMKBlca6sUTNjX+mZBd6G+t+n6xmzuaL8TSvAbIO2w== 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="Ma3/O+9R"; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b="pio/6yG0"; 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 5BD19606A32E for ; Tue, 1 Dec 2026 10:56:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5BD19606A32E 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=Ma3/O+9R; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=pio/6yG0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796122576; 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=H126plEZ+WVpkORqJdgLwK1E0LMbBg2gJqshDmKlmVI=; b=Ma3/O+9Rmfz4WFLJIdQjmy0lJ+j8XY6GnTzIULrF1PRGZO9ylMK6ZW9tcpBZU3zw8rD5GC c4YQeyVXxn8Bk9LD80cc8WKAwLMtuWcC6m8pqzWcR5MkH6upZi0RcRNDiQMj+UT936YPEC D6AdkBXLsbd5BO5QQtpjruS+YFUPdUg= 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-681-beiEjOH-OVW0QBHAedcy9w-1; Tue, 1 Dec 2026 10:56:14 +0000 X-MC-Unique: beiEjOH-OVW0QBHAedcy9w-1 X-Mimecast-MFC-AGG-ID: beiEjOH-OVW0QBHAedcy9w_1796122573 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4bba856092dso41696875e9.1 for ; Tue, 01 Dec 2026 02:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796122573; x=1796727373; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=H126plEZ+WVpkORqJdgLwK1E0LMbBg2gJqshDmKlmVI=; b=pio/6yG08KqXoMNkjfaxlNp9CJk1XLA7+XkUB+A48pRjJMEckjbSRFeQFulM8lS6zT hN8x1GbqlupvQiDh41QwegseTwNixTLJ8697WVqFmLxRgK8bFXh07tg8tHLU18KEij5z S723RFpCIW4G05Z+yAOgJsF5Yc6754GFRl+ixW3Y+5BhHjt9zMKDlgSqhdVTO+/B4zxe VFmmcTxJULbpMM2tNgmHwA48yTjp+89UYzG5OgofHK89hOr0kQnl3oaFl5r6o3vS3zZE Xq5fV/uNaNcCrdxYUiPZJUkliRj7s7w1CJANN3PbT5WD+IX65Vay79y06yC9XPhA5pGd sc7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796122573; x=1796727373; 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=H126plEZ+WVpkORqJdgLwK1E0LMbBg2gJqshDmKlmVI=; b=gHCdbGJGz0FEXSPPua2yMb8WysUx8b3w+B+5rGjRkm8YQwFeuwzqOTCFhcXQsxvGeG xKvwaWUZJJ0PflTECj+UDKMx1CP4Zqw0Qnsl0fNuBbwk1uSgbeTsR9zGJnQs7Gae6FCc G1J2LnAzzF1uomD0ILcX5WkO1aF+7RqBI9/F5lL0zw+3ps/uGHh6j/LViImAe4e0X9HN jH+aqCChkkTWbEEWFpmHdp8qad2duIwyIt+E6L8GJYh4aeqgqPLcBR6rbDtJ+cm81ksr A1Qgaew2apkhOE2E4x2O3z1TChs4X9QYNmgrhGQZIA6exRAAQtWgdhLXpqDsZW5RA+r9 1pCQ== X-Forwarded-Encrypted: i=1; AL+hErEnRDvjCDh7EbTfiLrRYzJOH5O+CkqAMKrJDbSsMQaYjB3xyvQSIZtcMCZkq2pXltNHskc=@vger.kernel.org X-Gm-Message-State: APuU4Z/KlNMR+5K8DJWAVh//BrDtfj75RCmagwVAdOd+Jz0GS3RjhOYB 8k8pZr1/5EhqGZppn7g4AnX/iPhqq0aXNJ+iGqNTkzUjwJi7hFA/+60ii7mS6crU+b8q6zxvnm2 r6Qjf1maHrY+mzaGEbA9kcsZjrvism7t6omTRP8FWjlqOzmzrCgo9e7Hij3xBgw== X-Gm-Gg: AZFdTZewIO2vDxzYn1VYsFqyEM8pb6LQ5D+djBw4L5HrqrBMSA7NRaKEPQ7j0Di/mMd jbIekjZPUnJaqQbys88xzjDC0swbkUFsBzc/RT3QIOho3POOvlP2BN7Qxc9ArIy0lF+Mrv3Bjgb TBNiz/UI2hEAri+lXLyE44POkAb/BvHxtABXeJFsNM4EINwPOdEQlv/9BZVHRKgncgOBpHg2MPb nltnVTdKN2Rle6hOP0OkbZPPfevJj2ps1gvJg4FjwGBhph7u4vXVZmcX2f+70MvACxp5fFWb4iB t4zM/RkiHR+fvURiXb81lWQRttgiN3kulGxnXEMXX5AP1pddBWzNqRspM+aEVx+xTmxqqybNT+i 9o+sPn5rGntsWIqnPjyiDAfPmT0JPpQCb7huTWyq2BxELbUn26oK7KPGn5zzX1dP+3JRwpdJ/gF FGCL+LpWGsSKpjkg== X-Received: by 2002:a05:600c:1d8c:b0:4bb:5345:606b with SMTP id 5b1f17b1804b1-4bb8882358dmr725149515e9.31.1796122573384; Tue, 01 Dec 2026 02:56:13 -0800 (PST) X-Received: by 2002:a05:600c:1d8c:b0:4bb:5345:606b with SMTP id 5b1f17b1804b1-4bb8882358dmr725149235e9.31.1796122572901; Tue, 01 Dec 2026 02:56:12 -0800 (PST) Received: from sgarzare-redhat (ip190-139-192-82.pool-bba.aruba.it. [82.192.139.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bba6a0d65fsm525495585e9.3.2026.12.01.02.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 02:56:11 -0800 (PST) Date: Tue, 1 Dec 2026 11:56:05 +0100 From: Stefano Garzarella To: Tao Cui Cc: "Michael S. Tsirkin" , Jason Wang , Eugenio =?utf-8?B?UMOpcmV6?= , Stefan Hajnoczi , Bobby Eshleman , Andrey Drobyshev , virtualization@lists.linux.dev, kvm@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, cuitao@kylinos.cn Subject: Re: [PATCH v2] vhost: account the per-device kernel allocations to memcg Message-ID: References: <20261120054517.526275-1-cui.tao@linux.dev> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261120054517.526275-1-cui.tao@linux.dev> On Fri, Nov 20, 2026 at 01:45:17PM +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 Why not including also vhost-scsi and vhost-vdpa in this patch/series? Thanks, Stefano > 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. > > Acked-by: Michael S. Tsirkin > Signed-off-by: Tao Cui > --- > Changes in v2: > - rebased on next-20261118, where the vq->nheads allocation now uses > kmalloc_objs(); the flag addition follows the new form. No > functional change. Carries Michael's Acked-by from v1. > Link to v1: https://lore.kernel.org/r/20261106131829.3228926-4-cui.tao@linux.dev > > drivers/vhost/net.c | 14 ++++++++------ > drivers/vhost/vhost.c | 17 +++++++++++------ > drivers/vhost/vsock.c | 5 +++-- > 3 files changed, 22 insertions(+), 14 deletions(-) > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > index 435d8ed3851f..390858056d20 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; > } > @@ -1340,17 +1341,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); > @@ -1358,7 +1360,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 dc973287567c..e8f9dce52aa7 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -526,10 +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->nheads = kmalloc_objs(*vq->nheads, 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_objs(*vq->nheads, dev->iov_limit, > + GFP_KERNEL_ACCOUNT); > if (!vq->indirect || !vq->log || !vq->heads || !vq->nheads) > goto err_nomem; > } > @@ -2052,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; > > @@ -3407,7 +3412,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 88a310390eb0..2fa205967f8a 100644 > --- a/drivers/vhost/vsock.c > +++ b/drivers/vhost/vsock.c > @@ -719,11 +719,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.53.0 >