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.129.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 CD224748D for ; Thu, 9 Jan 2025 04:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395547; cv=none; b=ioLCRhzRK/67Fyk4uZjGEfi/urvSuHX0iiwmOZfDsBZprh4ZaYkWII1RZPQ09sajP6LSUQFhYaPuJukZTJQWJ7BOT3v5gMygh8enk+cPvAYVeVJ7bJ5XzFG+BYP1j7V6ylDTu9M2tcnSwqk9Ao/rYOSON2BJHMaL0K2Ufz9gXsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395547; c=relaxed/simple; bh=w+bVTWItmxSJlF1kXCrMwAgO/te/FKuSis8eKYIDOJo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j6TFR8JtcBly8TJPMb2igRvvGZkOsJSL7sUAb7qsW06aZ0iPrS7iJ+fBQGBaYwhOInO+mB99+I+nH9QMzCDnywqoDiw0bFAw8ytlInZILqOYDpkS1t1rNuawVx4W/MBybd6QUYM/6NrZu7i1F7jHwCHfIJ/meYUW3YZ2GYM2Gz4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=igOKKAXe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="igOKKAXe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736395544; 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=K/Xk8laE8PpP2ahKG8re5OmfDcasIBvAKT0qr+dX/8k=; b=igOKKAXexj64P+k+lJfpCd1FVubd8kfUDnIBwCCUr3cozBpiJWWUInD/o50XyDDNFBEAVH spDU8RsW5Ax4wfrQMj6H95WcQE0VUnyyS1aSW1iLDzvr+dnu+CT26vBYDQFPAPSryI8mbG hlNVl7RAzjNnL45zyPhE+bsRy74xK/g= Received: from mx-prod-mc-04.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-621-qOJQNfmWOe2Ymqfqrk1UPg-1; Wed, 08 Jan 2025 23:05:40 -0500 X-MC-Unique: qOJQNfmWOe2Ymqfqrk1UPg-1 X-Mimecast-MFC-AGG-ID: qOJQNfmWOe2Ymqfqrk1UPg Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ABCC61944CEE; Thu, 9 Jan 2025 04:05:37 +0000 (UTC) Received: from localhost (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DD10E19560AB; Thu, 9 Jan 2025 04:05:35 +0000 (UTC) Date: Thu, 9 Jan 2025 12:05:30 +0800 From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , Chris Li , Barry Song , Ryan Roberts , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Nhat Pham , Johannes Weiner , Kalesh Singh , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 02/13] mm, swap: fold swap_info_get_cont in the only caller Message-ID: References: <20241230174621.61185-1-ryncsn@gmail.com> <20241230174621.61185-3-ryncsn@gmail.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: <20241230174621.61185-3-ryncsn@gmail.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 12/31/24 at 01:46am, Kairui Song wrote: > From: Kairui Song > > The name of the function is confusing, and the code is much easier to > follow after folding, also rename the confusing naming "p" to more > meaningful "si". > > Signed-off-by: Kairui Song > --- > mm/swapfile.c | 39 +++++++++++++++------------------------ > 1 file changed, 15 insertions(+), 24 deletions(-) Reviewed-by: Baoquan He > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index f8002f110104..574059158627 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1375,22 +1375,6 @@ static struct swap_info_struct *_swap_info_get(swp_entry_t entry) > return NULL; > } > > -static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry, > - struct swap_info_struct *q) > -{ > - struct swap_info_struct *p; > - > - p = _swap_info_get(entry); > - > - if (p != q) { > - if (q != NULL) > - spin_unlock(&q->lock); > - if (p != NULL) > - spin_lock(&p->lock); > - } > - return p; > -} > - > static unsigned char __swap_entry_free_locked(struct swap_info_struct *si, > unsigned long offset, > unsigned char usage) > @@ -1687,14 +1671,14 @@ static int swp_entry_cmp(const void *ent1, const void *ent2) > > void swapcache_free_entries(swp_entry_t *entries, int n) > { > - struct swap_info_struct *p, *prev; > + struct swap_info_struct *si, *prev; > int i; > > if (n <= 0) > return; > > prev = NULL; > - p = NULL; > + si = NULL; > > /* > * Sort swap entries by swap device, so each lock is only taken once. > @@ -1704,13 +1688,20 @@ void swapcache_free_entries(swp_entry_t *entries, int n) > if (nr_swapfiles > 1) > sort(entries, n, sizeof(entries[0]), swp_entry_cmp, NULL); > for (i = 0; i < n; ++i) { > - p = swap_info_get_cont(entries[i], prev); > - if (p) > - swap_entry_range_free(p, entries[i], 1); > - prev = p; > + si = _swap_info_get(entries[i]); > + > + if (si != prev) { > + if (prev != NULL) > + spin_unlock(&prev->lock); > + if (si != NULL) > + spin_lock(&si->lock); > + } > + if (si) > + swap_entry_range_free(si, entries[i], 1); > + prev = si; > } > - if (p) > - spin_unlock(&p->lock); > + if (si) > + spin_unlock(&si->lock); > } > > int __swap_count(swp_entry_t entry) > -- > 2.47.1 > >