From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 48CE23019D9 for ; Fri, 22 May 2026 02:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779417612; cv=none; b=pCTpAFou6phlo/B98MUQclKwXse2zQbI6UOJoGIoOq7xNJcaHZvrKnEK6W6ulAGONVR5KHR+yzt5ZE2gynJ0BbdzMpURbfnNI2oAFvRDF5mR7mNhpW7nlanUGNs/VjddwXSpifjW300AzawvwRnCIgPnNHxuAAxqhCct9VePFJ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779417612; c=relaxed/simple; bh=SVQEKYdpdNnKbRYWNJeLNtIxpMqsFNK9r30AKMgQ/XI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=atgb6/anowAZLzOO0THtbZs9F83RtvduQWmOtRExRRoiNVjPtE8JUWnJ886kBTJFvyxWqzoXj6AXFZzAdjqr/nyqQbP65At4kl/0u3prug8Fp77C3GcGUVR9cdGxOgYsJexLGTSct0MwDAHqJMknlAW+N3JrM6tk0UerXYIM5EU= 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=KpMw8dK4; arc=none smtp.client-ip=209.85.216.46 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="KpMw8dK4" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-36974217d4eso4332510a91.2 for ; Thu, 21 May 2026 19:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779417608; x=1780022408; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fm97KPHUVYZqun0p/IlrOCNvbRaK3CQJwbnFDIX8nLA=; b=KpMw8dK41KouEnK+o6NAwu0/1g519AlVS6yPXX08PAvNmOg6HyXRiC9jawGm66kTUp uRjMzcHnFkb0eHR5gxRI4ILxT1guF3mSnKHQCNeo+YRG3eUwyfI5qxKAntM/yPLHfiJ0 FLVzlcm48hYgt7fIUpwsKjWy9g34WARVJL4bOpNf6aoFNiBsvFuftSE0Ka5IFMaTOVmP dv1VQEY0LfWKYm9OOwTwDXv7FuZoP3bMnInpTStp1zQ9Zc1vzGLt+WozwdOPhCso0hod jwgFpZGI+Z8HnzYpxv8H4IGVuXY9c0Kn4ogk7fwUP8OkrjfUUvcEnUysk2ICEFtuWttA Pi5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779417608; x=1780022408; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fm97KPHUVYZqun0p/IlrOCNvbRaK3CQJwbnFDIX8nLA=; b=sNeQznVVvHH/xgTyDSWicqBo0oI6MNA8OqkQrFJkCg9qQlkP6M8zscNwvoJbtI7pMP VP9qrID+OZ/GexioB8v5penprP576Sizi1o9tXqGIw97wVRY724o6MR6dUclV9LPBlH9 a4qIctfIhZ/FqdAngrKXf+PDxEPTjCvgmVhPNeyB5imtBLwFiCEUWcoVS9nBRJLc53/W lILhDnkv9eW6yyx8D3CE3593jmmQGPGhE0dkAjpFBZGjzuYMhcwycCSA6eIxhyViygMk RXJOa08g8kHANBH5DmboDWH6zCFrI+IPkoKqkkQ/eWKqKvTXt2TQC3fkk62LBTtSsRlv 2IdQ== X-Forwarded-Encrypted: i=1; AFNElJ8ZgLZ01rI7tRxM35NTb3Zyo+EeEGeKJiS7oylxE7a8OjJ0YHXw54iHjubpeGYIoiSWI1/P1sR+SCtPXpA=@vger.kernel.org X-Gm-Message-State: AOJu0YwrdXluztXgly9oupNPQN8bjWHu4DQitnYIIAcRbvE+FRgjtphD PCrwYZFm97UnUwmIEX5fDqqwccre6NSxxu76aWwLwB0oY1L+03mF4CZO X-Gm-Gg: Acq92OF8PeWMZdsJc1ARuKz1FjLaxk/97E5pVOrYGr4BtEic+zvVKDrLdqYOY42YBww EMEjWA3UHIMTOT4BRm9iyWIUprIRkZdFkluYU8RZ7ej3AmEl41sYzCwZe64q/dX2bt6jyCTCUs4 mcSOnSsneyw1LC53KDRsQOL8+G3DGCruzvnSLizS+RcwTb31vgjFN+5WxJ/Ufzynumdut+/JaEe 6LkWZCxf8lNeuKzrCPOlOo+p02NJliTaSkINw7MgJsmbm2/VDZ2/chq8ZqKQPEW1nBXC5BwLjz5 s33QN2uxvsG77YwiKzq36GSjGzvRtYJLT/OWKsdpoZf0dUDCyrCrqJ5Kvi1PZQJ3NzRbUPaEj8i g+1VtZaRvZaLE+2sr7wUgHS6u8pTqy5D4nDXyxKwj37NLWZrFwKMSGT6JcdjcHIQb+pVL/pJC5H eLfmFeI9wRCFKIoS3EM/OpFpVAQTJtMjELFOJmyEKjUAguh7adcVPcIGjZdssEaHTKf1AYPCmb X-Received: by 2002:a05:6a21:a343:b0:3a2:dbaa:82ee with SMTP id adf61e73a8af0-3b328caba66mr1544588637.9.1779417608238; Thu, 21 May 2026 19:40:08 -0700 (PDT) Received: from KASONG-MC4 ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c85202901e6sm72726a12.2.2026.05.21.19.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 19:40:07 -0700 (PDT) Date: Fri, 22 May 2026 10:39:59 +0800 From: Kairui Song To: Andrew Morton Cc: kasong@tencent.com, Kairui Song via B4 Relay , linux-mm@kvack.org, David Hildenbrand , Zi Yan , Baolin Wang , Barry Song , Hugh Dickins , Chris Li , Kemeng Shi , Nhat Pham , Baoquan He , Johannes Weiner , Youngjun Park , Chengming Zhou , Roman Gushchin , Shakeel Butt , Muchun Song , Usama Arif , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Lorenzo Stoakes , Yosry Ahmed , Qi Zheng Subject: Re: [PATCH v5 12/12] mm, swap: merge zeromap into swap table Message-ID: References: <20260517-swap-table-p4-v5-0-88ae43e064c7@tencent.com> <20260517-swap-table-p4-v5-12-88ae43e064c7@tencent.com> <20260521185204.a109bfcd1e0e8f52135c5ed5@linux-foundation.org> 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: <20260521185204.a109bfcd1e0e8f52135c5ed5@linux-foundation.org> On Thu, May 21, 2026 at 06:52:04PM +0800, Andrew Morton wrote: > On Sun, 17 May 2026 23:39:51 +0800 Kairui Song via B4 Relay wrote: > > > From: Kairui Song > > > > By allocating one additional bit in the swap table entry's flags field > > alongside the count, we can store the zeromap inline > > > > For 64 bit systems, zeromap will store in the swap table, avoiding zeromap > > allocation. It reduces the allocated memory. That is the happy path. > > > > For certain 32-bit archs, there might not be enough bits in the swap > > table to contain both PFN and flags. Therefore, conditionally let each > > cluster have a zeromap field at build time, and use that instead. > > If the swapfile cluster is not fully used, it will still save memory for > > zeromap. The empty cluster does not allocate a zeromap. In the worst case, > > all cluster are fully populated. We will use memory similar to the > > previous zeromap implementation. > > > > A few macros were moved to different headers for build time struct > > definition. > > > > ... > > > > @@ -469,13 +474,21 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp) > > VM_WARN_ON_ONCE(ci->memcg_table); > > ci->memcg_table = kzalloc_obj(*ci->memcg_table, gfp); > > if (!ci->memcg_table) > > - ret = -ENOMEM; > > + goto err_free; > > } > > #endif > > - if (ret) > > - swap_cluster_free_table(ci); > > > > - return ret; > > +#if !SWAP_TABLE_HAS_ZEROFLAG > > + VM_WARN_ON_ONCE(ci->zero_bitmap); > > + ci->zero_bitmap = bitmap_zalloc(SWAPFILE_CLUSTER, gfp); > > + if (!ci->zero_bitmap) > > + goto err_free; > > +#endif > > + return 0; > > + > > +err_free: > > + swap_cluster_free_table(ci); > > + return -ENOMEM; > > } > > My m68k defconfig warned. I'll do the below, which looks good enough. > Please check. > > Perhaps a custom guard() handler would clean things up here. > > > From: Andrew Morton > Subject: mm-swap-merge-zeromap-into-swap-table-fix-2 > Date: Thu May 21 06:39:20 PM PDT 2026 > > mm/swapfile.c: In function 'swap_cluster_alloc_table': > mm/swapfile.c:488:1: warning: label 'err_free' defined but not used [-Wunused-label] > 488 | err_free: > | ^~~~~~~~ > > Cc: Baolin Wang > Cc: Baoquan He > Cc: Barry Song > Cc: Chengming Zhou > Cc: Chris Li > Cc: David Hildenbrand > Cc: Hugh Dickins > Cc: Johannes Weiner > Cc: Kairui Song > Cc: Kemeng Shi > Cc: Lorenzo Stoakes > Cc: Muchun Song > Cc: Nhat Pham > Cc: Roman Gushchin > Cc: Shakeel Butt > Cc: Youngjun Park > Cc: Zi Yan > Signed-off-by: Andrew Morton > --- > > mm/swapfile.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > --- a/mm/swapfile.c~mm-swap-merge-zeromap-into-swap-table-fix-2 > +++ a/mm/swapfile.c > @@ -472,22 +472,22 @@ static int swap_cluster_alloc_table(stru > if (!mem_cgroup_disabled()) { > VM_WARN_ON_ONCE(ci->memcg_table); > ci->memcg_table = kzalloc_obj(*ci->memcg_table, gfp); > - if (!ci->memcg_table) > - goto err_free; > + if (!ci->memcg_table) { > + swap_cluster_free_table(ci); > + return -ENOMEM; > + } > } > #endif > > #if !SWAP_TABLE_HAS_ZEROFLAG > VM_WARN_ON_ONCE(ci->zero_bitmap); > ci->zero_bitmap = bitmap_zalloc(SWAPFILE_CLUSTER, gfp); > - if (!ci->zero_bitmap) > - goto err_free; > + if (!ci->zero_bitmap) { > + swap_cluster_free_table(ci); > + return -ENOMEM; > + } > #endif > return 0; > - > -err_free: > - swap_cluster_free_table(ci); > - return -ENOMEM; > } > > /* > _ > Looks good, thank you. The error path is still simple and straight at the moment. It will be even better if we also remove the now unused ret variable as well (this isn't triggering warning yet since Kbuild don't set unused-but-set-variable by default): diff --git a/mm/swapfile.c b/mm/swapfile.c index 9712cc862c9c..615d90867111 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -450,7 +450,6 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp) { struct swap_table *table = NULL; struct folio *folio; - int ret = 0; /* The cluster must be empty and not on any list during allocation. */ VM_WARN_ON_ONCE(ci->flags || !cluster_is_empty(ci));