From patchwork Tue Dec 24 14:38:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13920190 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 958E3E77188 for ; Tue, 24 Dec 2024 14:39:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25F396B0089; Tue, 24 Dec 2024 09:39:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E8156B008A; Tue, 24 Dec 2024 09:39:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 061286B008C; Tue, 24 Dec 2024 09:39:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DC0196B0089 for ; Tue, 24 Dec 2024 09:39:40 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8FB7A802BC for ; Tue, 24 Dec 2024 14:39:40 +0000 (UTC) X-FDA: 82930110480.18.1DFB87F Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf03.hostedemail.com (Postfix) with ESMTP id D73F820002 for ; Tue, 24 Dec 2024 14:39:20 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SadAv3hW; spf=pass (imf03.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735051160; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rZtcJl9C6ncR1PQN3HhaQn7BWhIvEYupFW/4U59A+e4=; b=ExKCcArlNUMY/HizBVzCfYgNJ4JSsmkbSmv4caDUJO91UhEJb39F+kesC4nZamwAAzTvhG nYHgghxYQi8yFMLoKzPkTKUuEgj/FuLpg0CLdEc0T9iJOSDCQaG3HuD5GPgsES5LD7hxeK pyN7jl2l7kTWpaeCuhawTIejf5Fh0+c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735051160; a=rsa-sha256; cv=none; b=C/KWOJB1apTqsAGirmR7CUVORR0cZjmLlH8v3h58+OnArEl4wqzKdFbMkZIyOtN0SQ1COm WwyqyehcPmixO0WX8iBNmOCWuhfZFBLZSWbobZxJU6Q6riOUpLb2UfQFDz/3hiSuo81YHu btpF4TtPPSLAEvODHp1HhPXE1K5Ao3M= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SadAv3hW; spf=pass (imf03.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2163bd70069so52463955ad.0 for ; Tue, 24 Dec 2024 06:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735051176; x=1735655976; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=rZtcJl9C6ncR1PQN3HhaQn7BWhIvEYupFW/4U59A+e4=; b=SadAv3hWhf7NNVQkrcx6o7NQ5GQHphOVoYVDKfwj86dBbTRiXmlSSshzrbd0SDj21K OxS4EnGwBIddyZpHV2xuZy86K1AyS7+klFu4PLUhWbsmPNsonTiOquixEBIvpEP+dpLM 9Q+6E7lSe4/Km+pzIqquB85DOGja99/xrAmKnZWI0+lN/zleS/Knu5VhE70nZDjSlmED 6OFClF4s210o05c/B/JyXeuEiVrxgNg+kCrFBoq5Ge9uPu9SWD9tbvYqU6GX2aFeVIks DPEvkztx4T1n27tWLQo5v41uRPREJYKpD1rAWNiVPSxHn0YrxDZhzbIrq1RjppprDFqC 8lHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735051176; x=1735655976; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rZtcJl9C6ncR1PQN3HhaQn7BWhIvEYupFW/4U59A+e4=; b=xCKgCbiZdmM116bfNEFk0J60Ry2l5Qb9J9OU8DgQCK9CD+ldGxxu8ZHFZC1ajv1Bta 9p8wIbKJXN5usaHx5A8aVyBjS5hW0yOUZS5IXAFke8jNFRDrsTADBIiEImbGlAWt4yLk itiIpi2Q4KHnaF7EEX44PINahMBo6T3z/7oP8x6ZFo9yhpWbVULqM/vKD3un0LOjSCzF uy2wKQ2fIfwr7raTQmJUOLYacbnGkya/Mk9HkRUcccf9iu1MNiwvd5bwhkQbBgY8CGp/ ScppqlT1vdA8sh7KMJ61j8Brkcs/05kbD5supSmJ/jXXwGXTsN08/G5mbXfhUX+dX1aT S+UA== X-Gm-Message-State: AOJu0Yya3/tfa0j1PsuSQlEXak/OfyCAtPxkYFkWK9PDK8glxqRtk4YX LMw6I88r8+CT5ICPEwUqfk4vCG/mKXYa1BnRwpTXEUw/BFEhquyf9ppc5z6dg90= X-Gm-Gg: ASbGncuGUxogtg7ISPlxW2KJcruYaqkT8E6818lLnx0RllWWEM7vX1yZHrvErAWjB/d n4jBuPh3B+N6n8m5iFJShFHgw3JgjGCL8dRYPzVttswVvxzgK0s1V7AeHyKtLDWVtq7PC7c6qGP 9e7XYUQZEPzGZW+r1Umg2jR+CZmbCZQdjGH5hxcIOlkhbJA1P/8+3YIPnHViTKoy6In+A73MOxN 4+z6uiiI2HsqpM6aLnQ9734xcrsaBLBVjSTfgefL8p2HoYOcMdzz2IUN2/cxLpTwyv+wA+8iKVo gQ== X-Google-Smtp-Source: AGHT+IEkDx4n/weETtq0G9ZPhvCOgy2IrUiCp+3qPSdSRiNgKT1LkatuidUbaG44s3+jtvqlnVPqTA== X-Received: by 2002:a17:902:d4c4:b0:211:ce91:63ea with SMTP id d9443c01a7336-219e6ea1accmr181270775ad.15.1735051176547; Tue, 24 Dec 2024 06:39:36 -0800 (PST) Received: from KASONG-MC4.tencent.com ([115.171.41.189]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9cdec1sm90598735ad.136.2024.12.24.06.39.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Dec 2024 06:39:36 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: 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, Kairui Song Subject: [PATCH v2 02/13] mm, swap: fold swap_info_get_cont in the only caller Date: Tue, 24 Dec 2024 22:38:00 +0800 Message-ID: <20241224143811.33462-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241224143811.33462-1-ryncsn@gmail.com> References: <20241224143811.33462-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D73F820002 X-Stat-Signature: tnftw8x7dbsar8ymnf6b9f3ji7aehe6w X-Rspam-User: X-HE-Tag: 1735051160-154159 X-HE-Meta: U2FsdGVkX1+iEUXbDyadfyUj+SDePQtcuNaupZIIAAMaJ6WLFBPk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ba3QM8DiGwxTD9FwPGohTtNdewuj4eu5V9qjoaWLuG8MP55/oOKiCBUvaDyUqJrrKCEFXJ6G5idMim9HIzYg3zAA3Zyv2rC28pgtv+k0VhGUjbpD8b+X7JOEL8O59p9yF1z1Dc5CaQSYsVoiTk+WPeiFVr+KTugKZNaZ4ck9vD1SzEnElGKxA6qS4eiywNZm60SZXraH4TW8iu0L4lxh1YapkZpZWiUb2ehpNU4msYmBPNdk1xlCzVtffMYweIO9E23x2EHCa8ufDECsqCQpanS1FgXEecC5WnaxFr8AmMNgj9rbbHzCH3c1c+EkGZ6f8GmbQTL54CmeED2yyaFtt3ZvjgxF5g5GTgFlO+JVlVqWKU/wxPSrMdmGSXN/TU/S4Y0Ilcdw1l4Y2HDrxQtMngcSS7qpURoJBW4dgqr5lilWUdUEi3h X-Bogosity: Ham, tests=bogofilter, spamicity=0.022054, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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(-) 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)