From nobody Mon Apr 6 14:55:33 2026 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 95DD83368BD for ; Thu, 19 Mar 2026 03:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773889649; cv=none; b=c/hMPqO5pS8LmOv5svIBbpufSkIYIZttAVMie15uAGjVT4Xr8LnDLvKYBlfzv2ohn1STJhr1WyfKaqtDigldZmw8iw8APDGRlAhTOhLMesthxa2TPEj327O/Lrvi0Z6RN5LI2Lv1NS1/uOUl4s8xfLSRXw/2rFKikwpNCSWC0JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773889649; c=relaxed/simple; bh=JquhJeqyY9JJ4md/H744Y7j4rH7nuwglQtwbONi7M+I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=a2DqF9XOA22jO81igxUU9SyCTn0gN1p3NqTq05BJgmI8x3QrRPZnD9y3wokQ+3M0zM1JQWYt4cwm5emnbbRnZtDL5RGOfcbli67nnUGEzqCybtS4M8sUAhy+X6TSJ8RHq5mETiGc/uOccwHHCiKF9K2mvE7o5p4VhiyIjWNdCNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lLxmA3bz; arc=none smtp.client-ip=91.218.175.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lLxmA3bz" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773889645; 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; bh=6hujQatMDnVNbQ2NGpCAprMmrazeehMBUZspO/yPHpc=; b=lLxmA3bz/arCyCkRMch4A6JK6jCtdnU+JSRXE7p0M3FZJ6gXY1Lh4taTdEghRxRgufa6hO uEeuM+d3dc5bC0wpIDLXjX7CEsqyh0YCRTV+2sziEAzrrzMiPTeYfoWd0GlNTdFszW9Oz0 o0H076XKaHzWDiqKYkiu+8UVqL0cFxA= From: Hui Zhu To: Minchan Kim , Sergey Senozhatsky , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: teawater Subject: [PATCH v2] zsmalloc: return -EBUSY for zspage migration lock contention Date: Thu, 19 Mar 2026 11:07:09 +0800 Message-ID: <20260319030709.62556-1-hui.zhu@linux.dev> 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-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: teawater movable_operations::migrate_page() should return an appropriate error code for temporary migration failures so the migration core can handle them correctly. zs_page_migrate() currently returns -EINVAL when zspage_write_trylock() fails. That path reflects transient lock contention, not invalid input, so -EINVAL is clearly wrong. However, -EAGAIN is also inappropriate here: the zspage's reader-lock owner may hold the lock for an unbounded duration due to slow decompression. Since migration retries are bounded by NR_MAX_MIGRATE_PAGES_RETRY and performed with virtually no delay between attempts, there is no guarantee the lock will be released in time for a retry to succeed. -EAGAIN implies "try again soon", which does not hold in this case. Return -EBUSY instead, which more accurately conveys that the resource is occupied and migration cannot proceed at this time. Changelog: v2: According to the comments of Sergey Senozhatsky, change from -EAGAIN to -EBUSY and add comments. Signed-off-by: teawater Acked-by: Sergey Senozhatsky --- mm/zsmalloc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 2c1430bf8d57..db42ec4ffcfa 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1727,7 +1727,19 @@ static int zs_page_migrate(struct page *newpage, str= uct page *page, if (!zspage_write_trylock(zspage)) { spin_unlock(&class->lock); write_unlock(&pool->lock); - return -EINVAL; + /* + * Return -EBUSY but not -EAGAIN: the zspage's reader-lock + * owner may hold the lock for an unbounded duration due to a + * slow decompression. + * Since migration retries are bounded by + * NR_MAX_MIGRATE_PAGES_RETRY and performed with virtually no + * delay between attempts, there is no guarantee the lock will + * be released in time for a retry to succeed. + * -EAGAIN implies "try again soon", which does not hold here. + * -EBUSY more accurately conveys "resource is occupied, + * migration cannot proceed". + */ + return -EBUSY; } =20 /* We're committed, tell the world that this is a Zsmalloc page. */ --=20 2.43.0