From nobody Tue Oct 7 18:21:13 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 433B2262FEB for ; Mon, 7 Jul 2025 18:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751913976; cv=none; b=C6v7tm/uyeQaXaGHGrPMHFavBkkk09udHTPq9dsyHw/R/fTcwMrm0yn/HWxOtoTBXjxaPW2xaQGs06b+HvPjREPFtZpLZ+F3vghRCoNIOQ4UmjNWtEIPZXKywLn/NpxAhnB6Zg979tNwgBZYTKsjgY4cG16yoqP3qOt9dVXtoAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751913976; c=relaxed/simple; bh=pN4FU4Ls/jrjh17+kg2Kx51Dh9JaiG7rlzwNilpX9Ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ofI5nWaU9tZHVTnrwZeYqgzG47dRJdRtAjkUX4kFg5H48s/u14dQyKB+um2HGuIQREB+E8neYTzCN/0rC5SEjLrbRHgOBqWA+AdyeLqZwzEPkWXGqgltIKe3+Q8n+ATkhCWnlQjrgow2JO5GwASjxLnQqgSVA1WDTEc2WmwocZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BdRWAljq; arc=none smtp.client-ip=170.10.129.124 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.b="BdRWAljq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751913972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7UaVXYkQoQ+lBXJKl8sj6Psnk2uGxXUYzji8T+Xouis=; b=BdRWAljqHjdqNqmirtrlpmLmT94PjLMoIU8HhE2ioiwYXhlEjd5fLVxaKHOgHS5iOPS0AO tcui6MqpeN75U1qqphfpt4Xjz1FZvZ6DF0F93zv6n6UFXjGpdNE1NLBNkhge42ofGHZbrv je5HgxQcy/stoKGK8lfxon3Hj6Mqp/Y= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-xcgKBE3dM9aXaWbE0eB13w-1; Mon, 07 Jul 2025 14:46:09 -0400 X-MC-Unique: xcgKBE3dM9aXaWbE0eB13w-1 X-Mimecast-MFC-AGG-ID: xcgKBE3dM9aXaWbE0eB13w_1751913968 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EF9CB18011FE; Mon, 7 Jul 2025 18:46:07 +0000 (UTC) Received: from bcodding.csb.redhat.com (unknown [10.22.74.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A08C819560AB; Mon, 7 Jul 2025 18:46:06 +0000 (UTC) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Tejun Heo , Lai Jiangshan Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, djeffery@redhat.com, loberman@redhat.com Subject: [PATCH 1/2] workqueue: Add a helper to identify current workqueue Date: Mon, 7 Jul 2025 14:46:03 -0400 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Introduce a new helper current_workqueue() which returns the current task's workqueue pointer or NULL if not a workqueue worker. This will allow the NFS client to recognize the case where writeback occurs within the nfsiod workqueue or is being submitted directly. NFS would like to change the GFP_ flags for memory allocation to avoid stalls or cycles in memory pools based on which context writeback is occurring. In a following patch, this helper detects the case rather than checking the PF_WQ_WORKER flag which can be passed along from another workqueue worker. Signed-off-by: Benjamin Coddington Reviewed-by: Jeff Layton --- include/linux/workqueue.h | 1 + kernel/workqueue.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 6e30f275da77..29e1096e6dfa 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -623,6 +623,7 @@ extern void workqueue_set_max_active(struct workqueue_s= truct *wq, extern void workqueue_set_min_active(struct workqueue_struct *wq, int min_active); extern struct work_struct *current_work(void); +extern struct workqueue_struct *current_workqueue(void); extern bool current_is_workqueue_rescuer(void); extern bool workqueue_congested(int cpu, struct workqueue_struct *wq); extern unsigned int work_busy(struct work_struct *work); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 9f9148075828..a96eb209d5e0 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -6009,6 +6009,24 @@ struct work_struct *current_work(void) } EXPORT_SYMBOL(current_work); =20 +/** + * current_workqueue - retrieve %current task's work queue + * + * Determine if %current task is a workqueue worker and what workqueue it's + * working on. Useful to find out the context that the %current task is + * running in. + * + * Return: workqueue_struct if %current task is a workqueue worker, %NULL + * otherwise. + */ +struct workqueue_struct *current_workqueue(void) +{ + struct worker *worker =3D current_wq_worker(); + + return worker ? worker->current_pwq->wq : NULL; +} +EXPORT_SYMBOL(current_workqueue); + /** * current_is_workqueue_rescuer - is %current workqueue rescuer? * --=20 2.47.0 From nobody Tue Oct 7 18:21:13 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B07FD265632 for ; Mon, 7 Jul 2025 18:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751913977; cv=none; b=gcaTmD5tG6EHlBxyu+GHvELau/bueEsq98Oov8NvSdmn4pLRf1KGB+n9rJJyKTy0/kXmLqJMLGc9P5+Rr36kzIP457G+wPGZ9zVEbCMrGhedmapaJXAx44ryrvCquc6X21Uz957H8p4Eo8mK7M+EuPh8f/CQDgH8IsOnocDUyS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751913977; c=relaxed/simple; bh=83Ba0mK1VEiznArAENk9nArtQQK30RYW79zt7Z+AzM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sfiCJKBFtXSYS4Kx1FKHZGiFQuKVktJ9nyTrDCGETTcQjrwEhFxRm4DKt/M3jr8Q/Ye9Hk1LHKYBed3WCyEI5QDapEwPgfW041TPIswy1nUHJr9/aI9NuDiOkdvo5WayGsP/HavPlxBMjwnNpORg1n1kDRjCdUdGVrUyOx0V0Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OxemsZ/s; arc=none smtp.client-ip=170.10.133.124 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.b="OxemsZ/s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751913974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s6jUDIY0+wkpp5w9gqMEkqBb/sfMBkyBmQ7+Gp3OVZQ=; b=OxemsZ/smHKdRiX+EujtX93Lx7EUD1PlZDyHTu/b2b9pL2tl3dpfOoim9G06vQ3zzB+9C7 IFhEJSz4JaQIhga2pmFzeBGHvnlokwK+40M1awTI/QQA2vFq8h6qBjGIFWDkjnzM6kJlUU rsPNR9ke4aoxtBpXkLRV9K9liUZwVsY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-0crdWXRUMv6UFj4ZrVrLGw-1; Mon, 07 Jul 2025 14:46:10 -0400 X-MC-Unique: 0crdWXRUMv6UFj4ZrVrLGw-1 X-Mimecast-MFC-AGG-ID: 0crdWXRUMv6UFj4ZrVrLGw_1751913969 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7A17818089B4; Mon, 7 Jul 2025 18:46:09 +0000 (UTC) Received: from bcodding.csb.redhat.com (unknown [10.22.74.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3326C1956095; Mon, 7 Jul 2025 18:46:08 +0000 (UTC) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Tejun Heo , Lai Jiangshan Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, djeffery@redhat.com, loberman@redhat.com Subject: [PATCH 2/2] NFS: Improve nfsiod workqueue detection for allocation flags Date: Mon, 7 Jul 2025 14:46:04 -0400 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" The NFS client writeback paths change which flags are passed to their memory allocation calls based on whether the current task is running from within a workqueue or not. More specifically, it appears that during writeback allocations with PF_WQ_WORKER set on current->flags will add __GFP_NORETRY | __GFP_NOWARN. Presumably this is because nfsiod can simply fail quickly and later retry to write back that specific page should the allocation fail. However, the check for PF_WQ_WORKER is too general because tasks can enter = NFS writeback paths from other workqueues. Specifically, the loopback driver tends to perform writeback into backing files on NFS with PF_WQ_WORKER set, and additionally sets PF_MEMALLOC_NOIO. The combination of PF_MEMALLOC_NOIO with __GFP_NORETRY can easily result in allocation failures and the loopback driver has no retry functionality. As a result, after commit 0bae835b63c5 ("NFS: Avoid writeback threads getting stuck in mempool_alloc()") users are seeing corrupted loop-mounted filesystems backed by image files on NFS. In a preceding patch, we introduced a function to allow NFS to detect if the task is executing within a specific workqueue. Here we use that helper to set __GFP_NORETRY | __GFP_NOWARN only if the workqueue is nfsiod. Fixes: 0bae835b63c5 ("NFS: Avoid writeback threads getting stuck in mempool= _alloc()") Signed-off-by: Benjamin Coddington Reviewed-by: Jeff Layton Reviewed-by: Laurence Oberman Tested-by: Laurence Oberman --- fs/nfs/internal.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 69c2c10ee658..173172afa3f5 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -12,6 +12,7 @@ #include #include #include +#include =20 #define NFS_SB_MASK (SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS) =20 @@ -669,9 +670,18 @@ nfs_write_match_verf(const struct nfs_writeverf *verf, !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier); } =20 +static inline bool is_nfsiod(void) +{ + struct workqueue_struct *current_wq =3D current_workqueue(); + + if (current_wq) + return current_wq =3D=3D nfsiod_workqueue; + return false; +} + static inline gfp_t nfs_io_gfp_mask(void) { - if (current->flags & PF_WQ_WORKER) + if (is_nfsiod()) return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; return GFP_KERNEL; } --=20 2.47.0