πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9179

Re: [PATCH] vhost_task: do the return-to-userspace work between work items

#9179
From: Shakeel Butt
Date: Sat, 31 Oct 2026 18:58
49 lines
10825 bytes
On Sat, Oct 31, 2026 at 02:15:40PM -0400, Michael S. Tsirkin wrote:
> On Sat, Oct 31, 2026 at 11:10:04AM -0700, Shakeel Butt wrote:
> > A vhost task is a user worker: a thread of a user process that runs only
> > kernel code. It never returns to userspace, so it never runs the work
> > that is queued for the way back. resume_user_mode_work() does that work
> > when TIF_NOTIFY_RESUME is set. For a vhost task this means:
> > 
> > - memory.high is handled at the wrong time. When a charge goes over
> >   memory.high, the task counts the pages, and should reclaim, and sleep
> >   if needed, on its way back to userspace. A vhost task only reclaims
> >   when more than a batch of pages has built up and the charge can block.
> >   Then it reclaims and sleeps in the middle of the charge, maybe while
> >   it holds a lock. vhost-scsi, for example, can fault in guest memory
> >   while it holds vq->mutex. If the charges can't block, nothing is done
> >   at all, and the count keeps growing.
> > 
> > - Block cgroup throttling never runs. blkcg_schedule_throttle() asks for
> >   it, but only resume_user_mode_work() acts on it.
> > 
> > - Task work queued with TWA_RESUME, like a deferred fput() or a NUMA
> >   balancing scan, waits until the task gets a signal or exits.
> > 
> > io_uring workers had the same problem, and io_run_task_work() calls
> > resume_user_mode_work() for them. Do the same in vhost_task_fn(): if
> > TIF_NOTIFY_RESUME is set, call resume_user_mode_work() at the top of the
> > loop. That is between work items, no locks are held there, and the task
> > is running. Passing a NULL regs is fine, io_uring and KVM already do it.
> > 
> > This covers every user of vhost_task_create(): the vhost workers and
> > KVM's NX huge page recovery thread.
> > 
> > Tested in a VM with a version of tools/virtio/vhost_net_test that puts
> > each RX buffer on a new page, so the vhost worker faults in, and
> > charges, 256M while its cgroup has memory.high=64M. Before, all 285
> > calls to __mem_cgroup_handle_over_high() came from try_charge_memcg(),
> > inside handle_rx() with vq->mutex held. After, all 589 came from
> > vhost_task_fn(). memory.peak stayed at 64M, and the run took about the
> > same time (0.66s before, 0.67s after). A lockdep kernel showed no
> > warnings.
> > 
> > Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> 
> Is this different from:
> 
> Message-ID: <AS8P251MB00012469E6ECBEA2B7D87BB0C86C2@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM>

Oh wow, it is same but somewhat for different reasons. I am fine that patch, I
will comment on it.
Technical Details
Message-ID: <auY57Gu5NBtLWKoY@linux.dev>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354127-linux-kernel-netdev=dewy.ru
References: <20261031181004.4193627-1-shakeel.butt@linux.dev> <20261031141506-mutt-send-email-mst@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354127-linux-kernel-netdev=dewy.ru
From: shakeel.butt@linux.dev (Shakeel Butt)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] vhost_task: do the return-to-userspace work between work
 items
Date: Sat, 31 Oct 2026 11:58:31 -0700
Organization: Usenet Network
Message-ID: <auY57Gu5NBtLWKoY@linux.dev>
References: <20261031181004.4193627-1-shakeel.butt@linux.dev>
 <20261031141506-mutt-send-email-mst@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="2529533"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:udDgHw478s7tfF0uJxh1So5552s= sha256:rskzdOIdhNT9fo69PX1TJGNQFxWuP2rCC1oWDxG1sW8=
	sha1:doHmPCn7sqAm/B9vxr7VShIznVY= sha256:1VnIbhtMNDVi8/Suu8EbK3PNE61VfFz8CjBCchLzt8w=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8B77E125CB9; Sat, 31 Oct 2026 21:59:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id kbVn10l2jffs;
	Sat, 31 Oct 2026 21:59:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-354127-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id A4B73125CB5; Sat, 31 Oct 2026 21:58:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id D3CA2222A2; Sat, 31 Oct 2026 18:58:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793473123;
	b=Ql77y9Vj6miwDSoo13Sm/hdX4ZpEjBlTXIHQut8jNPuO8gamhQY7qyJ3ZNqGCMjURT2g
	 8EbnBvJzwtL9WsgU444C2kKUHqodUy6g7LQyXOPvAVBYYM//Z4c7F+WX89HFlMmLcamNm
	 Q04VeSNhN8W4YeK6SRPo6LNbzTEL7umt/gvXHxkG587M/WSXPryv0DiqoGobmsaXdLaDp
	 BVDOvMXOwbpQ2lXuSIrA1oOJ1gsdJCoEHJHAMEb06Cj/lVx8ezMD+321yIQAe/+VehfHf
	 Tm5bEPxAc39kZjLB1hURblVDdzG2uDmIBlCbs+7xSywlQVeVRthdqEv/6uLLuPu85YQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793473123;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=WTXPO9m21ChhSJhJsMR1jm9N3k/S9PtVs0GDOD3AsIY=;
	b=ySPDnMBPt4Bu19VK+xNlKuKa/JniOU9yS+GBff+RV1SaPpI/GChaKZ9oFhNU1v4AYVZQ
	 TojqjRzKfQEVdlWmrSOHeFt4MpJ7pTe1Lo/AtPHOZF+zeW99WVqBp2QBztaw5+X2F1JKA
	 xTTZGFKTLJ0t7RibYJayLPvxm2Fixbyd1JfIDQuPa8vKzBiwEc/RTZnrMtnrayu9TF45p
	 ok1dd9/PpC8b23AgACiVstbdlMtYjOeA7X9HJcL8gYWaMWZxSjnEYxgF4pxPRfk1OOK24
	 gZFJYMIqLuUo5/2ojpIVJkXk9TG491zkpC6X9IzY4UevBtbb7VgH+FFwfhY4YXethjw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FgLPquBt;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4741C606A327;
	Sat, 31 Oct 2026 18:58:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FgLPquBt
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.123
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793473121;
	b=KX6Yd65/xdxPXgRdS9qboYuaHCv5w41/Ay5hrAAis+g+tnH7GT9PokRsbR8a52QI11KH
	 FqFaJIa1e6vlcaQxm3e2aCktGsxq4/6ap+kvgiAdIwqGt98hCrxuyqO9ySt9FnSu4lRPi
	 cg/HriXyVzuKZ5dreCS4OLflwCyOjC/NlvMIfb/TWb04etxzWX9inR0kKSonw1rA2MH1e
	 nmvG6W9Hpib5H4PLD4/jVAo3cbEBywPYy15p3kFLJ3ftVrJvhTbCQBOLTc5v7rPZsCUep
	 YXJKf3dMyeeg/lJOxW2Q9zJXaWIwXgM2Anz4IsSTM8nyvlZwBDr87HapMy2H3FD/IFg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793473121;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=WTXPO9m21ChhSJhJsMR1jm9N3k/S9PtVs0GDOD3AsIY=;
	b=PIVa0jQDfGqLy6bJHMm38cuA5qxI9+sUr1yVADAg1TFM+Bxi0OxvFQB/qzGulR9ttfoI
	 16jbqj6wRvP40nm9XuZA8NEFPk97bIm+U2XQCMNYUWfAJkkDHYYFpKvmmwirltVlJA6DJ
	 gdB+eLexnRjWe8eY8CZyXwqeX+Voamd8BbJfA3ElNRanyGx/P6GMb6XI/THGeeinHYWXL
	 6t/3zSfIMHh6AC27TkJrcBZEIRhgjlVg07kWPY7r1YMdUsGUIMPHWjEPJYzDS14IQtq5s
	 I79Yq5u/xBeIdA+JNi7FyskDQH7/N3CkXDBhEgEZvCLLel8C2QCGD65sEU8VvvhGJtQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=none smtp.remote-ip=95.215.58.123
X-Received: from mta1.migadu.com (out-123.mta1.migadu.com [95.215.58.123])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53AFB606A31F
	for <netdev@vger.kernel.org>; Sat, 31 Oct 2026 18:58:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 53AFB606A31F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=nhn60L6iDcU1tEzuh3dkIqEoHLNq1R18VibAiPoFZc4=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1793473113; v=1; x=1794077913;
 b=FgLPquBtbge3POVC+2Dr8m+4QENK0dVztMZkqUikUBrZvJtE6H91VKKswJxIsBJL67pY6Jz9
 6g8qzsLTfA9LttvrY33jPtsEM+SjPu1YN01qWSJr0tzgcny6phbIpfbk016/wYEPf6rRAq9FOJQ
 UmOda5mSHbWZxP2yJv5ZIimA=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id d88e81d4557f9af7;
	Sat, 31 Oct 2026 18:58:33 +0000
X-Mizu-Trace-ID: d88e81d4557f9af7
X-Migadu-Flow: FLOW_OUT
X-Cc: Jason Wang <jasowangio@gmail.com>, 
	Eugenio PΓ©rez <eperezma@redhat.com>, Meta kernel team <kernel-team@meta.com>, cgroups@vger.kernel.org, 
	linux-mmc@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, 
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261031141506-mutt-send-email-mst@kernel.org>