From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5D9AC2BCF7F for ; Wed, 17 Dec 2025 11:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765970582; cv=none; b=ZsCnVk6OrAEkOg44QykAa/OJ7tgQlYo3IIu5itKeQD+5GHZX5j10+PTifeNlyxDK4NyeLhb8mlkEDxxXWvRgqUFrAWh67rJ+8Kmb3lhwAPKldaHQ6NdGJ6hZgytdxxrWesM/Oa2lU1v8Fd0xDbXGh4S8GaHZtFtEKTKGZ5IL8DQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765970582; c=relaxed/simple; bh=BN+ZdQQTHZdwx9DjE5wAHGT5HeyPEMIgey8F3t3TZHM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NX0PLLp+gGjIYbENlMU3mCpZDtDiJyvk45Qz1dC60Q5+v5QaB9B63oPpjjeJzya4tbF6Lkoqf34+qapH5xnmRhwyDvMZbsA5blz6cPkMvxR8bw64mKpTGcWxljQo/BSWS7awTTMB0n6qh1UXy+8zY5nzUDTG/g59ylgtI9jcxao= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=M+s+eSNC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M+s+eSNC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765970577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dIV0ashPOP0A+MXzT9KnBJgDvJXqc+fF08sRABQUW2M=; b=M+s+eSNCCXTv+0eB0q5MNU/40K0cJic5nkQs6C2j+jWnJgdBx1aSsLmYIeE0i5RU4NCvKp WfY29f7om316B8x0Jmg9u0sB8mYTn6JE3Vi3cVxCxqZY88LeOwTn5gM/cD9+aa2JsmHXpn z+L2jV8Tm/xWNu8yz44iGfTzwzJQj2Q= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-wx-E1mOyOhutKciBFe40sg-1; Wed, 17 Dec 2025 06:22:52 -0500 X-MC-Unique: wx-E1mOyOhutKciBFe40sg-1 X-Mimecast-MFC-AGG-ID: wx-E1mOyOhutKciBFe40sg_1765970570 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 18A36195609F; Wed, 17 Dec 2025 11:22:49 +0000 (UTC) Received: from localhost (unknown [10.72.112.95]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 639CD180045B; Wed, 17 Dec 2025 11:22:45 +0000 (UTC) Date: Wed, 17 Dec 2025 19:22:41 +0800 From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , Barry Song , Chris Li , Nhat Pham , Yosry Ahmed , David Hildenbrand , Johannes Weiner , Youngjun Park , Hugh Dickins , Baolin Wang , Ying Huang , Kemeng Shi , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Kairui Song Subject: Re: [PATCH v4 11/19] mm, swap: split locked entry duplicating into a standalone helper Message-ID: References: <20251205-swap-table-p2-v4-0-cb7e28a26a40@tencent.com> <20251205-swap-table-p2-v4-11-cb7e28a26a40@tencent.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: <20251205-swap-table-p2-v4-11-cb7e28a26a40@tencent.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 On 12/05/25 at 03:29am, Kairui Song wrote: > From: Kairui Song > > No feature change, split the common logic into a stand alone helper to ~~~~~~~~~~~ standalone, typo? > be reused later. In phase 2, I saw the newly added swap_dup_entries() is only called by __swap_duplicate(). The 'reused later' means? > > Signed-off-by: Kairui Song > --- > mm/swapfile.c | 62 +++++++++++++++++++++++++++++------------------------------ > 1 file changed, 31 insertions(+), 31 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 2703dfafc632..d9d943fc7b8d 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3666,26 +3666,14 @@ void si_swapinfo(struct sysinfo *val) > * - swap-cache reference is requested but the entry is not used. -> ENOENT > * - swap-mapped reference requested but needs continued swap count. -> ENOMEM > */ > -static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) > +static int swap_dup_entries(struct swap_info_struct *si, > + struct swap_cluster_info *ci, > + unsigned long offset, > + unsigned char usage, int nr) > { > - struct swap_info_struct *si; > - struct swap_cluster_info *ci; > - unsigned long offset; > - unsigned char count; > - unsigned char has_cache; > - int err, i; > - > - si = swap_entry_to_info(entry); > - if (WARN_ON_ONCE(!si)) { > - pr_err("%s%08lx\n", Bad_file, entry.val); > - return -EINVAL; > - } > - > - offset = swp_offset(entry); > - VM_WARN_ON(nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER); > - ci = swap_cluster_lock(si, offset); > + int i; > + unsigned char count, has_cache; > > - err = 0; > for (i = 0; i < nr; i++) { > count = si->swap_map[offset + i]; > > @@ -3693,25 +3681,20 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) > * Allocator never allocates bad slots, and readahead is guarded > * by swap_entry_swapped. > */ > - if (WARN_ON(swap_count(count) == SWAP_MAP_BAD)) { > - err = -ENOENT; > - goto unlock_out; > - } > + if (WARN_ON(swap_count(count) == SWAP_MAP_BAD)) > + return -ENOENT; > > has_cache = count & SWAP_HAS_CACHE; > count &= ~SWAP_HAS_CACHE; > > if (!count && !has_cache) { > - err = -ENOENT; > + return -ENOENT; > } else if (usage == SWAP_HAS_CACHE) { > if (has_cache) > - err = -EEXIST; > + return -EEXIST; > } else if ((count & ~COUNT_CONTINUED) > SWAP_MAP_MAX) { > - err = -EINVAL; > + return -EINVAL; > } > - > - if (err) > - goto unlock_out; > } > > for (i = 0; i < nr; i++) { > @@ -3730,14 +3713,31 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) > * Don't need to rollback changes, because if > * usage == 1, there must be nr == 1. > */ > - err = -ENOMEM; > - goto unlock_out; > + return -ENOMEM; > } > > WRITE_ONCE(si->swap_map[offset + i], count | has_cache); > } > > -unlock_out: > + return 0; > +} > + > +static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) > +{ > + int err; > + struct swap_info_struct *si; > + struct swap_cluster_info *ci; > + unsigned long offset = swp_offset(entry); > + > + si = swap_entry_to_info(entry); > + if (WARN_ON_ONCE(!si)) { > + pr_err("%s%08lx\n", Bad_file, entry.val); > + return -EINVAL; > + } > + > + VM_WARN_ON(nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER); > + ci = swap_cluster_lock(si, offset); > + err = swap_dup_entries(si, ci, offset, usage, nr); > swap_cluster_unlock(ci); > return err; > } > > -- > 2.52.0 >