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=1795101193; b=3bzVbZfuaxl2gMzkvwcIX+fg1VHuR20cq/ok9eIRkrSVDr4fi7OyKaHVUPCYR3lGuXA+ vuJO78TBfvm3ien82G1vaklA/XGPnJboyjsF1t7M83P+Xm/XiB6xiYKnvpJcg7feTN5Bi 3sb3e4yLi9mCiMylDM3d9FaOOpvwpu9aWE5/79OE3WXXjFGVIO9s2P2vn5LcC20xhrp2x 4/32d1SDQB+d5pSTEZmXU2GOXAQsZ0lgEfXinOsMiYe1wEAvtUTrIg2tr3Ac2AIf8autM 1ZZgV2dZcuzZFarRB7a3qRkMtxqme7EIdYmvaciXgAsClyml3XMu487DGmXfieY7Q6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795101193; 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=aUaUnGVOD0AnB0qQi2tHlDtmvMhT+a6tdGKKo0EDxDI=; b=oKP2o5G9HZ3a4ENkIsZj4QTjH9ER0dpWMObCqAHR5xjNylntmy9Pfy2gi7ePo5DCc3J7 1wRurIp52/lwOOUV+s0rMZEe5CX1/wHTyVd4HaRQzrDal3N+N6GbbWBEApdC7/bh6akl5 lkE4dGAOV5modpfiFs3XRM9wb87/95ijx9D8ei9LNkMnzE5LgookhAdhBqZY07NgfQhkj 56OsA/Hnu0djf5/D8prsyIS7plNrORAapb62gtsRs3BhDiLfjkN7bPXqTZ0m73MThbY8H WwAVOy70pwlCvicUVqbmQOKGkbEkTm/ERJT6QQRpHhy9HNncsi3plUypRcLG5CAkHrA== 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; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=uIMFT2Q8; 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 8F35E60A2608 for ; Thu, 19 Nov 2026 15:13:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8F35E60A2608 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=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=uIMFT2Q8 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-516-4IvIyJNnPJKjDlPpG9UcOw-1; Thu, 19 Nov 2026 10:13:08 -0500 X-MC-Unique: 4IvIyJNnPJKjDlPpG9UcOw-1 X-Mimecast-MFC-AGG-ID: 4IvIyJNnPJKjDlPpG9UcOw_1795101186 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a4654add56so17349555e9.2 for ; Thu, 19 Nov 2026 07:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1795101186; x=1795705986; 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=aUaUnGVOD0AnB0qQi2tHlDtmvMhT+a6tdGKKo0EDxDI=; b=uIMFT2Q8PmwavS9NEqE0h+UAUF0TVPPrepbqUcVYtImSmrBGEpC/IpWDBJ7mtY6zmZ sbQ1uIr2CnqNvfjn1DlAq6AtwD9dPCNLnMyGzQZgSFvqMbuC2DAP99pBymaYMf/xx20o MWpEpEK77N6KDJ7HYgKlPRvaT5Vh+DrnsqbQGV/jf8N3qI+dtm52bKMcItGA8tnsm9bi 8hCR9ok+WZR2vRkBQvA7jIbMBoCw/f51ruQWTRjG2j+wEHH2yKf7N+i3kTeh7lEevBdM TS5ZR73v3NH8ivc0PEGN3k8BOrxCae2Jol/+r4LzeRpe0hV8im4QOJb7GaN20LQHP8Wc eBgA== 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=DIcHqoWdWfTLArA72jbmtOHTlfbdLzZBqyv+9gTB5+yxIWs5nyYTGRX8lAs+fSafsV vqfYwStiEZiE92IvG1LTm4LZ8FbjSSRuCuaFONAROYWWklDf2wjUnHEH4U4pE209zffi qPKvGonV0oUt24htA4kq4ze9rJ3IaaPW0S2gtV23KC0XhkfM+Vduc7E57wkPGXhVx1Oj 2pXxGTnQKegeT8oZ6dFD2qivlU3960gYjxtgxXE1FfHlPczkuLJKTr2WX9yXyiVObE+6 8f3o7LNubcvwLpQY7uyvCXOwLY9z6y9+YgIqj/l8h+dUDhMIQ5sR7KBIH2bQWVgKdbTe 2l8g== X-Forwarded-Encrypted: i=1; AL+hErHSp08LfveOl5KFxNOV1nZfHCVKwBDacnzDNXYgI6bztxRTNOLsZT2vOeyO2ykJpWpgf+o=@vger.kernel.org X-Gm-Message-State: APuU4Z8eMse6OGnDmKWdHDEB85Xpsg/tlxuVWwiwA1C2PURVmFvsux7V kwUj8EeJ38ilGbRc+gHn3fr1Eg0+AZrSoyi/YQYijW9gmlM024r3c4vEQSkiQrie3Cs5+kE0xO6 FY7oJkqq3TFnMwF8gZFViQn2C2lqcrWcdQDehwwEIGe7h09Yu87aKHw== X-Gm-Gg: AYBFou1sEbTCwiwK1oOKnweIG6+enMAgJt/a4ioyR3oZNzVIS6GweitCSmdgolXpX/5 uOP5zeV7exCAGEUN3N771DYk9fW5dl5qyaDu6eFMQBtfKOa/GGUcPK7LUBpKIA8kGtRGHoAQa79 uhd5bFThSOllkw6zpY3sWi487X1fcRJcL5xSMi6wV26wOeDE8lmD3tGF1MFGe4kFNgSA0d1QRDx sREZvK5ec8tbOdaEUKbNjIbN2dLfr14RrvMBICWsZJUWRzGX+yx+2mhYv0XnMsNAzHMwb0LOR6A 3HLjhx1bmWIK1pQyY34uGNREF9fzH4IT/MZ693qtNpzQstMdY7Efcg3eA898pZH809DNVNyHgIA CsbGrye+MSQyBmRqstgKoqiCElsxnJwuxLzw4C1zVrQ== X-Received: by 2002:a05:600c:3107:b0:4ba:eb:eb9b with SMTP id 5b1f17b1804b1-4bb7da1272cmr124142255e9.8.1795101185837; 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: 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: <20261106131829.3228926-4-cui.tao@linux.dev> 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