From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCE0D3D47D0 for ; Thu, 19 Mar 2026 13:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773926623; cv=none; b=ouRLh3/++eVo/wi+D8Ghp2CBCjo8jZk9S317VOShmHZnREoGdmu0/MbapdGQB24KIbIKm8l9Jt88gPLzw7OT6Z9a+ST7+7OV0LHg7Xl8eMtQKWN0pZjXjWAGMCPz1ufNcbmSJ8o6V3LOCnzmc0mhht/H/qbfkHCL5rsqPA7XlAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773926623; c=relaxed/simple; bh=8BDuG8Vvc1rVleNk0aNinytFmfZVuf0snhQQ6VXU34g=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R2U2CIpGA1t6DVRiWQ+b6gleiI61X+qofVJH6P7DlhB8jAuCUBlY108Bsznq9orq3dgS0vJyNQpEipIwjXEAgdxEfZhfomNfT6fOVx1EEdu11+lSKQ5CO2wryH6KRh4kDasfQ7P4k0pvHWlZ6QRnLikOqeiiK7Xnu1LtmmrkXPs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jX2CSHRV; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jX2CSHRV" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5a278b4c1a5so817290e87.3 for ; Thu, 19 Mar 2026 06:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773926620; x=1774531420; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=gi1yeZfgvnivbkzQjzFZaRoJUwW3BJjiIJuxd//iTGg=; b=jX2CSHRV70FFvvgRSH1s7x2ntsv9KNjdCVOkQ4I21mgcsZWax58ZQvU42GI5c0Fe2i Cn3gVJdW9fdc3xEV1Kh5QW96NgEJ3OWH3mepfAgu9rWUKPvnVXt8fac9giiEWZRAT65E zGtwXiiJNmyO3f8+bOrPjrSdIHj/22MxE5EmFUL3S3pTT4RNUFPjCXwtBdgFlgH1y+RI OzN3dkaFAZ34a448Jgu8y6I9yjl7fdm4pzla1YhVK63syhz9ZLhTNcumhX8/UK+sDoqu LGAIHjtfZKtAppTJD+TNWbtSnAHI4erCxuomYzSqgheP4aS4GFfpTEcg96DURflHzucH xQ4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773926620; x=1774531420; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gi1yeZfgvnivbkzQjzFZaRoJUwW3BJjiIJuxd//iTGg=; b=aZakwRti6YDi3P7Cn2nn5lR5Xkdl/SPd5nl9wO++CO5ATUZXt2w2ECHL4b0e3jKNpx aRt99vAWOeGmFWpYPigYdLVN8Yb1NablzRTadBY4MuZlrBEzd36XBI+sibKwj14lxWyF kC/bdn7qdcBAPH2fZfcHpvAYCmMhN6vlbYE2VkSGlNMupbz47B595NPbxUBwkdh8qnsJ hlXdtYx3X3JIx8B2+8YcDcJD0FDTWNIumYuQ4GbPDLaf8Q7cxd3ssS36dES25NEDRlll F48kt3iaVptK8XeXME08+Tck2ZwP15qOFS/iGXDqkWU+KvMf2GaTY/rS47hX0AjMtV1m soTQ== X-Forwarded-Encrypted: i=1; AJvYcCUm/v0LXANxjtP6c6uHFtTyfPWsaUk5TrCFozXQEBMSoH0ctsduhqgwrGYtsAigqhG5CXLoLUR5YEYe01U=@vger.kernel.org X-Gm-Message-State: AOJu0YzrKFbWlBP7sd3lE5qe/+tX3O82PX2owrbvJWpsbHVxWGQiAE6I o2XcGeLyV3jpzdYTUZkFFCA69nPn6f4jbFQ6UeYKly+PfcgMo4XM+B5yn7OnT6Kk X-Gm-Gg: ATEYQzxXHh+D3xKOw/83p1TB/T0rUUbH+4XV/Ztgbao+0mlscoUJ2iETQ2BnDcMZsRP 494f6v6gcBwt21rqPb5YuoiUjNrKp1IStv0AtKm6xmDvO/Cn0/75mNWhHeZ73TPD6tT3lZaM695 1VgzUwdhy3ib6+BDiAZUUnMMQ8/rDpkFm8EBkLK9M1dxpMEVMcD4NMnc/nw4j+M8y1V9OFl2z/W 0YaElLrVnxLkXg67A403U2IZ/LlZtoYFtAxqj//1x506CmrrqDckOHcbzj7/DKCvQBqmfuvTc/n IaC/zIBs8pS+xcWFvhVQFX8cTVt1HJrYMpIODlgdVdU3LOyZYDkEPCM9PwCHiPDO7M6OByVTf2j L+VUhZsj0QNBjiET+aqBQaIcOp2/s+5fHhU8sskYuF0bx2fW5aaF0vQe71DWW+lC+ X-Received: by 2002:a05:6512:14d:b0:5a1:74e3:203e with SMTP id 2adb3069b0e04-5a2796b61d5mr2389827e87.41.1773926619474; Thu, 19 Mar 2026 06:23:39 -0700 (PDT) Received: from milan ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a279c2c11dsm1212391e87.22.2026.03.19.06.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 06:23:39 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 19 Mar 2026 14:23:37 +0100 To: "Li,Rongqing(ACG CCN)" Cc: Uladzislau Rezki , Andrew Morton , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: =?utf-8?B?562U5aSNOiBbPz8/P10gUmU6IFtQ?= =?utf-8?Q?ATCH_v2=5D_mm=2Fvmalloc?= =?utf-8?Q?=3A?= use dedicated unbound workqueue for vmap area draining Message-ID: References: <20260319074307.2325-1-lirongqing@baidu.com> <73a0ae8d2a334777a199a1555d6fdaaa@baidu.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <73a0ae8d2a334777a199a1555d6fdaaa@baidu.com> On Thu, Mar 19, 2026 at 10:05:42AM +0000, Li,Rongqing(ACG CCN) wrote: > > > > On Thu, Mar 19, 2026 at 03:43:07AM -0400, lirongqing wrote: > > > From: Li RongQing > > > > > > The drain_vmap_area_work() function can take >10ms to complete when > > > there are many accumulated vmap areas in a system with a high CPU > > > count, causing workqueue watchdog warnings when run via > > > schedule_work(): > > > > > > [ 2069.796205] workqueue: drain_vmap_area_work hogged CPU > > for >10000us > > > 4 times, consider switching to WQ_UNBOUND [ 2192.823225] workqueue: > > > drain_vmap_area_work hogged CPU for >10000us 5 times, consider > > > switching to WQ_UNBOUND > > > > > > Switch to a dedicated WQ_UNBOUND workqueue to allow the scheduler to > > > run this background task on any available CPU, improving responsiveness. > > > Use WQ_MEM_RECLAIM to ensure forward progress under memory > > pressure. > > > > > > Create vmap_drain_wq in vmalloc_init_late() which is called after > > > workqueue_init_early() in start_kernel() to avoid boot-time crashes. > > > > > > Suggested-by: Uladzislau Rezki > > > Signed-off-by: Li RongQing > > > --- > > > Diff with v1: create dedicated unbound workqueue > > > > > > include/linux/vmalloc.h | 2 ++ > > > init/main.c | 1 + > > > mm/vmalloc.c | 14 +++++++++++++- > > > 3 files changed, 16 insertions(+), 1 deletion(-) > > > > > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index > > > e8e94f9..c028603 100644 > > > --- a/include/linux/vmalloc.h > > > +++ b/include/linux/vmalloc.h > > > @@ -301,11 +301,13 @@ static inline void set_vm_flush_reset_perms(void > > *addr) > > > if (vm) > > > vm->flags |= VM_FLUSH_RESET_PERMS; > > > } > > > +void __init vmalloc_init_late(void); > > > #else /* !CONFIG_MMU */ > > > #define VMALLOC_TOTAL 0UL > > > > > > static inline unsigned long vmalloc_nr_pages(void) { return 0; } > > > static inline void set_vm_flush_reset_perms(void *addr) {} > > > +static inline void __init vmalloc_init_late(void) {} > > > #endif /* CONFIG_MMU */ > > > > > > #if defined(CONFIG_MMU) && defined(CONFIG_SMP) diff --git > > > a/init/main.c b/init/main.c index 1cb395d..50b497f 100644 > > > --- a/init/main.c > > > +++ b/init/main.c > > > @@ -1099,6 +1099,7 @@ void start_kernel(void) > > > * workqueue_init(). > > > */ > > > workqueue_init_early(); > > > + vmalloc_init_late(); > > > > > No, no. We should not patch main.c for such purpose :) > > > > > rcu_init(); > > > kvfree_rcu_init(); > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 61caa55..a52ccd4 100644 > > > --- a/mm/vmalloc.c > > > +++ b/mm/vmalloc.c > > > @@ -1067,6 +1067,7 @@ static void > > reclaim_and_purge_vmap_areas(void); > > > static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); > > > static void drain_vmap_area_work(struct work_struct *work); static > > > DECLARE_WORK(drain_vmap_work, drain_vmap_area_work); > > > +static struct workqueue_struct *vmap_drain_wq; > > > > > > static __cacheline_aligned_in_smp atomic_long_t nr_vmalloc_pages; > > > static __cacheline_aligned_in_smp atomic_long_t vmap_lazy_nr; @@ > > > -2471,7 +2472,7 @@ static void free_vmap_area_noflush(struct vmap_area > > > *va) > > > > > > /* After this point, we may free va at any time */ > > > if (unlikely(nr_lazy > nr_lazy_max)) > > > - schedule_work(&drain_vmap_work); > > > + queue_work(vmap_drain_wq, &drain_vmap_work); > > > } > > > > > > /* > > > @@ -5422,6 +5423,17 @@ vmap_node_shrink_scan(struct shrinker > > *shrink, struct shrink_control *sc) > > > return SHRINK_STOP; > > > } > > > > > > +void __init vmalloc_init_late(void) > > > +{ > > > + vmap_drain_wq = alloc_workqueue("vmap_drain", > > > + WQ_UNBOUND | WQ_MEM_RECLAIM, 0); > > > + if (!vmap_drain_wq) { > > > + pr_warn("vmap_drain_wq creation failed, using > > system_unbound_wq\n"); > > > + vmap_drain_wq = system_unbound_wq; > > > + } > > > + > > > +} > > > + > > > void __init vmalloc_init(void) > > > { > > > struct shrinker *vmap_node_shrinker; > > > -- > > > 2.9.4 > > > > > Why can't you add this into the vmalloc_ini()? > > > > If alloc_workqueue() is added into vmalloc_ini(), system will crash and fail to boot, sine allocate workqueue depends on workqueue_init_early() > > Maybe this commit 3347fa092821("workqueue: make workqueue available early during boot") shows the reason > That is true. diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 61caa55a4402..81e1e74346d5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1067,6 +1067,7 @@ static void reclaim_and_purge_vmap_areas(void); static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); static void drain_vmap_area_work(struct work_struct *work); static DECLARE_WORK(drain_vmap_work, drain_vmap_area_work); +static struct workqueue_struct *drain_vmap_wq; static __cacheline_aligned_in_smp atomic_long_t nr_vmalloc_pages; static __cacheline_aligned_in_smp atomic_long_t vmap_lazy_nr; @@ -2437,6 +2438,17 @@ static void drain_vmap_area_work(struct work_struct *work) mutex_unlock(&vmap_purge_lock); } +static void +schedule_drain_vmap_work(unsigned long nr_lazy, unsigned long nr_lazy_max) +{ + if (unlikely(nr_lazy > nr_lazy_max)) { + struct workqueue_struct *wq = READ_ONCE(drain_vmap_wq); + + if (wq) + queue_work(wq, &drain_vmap_work); + } +} + /* * Free a vmap area, caller ensuring that the area has been unmapped, * unlinked and flush_cache_vunmap had been called for the correct @@ -2470,8 +2482,7 @@ static void free_vmap_area_noflush(struct vmap_area *va) trace_free_vmap_area_noflush(va_start, nr_lazy, nr_lazy_max); /* After this point, we may free va at any time */ - if (unlikely(nr_lazy > nr_lazy_max)) - schedule_work(&drain_vmap_work); + schedule_drain_vmap_work(nr_lazy, nr_lazy_max); } /* @@ -5483,3 +5494,15 @@ void __init vmalloc_init(void) vmap_node_shrinker->scan_objects = vmap_node_shrink_scan; shrinker_register(vmap_node_shrinker); } + +static int __init vmalloc_init_workqueue(void) +{ + struct workqueue_struct *wq; + + wq = alloc_workqueue("vmap_drain", WQ_UNBOUND | WQ_MEM_RECLAIM, 0); + WARN_ON(wq == NULL); + WRITE_ONCE(drain_vmap_wq, wq); + + return 0; +} +early_initcall(vmalloc_init_workqueue); -- Uladzislau Rezki