From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 6A3FC397E8E for ; Mon, 24 Aug 2026 13:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787577588; cv=none; b=uQK9ZLfTJYggi3a2PH3QEmq98tfmH4uKc3lFk3wLdzCjk8CW0bTLNET3/wmGffD72QpdxvW6juTDKNAWTDmBajKNt8Gc+EtT1K2TDfptl8tf6ExigjGg8/iXBqEPo8lK0UCVQW+RC826VhooDCyyizsMBt4+XLna57GCwFo4yw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787577588; c=relaxed/simple; bh=N77q8rayXqcpV4pfB4C+vnb2LyShhyE8NRdHXKlU9/Q=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TjQCGXZZq/WJKbgBET5+wyb5L0ZbeE7LlHunYW4zSOeazbepVkT/V3+pUgm4T1NRUCSjwIQ7SgDLeUfGT3zGZ0amEPqAWjAdsI1IGetU2ij1KO97akvfPKNZCQ498DCsJFtXP4dtCCprwLt0jbQoj63qMa5we+60QPnWBJ9QPz8= 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=WkVh787f; arc=none smtp.client-ip=209.85.218.48 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="WkVh787f" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-c15d47266baso393368766b.3 for ; Mon, 24 Aug 2026 06:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787577585; x=1788182385; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=yUP9UlMsBWRJmeASo8LmnRIcQu22MzYbbDAVky2m5Rk=; b=WkVh787fI+kzlSiHcvTS1nIXrIEibz2IMqMmq1EFAA5Z/wKtFcbrZgrbzFD5jBOvNH DnuoS25FReb8redg2oVbFG/ThwCsYyNS5JV+J16Avj1JmnHB58JUW9MN0WZZcDKNas++ 1Y0h63kr+zxRivr0mZuzxt5BIwIKM97/Ea3eVEuSyXsodfCiftBv0ALhYVuf8+W+MYzD EOTLe6UpC+rElRb0pdp/IjUpjgb6RA9panyHvNVNdk20oBNUCVBe/IEjCt8gEAdO6Nvt cVATxLwi7d2wlC/6HifJjB1Y+zpwhGrkB9ciFgEI3Lh+VPcKZ30Z69XNzTDI2Ot3OOJI L4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787577585; x=1788182385; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=yUP9UlMsBWRJmeASo8LmnRIcQu22MzYbbDAVky2m5Rk=; b=GChIQXPmrzX3fHzKUnBSBKI8LOkwDGhlmWTkd3bJeM3kZ53ElMwkBaiTWJO2djNIBF 2kTT1QP6cGIc7zVzkdL7W6HYBqYIEiWQiMIJ65Y7A8Ft9/3Uqxfz7CwEz4b0fpwr6Rf/ rY42QD6PT7ZQfjPjyUr6D20iq7Iw4QP0gUd7hbHhHjMxDMSKqne/Ph3gkNXbag/WPBpz mHh4pCZl0Kw0l0G8zmGZll+FoRrAQEQkAiGjk/LHRZg5DtThXVTQ9VNTv/1JHYB0zbRf ZOE2lW4kWbTTWt6tLQJ9wo2EEJQ+O+0obzGVe86T+99YvE0u+YlUaxg8HvFa0OtLxdcI PW5A== X-Forwarded-Encrypted: i=1; AHgh+RrEJkLt6BE3LYVUQCAyBjI2sxFefAfLcpUj5i3c9YeDpfYsi41Bta+a9JYPEU2fXRqPEc+JuFivMJuUbhM=@vger.kernel.org X-Gm-Message-State: AFuF++kXgFYWPS9x15BriETJ+HhWo+7t/xhCzRhe4uZKeV6e565HHXaK jX+RD+jV0ob7sl5wIzA5tuTzzGKCad0/HniQVOO0IA82zkkIyjT5jn+E X-Gm-Gg: AR+sD10azdqI8p4T0fxq6R3FOFS1Zll/058xjjcaxdDcH5WQf7gN86xQT6lEfuH/u/y rqxeQdiWfGkkR5hk2qqwMWfB4eAvqx454lW01Gk5Xguz+ExLnkD9OKgvzzPmNolUmgIec/SWR2G mLBbkzqKCHh2R0tamOxsdOBB00FBPW9fUooGjhSGgxA7rfX1Ky95MSS5fuUhUOD0tuFG68Qw+Hy /yA14icdEMSdNGZlOA/C2oXmZjnop8pZzk/WoBtMWyp1u/KcZJ/Q1VthA52KdaaZQod5xPGH5XY s7LoKrbflcmIgLY2jtsmi1qzT3B08WExk2M+jB4fNXluiFVV+lS4lp3yFlW7+mcE2Dj+NJgUxev ywcpWlm7NINgRukZAwIamFnDD9Xw/T8gJ7BdRKzl1E9yg1qCCAaVcDS7HvLTXQ5JXcCV0Zq8Lyh mGsWfLG1gWkzF7UMn+yUvqjJSt1w== X-Received: by 2002:a17:907:e901:b0:c16:769b:9838 with SMTP id a640c23a62f3a-c246a2eba8amr2906625466b.5.1787577584401; Mon, 24 Aug 2026 06:19:44 -0700 (PDT) Received: from milan ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c249673d43bsm1191762766b.47.2026.08.24.06.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 06:19:43 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 24 Aug 2026 15:19:42 +0200 To: Ye Liu Cc: Andrew Morton , Uladzislau Rezki , Ye Liu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/vmalloc: fix vmap_purge_lock livelock under memory pressure Message-ID: References: <20260824095020.1225189-1-ye.liu@linux.dev> 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: <20260824095020.1225189-1-ye.liu@linux.dev> On Mon, Aug 24, 2026 at 05:50:19PM +0800, Ye Liu wrote: > From: Ye Liu > > The vmap_purge_lock mutex can be held for an extended period by > __purge_vmap_area_lazy() which calls flush_work() to wait for > purge_vmap_node workers while holding the lock. Under memory > pressure, those workers may themselves be blocked in direct > reclaim trying to acquire the same lock via the > vmap_node_shrink_scan() shrinker callback, creating a circular > dependency that deadlocks the entire system. > > Two changes: > > 1. vmap_node_shrink_scan(): replace blocking guard(mutex) with > mutex_trylock(). This is a shrinker that only decays the vmap > pool and returns SHRINK_STOP without freeing memory; skipping a > decay cycle when the lock is contended is harmless and prevents > tasks from piling up on the mutex in the direct reclaim path. > > 2. __purge_vmap_area_lazy(): purge all vmap nodes inline instead of > scheduling purge_vmap_node via workqueue and calling flush_work() > while holding vmap_purge_lock. The workqueue dispatch + flush > pattern under a mutex is the deadlock trigger: if no free worker > threads are available (all blocked on the same lock), flush_work() > never returns and the lock is held indefinitely. > > Fixes: 7679ba6b36db ("mm: vmalloc: add a shrinker to drain vmap pools") > Signed-off-by: Ye Liu > --- > mm/vmalloc.c | 51 +++++++++++++++++++++------------------------------ > 1 file changed, 21 insertions(+), 30 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index bea9f76ed7e7..41443708d22d 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2358,7 +2358,6 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end, > bool full_pool_decay) > { > unsigned long nr_purged_areas = 0; > - unsigned int nr_purge_helpers; > static cpumask_t purge_nodes; > unsigned int nr_purge_nodes; > struct vmap_node *vn; > @@ -2397,36 +2396,17 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end, > if (nr_purge_nodes > 0) { > flush_tlb_kernel_range(start, end); > > - /* One extra worker is per a lazy_max_pages() full set minus one. */ > - nr_purge_helpers = atomic_long_read(&vmap_lazy_nr) / lazy_max_pages(); > - nr_purge_helpers = clamp(nr_purge_helpers, 1U, nr_purge_nodes) - 1; > - > - for_each_cpu(i, &purge_nodes) { > - vn = &vmap_nodes[i]; > - > - if (nr_purge_helpers > 0) { > - INIT_WORK(&vn->purge_work, purge_vmap_node); > - > - if (cpumask_test_cpu(i, cpu_online_mask)) > - schedule_work_on(i, &vn->purge_work); > - else > - schedule_work(&vn->purge_work); > - > - nr_purge_helpers--; > - } else { > - vn->purge_work.func = NULL; > - purge_vmap_node(&vn->purge_work); > - nr_purged_areas += vn->nr_purged; > - } > - } > - > + /* > + * Purge all nodes inline. Do not schedule_work() and > + * flush_work() here: flush_work() while holding > + * vmap_purge_lock can deadlock if the worker pool is > + * starved (e.g. all workers blocked on this same lock > + * in the direct reclaim path via vmap_node_shrink_scan). > + */ > for_each_cpu(i, &purge_nodes) { > vn = &vmap_nodes[i]; > - > - if (vn->purge_work.func) { > - flush_work(&vn->purge_work); > - nr_purged_areas += vn->nr_purged; > - } > + purge_vmap_node(&vn->purge_work); > + nr_purged_areas += vn->nr_purged; > } > } > > @@ -5519,10 +5499,21 @@ vmap_node_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) > { > struct vmap_node *vn; > > - guard(mutex)(&vmap_purge_lock); > + /* > + * This shrinker is invoked from direct reclaim path where memory > + * pressure is already high. Blocking on vmap_purge_lock here can > + * cause a pile-up of tasks all waiting for the same mutex while > + * the lock holder may itself be blocked in flush_work() waiting for > + * a worker that is stuck in the same reclaim path. Use trylock to > + * avoid this; skipping a pool decay cycle is harmless. > + */ > + if (!mutex_trylock(&vmap_purge_lock)) > + return SHRINK_STOP; > + > for_each_vmap_node(vn) > decay_va_pool_node(vn, true); > > + mutex_unlock(&vmap_purge_lock); > return SHRINK_STOP; > } > > -- > 2.25.1 > Have you seen any report about the problem you described? -- Uladzislau Rezki