From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lgeamrelo11.lge.com (lgeamrelo11.lge.com [156.147.23.51]) (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 73638439325 for ; Tue, 21 Jul 2026 07:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.23.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784620720; cv=none; b=c9btvgft3j1I2gUVnQZd66TpUhBRlI+9SmbqwIDyMCE0taUtvY+2wUfZ0HjOv+HXHZnzW5bGpnMCepLvfv5IfF3942b8xTneUVEFktBFrp3JO0GgfAOYpcBI2fPrjeqkw8Rxf0N0NRCNRdK43qj9dSR5BfNqLNdmxeII3XFmia8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784620720; c=relaxed/simple; bh=99eQIqGAUpyGNKVhY2GaBY3l+4ir959MOQa+Tmu4E/0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i0dg9z/pp9ERa7lmcx9j9FCG0px1AiWLdKtBGco4znMLARZgGqBIYMwolp0wDE0Oh8H534F93/vbASM6b36/x0htgWwjx1W4/TZFsdQWCTufJtyqQBpb/LEXw8s2pPP93/mbAd9bgDNj4Z1oL0lYIoek8B+0UakzqJ14WICZbNo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.23.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgeamrelo02.lge.com) (156.147.1.126) by 156.147.23.51 with ESMTP; 21 Jul 2026 16:58:34 +0900 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: youngjun.park@lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330) (10.177.112.156) by 156.147.1.126 with ESMTP; 21 Jul 2026 16:58:34 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com Date: Tue, 21 Jul 2026 16:58:34 +0900 From: Youngjun Park To: Kemeng Shi Cc: chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, baoquan.he@linux.dev, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/4] mm, swap: Remove unneeded swap_extend_table_try_free() in swap_dup_entries_cluster() Message-ID: References: <20260720071342.50742-1-shikemeng@huaweicloud.com> <20260720071342.50742-5-shikemeng@huaweicloud.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: <20260720071342.50742-5-shikemeng@huaweicloud.com> On Mon, Jul 20, 2026 at 03:13:42PM +0800, Kemeng Shi wrote: > Since commit 0475fde0f68de ("mm, swap: avoid leaving unused extend table > after alloc race"), extend table is always allocated when any swap count Looks like this? 395085eacdfa > reach MAX - 1 and is always freed when swap count decrease to MAX - 1 > or MAX - 2 with cluster lock held. So the extend table will always be > freed properly when decrease swap count in __swap_cluster_put_entry(). > So swap_extend_table_try_free() outside of __swap_cluster_put_entry() > is unneeded and can be removed. > > Signed-off-by: Kemeng Shi > --- > mm/swapfile.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 3fcbd10c6353..fc9f16bc2e4e 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1732,7 +1732,6 @@ static int swap_dup_entries_cluster(struct swap_info_struct *si, > failed: > while (ci_off-- > ci_start) > __swap_cluster_put_entry(ci, ci_off); Right, it handles duplicate here. > - swap_extend_table_try_free(ci); > swap_cluster_unlock(ci); > return err; > } > -- > 2.36.1 However, looking at this part, since swap_extend_table_alloc() uses GFP_ATOMIC, I think it could be further improved by not releasing the ci lock. This would also clarify the situation where scount becomes MAX - 2. But there seem to be some drawbacks. For instance, the original intention might have been to make the swap_extend_table_alloc() API work seamlessly for both sleepable and unsleepable contexts, and some implementation details might not look as clean. Here is what I was thinking: ... err = __swap_cluster_dup_entry(ci, ci_off); /* <- Could -ENOMEM handling be improved here? */ if (unlikely(err)) { if (err == -ENOMEM) { spin_unlock(&ci->lock); /* <- Change to NOT release the lock, and make * swap_extend_table_alloc aware of it with * GFP_ATOMIC(aware cluster locked) */ err = swap_extend_table_alloc(si, ci, ci_off, GFP_ATOMIC); spin_lock(&ci->lock); if (!err) goto restart; Just sharing my thoughts! (Wondering if this could be a good direction for further improvement?) The current modification looks good enough to me. Reviewed-by: Youngjun Park Youngjun