From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A5E5E77197 for ; Thu, 9 Jan 2025 04:05:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2FC56B009D; Wed, 8 Jan 2025 23:05:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE0166B00A7; Wed, 8 Jan 2025 23:05:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B808D6B00A8; Wed, 8 Jan 2025 23:05:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 969956B009D for ; Wed, 8 Jan 2025 23:05:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 42C6A161603 for ; Thu, 9 Jan 2025 04:05:46 +0000 (UTC) X-FDA: 82986574692.27.B049F32 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 6A331A000F for ; Thu, 9 Jan 2025 04:05:44 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GZg4iYUK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736395544; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=K/Xk8laE8PpP2ahKG8re5OmfDcasIBvAKT0qr+dX/8k=; b=HyqbidHrHGplKsL3q1Z+mFVWF59KaRWFEMaRphZy871hNOsrRIwws4JlqWBUDM/kyNH6xS PECVOX75B/sWWx9NPMqqMwiF/I2GWUdawCORbukjIRW8mNFDOi8iNut78To2WII4mEEXf1 R9gbjR5VjHaCi/Ns02Ji+ZYFAVFhdrQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736395544; a=rsa-sha256; cv=none; b=YYcNHdhiVX4YQH1Fahd0e5GjQNgcITqDk5FF9Gz4BjZAxvf5bdRChfODOk9B2CaYPUhzpe U3Irz/gVWYL6wuixsdpmoE5Uu72ZYFct+evzPyuwofhk3QpqbhfDGKuokaM/zuhi5aNjI5 sKTFMzUbs8thjeDfcHyxV4VWjvyyJvo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GZg4iYUK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736395543; 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=GZg4iYUKuxc9iTQxiVnzodF5ywsTyockY6u/Ohj4gwHmQA6/WbKaBc8i4ECu1sdC7/upv9 Ry1R9YBenHlb1RFzRMoFiaHL20N5PzTmY9FPDsFXjfR0Ji92bWgxd2e1KM6MjaauGKKvSj AvjZwUVIM9MrNVc5SxbCc0tmdY6pGwQ= 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> 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 X-Stat-Signature: up9j9u79wek6p38e7qh5jpfjx7zhtre7 X-Rspamd-Queue-Id: 6A331A000F X-Rspam-User: X-Rspamd-Server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F1wEbyW8yPgDI9n+R1M7F4xSyEOyiLro+97r+bq9hSaCwEAgXiRhWVV6gfF3MJSpcqOjP2XBcGqqZYDJFYEDEnUkB2GgqwuR9XNFSMlXFGexkVcEqKm0xSFRWFG6+E3h6zAfuBROYFZvYH3hN8cl7fRWWQT1lg5fCNwJ+/AquyEW9EIxPpDiHDo5qUzFUfV3DlXZ0H1O+3vF8pcnnnQAqq+jT58QSt8I5+tnHjKRk48jJrgMih8qwqNFf3PkgkUc4c1oNLjUke+jabKDQgle4V31lbjOFSK51EM08UPWXwA9woPgNXVZ+71nqB21TiOuUpY+a7ZOh9IMRfhAI5bUx94K5x5c1gtVG+XCQfnX0t1ACJdPqYyrwvru9N+F8cl+OMxh5dR5jhuLkHCJbcq/sZO X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 > >