From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796122578; b=PuTBfbs/z/oUlPyaSkDzgKndw55qdYyFynJ3/ji5Pwnn8ayXk4WZ9I0pvPALt+UKy/gd 5S3D8AxQJGAMlz62P4dRoChtsRS3VNvuM5rI4OnyaW9HJJ4R67SaKbK2C/LUO3Yw6HORv ETJ4SlGc5LN3bedSq7R7BLv1pibfLxN6hWwZxXYa/s5NoTLRo8IZ5nZ4vNh2a6gEUBQhv JO9J+LmpzjbE+4wrzW4D1z7jTEJnG7lLVKhIEJ9QEYJCVc0AlZbz0+mbmgJnFRiW/ALJw pLyKWl/XzaO0rfdBSeUK2L9bJseGaIKRhGRhvOB8+dCNn5diamwQDITl0XlRAjLYbXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796122578; h=DMARC-Filter:DKIM-Signature:X-MC-Rep: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=H126plEZ+WVpkORqJdgLwK1E0LMbBg2gJqshDmKlmVI=; b=fsvq+Vo3hQpW6NLG3jGXpWTaP73nRfCWrWTnkbG+v/sF+UC//54OJ4lsJD2X+HHuPlyp 18RPpmpnVw08TmeYWXws6/AUBmMzcS3yFMs6eeEu9LPYD/QMfoYFKmszvt1j3PeiGMS+E drI9tFifjbsWkDgn29GDe88M/h/zh7g5zhoWevbzrAQlsidsDcBzAq8ylcAUhEX8UhGfL qrgQETlYATTbzGWLD0RUAy656cH74RyyjFqR9ILMYqexG+MfAWBNapfaw4gefjwCrd98q M+6EDFxJ5vW64lCPHpDkXDU4xQ7CaEsVxW2sghYcqYfR/FiT4s3ExV+4WNbiSTLQuPw== 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"; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 AE6FB606A329 for ; Tue, 1 Dec 2026 10:56:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE6FB606A329 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-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= X-MC-Rep: binary re single 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-118-Axxiw7bEOHG2R2anawOS0A-1; Tue, 1 Dec 2026 10:56:14 +0000 X-MC-Unique: Axxiw7bEOHG2R2anawOS0A-1 X-Mimecast-MFC-AGG-ID: Axxiw7bEOHG2R2anawOS0A_1796122574 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4bb818d8dcfso57411845e9.3 for ; Tue, 01 Dec 2026 02:56:14 -0800 (PST) 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=e/W1DxamW7pmsXxptX4EXTB5Wn7koKGBEaczdeA4DfJCQ/NTazeDCW+LaMzvCfupj3 o96i1gvboLUFU3W7JfvWSeR/rK5pexXEsO4+gyW68uoKwTE3PoIrvtVL5ivdqimHdlL4 vqmP0s9U5SzczgN1rRs2uUvlYDMcn1lvkNojZEFkh9LgLAkLwY+lPP6bJGUWovAIzZ6K 3/2l13WU70ASa5JCgvP3rgrMYUGkUxeiuocKMJP7WJ0HYxqLRNxM32b9DuLybHc0AKuW m2WfS4lrJ6AZsAajH6mx3HJ91wq90NT3rrsp9o9utz1h5oAVNKPFiNKLDiZp/ee5ij2h 3yHQ== X-Forwarded-Encrypted: i=1; AL+hErFyXnSiHeQn8fFADvlCowduG8+8vmDj0uRDf6h5XNNoYbRkfG6XwZFKWUy4rgkRL09tGeXxYo+OGHsJCj6kTg==@lists.linux.dev X-Gm-Message-State: APuU4Z9f/BpoDq9i+kZ+qWerx0BKxvqtSHnAw4NSwJVBoZm8DwtLX7HH 3VUKJg4RnKAxfoQPjoa8mAB4yLtXoyrzkznZntu1c9WhNMQWfAarQ3nDLNZBEaaKKuOget8AxqF UMJIPlOwQ1r8N69P1AhMiwhckGkHRPy64Ac7RXv/HSKDp5dPC9jaF5+Dqp/K9E1zbwSq5 X-Gm-Gg: AZFdTZfW0hHmWXSPJLCORun/UcM/wLLdnbrbmZ8muK3m7qdCJW6/R9pO9hC9FSOWRX1 hSOo8y+AdMIOGDms7AcP9FrFkqug+rxPZScB0F0swfxFXz5neHOW9YlPqGtB/pckLeZLuLWDrYv hREqu9jJA/1rZnNhqYVmp0q12WtICWkIIV+7FRR/U+8OicmKJtyx+pM+nPwbYR7Eeblmdl+SGD6 jslx094bMW9rGekrBAVjgumHxFwj5+rjrDkpxKx6cycWJFUOXRrzs1s1ilVpwVn/l9dmA1xg1Vj JcnLDKCqE53VQAFuKrU9JvvR/ruIOZMAki3sXk7cg6h19hlyJV2gR4Mjtx0CXaqRrEvFM2IIEOP l+JbLZFXl4E7+TvH5OW23ygNAbs8PaXRshQ3STGloh8Ec2GdOPhzpmo5mpHl+jJhzpCJeeltts6 URc/r/J6SN+GkZyg== X-Received: by 2002:a05:600c:1d8c:b0:4bb:5345:606b with SMTP id 5b1f17b1804b1-4bb8882358dmr725149585e9.31.1796122573404; 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: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: <20261120054517.526275-1-cui.tao@linux.dev> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yMu9IL9_gLdCsdPxnplyeN49Np3d3buC7ywx8oDQRzw_1796122574 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 >