From patchwork Tue Oct 22 19:24:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13846076 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 E9F17CDD0D7 for ; Tue, 22 Oct 2024 19:29:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DC966B0085; Tue, 22 Oct 2024 15:29:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 766366B008A; Tue, 22 Oct 2024 15:29:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C2656B0085; Tue, 22 Oct 2024 15:29:55 -0400 (EDT) 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 35A246B0085 for ; Tue, 22 Oct 2024 15:29:55 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A25C1A0472 for ; Tue, 22 Oct 2024 19:29:24 +0000 (UTC) X-FDA: 82702227930.15.FE4DA58 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf12.hostedemail.com (Postfix) with ESMTP id 91E0040010 for ; Tue, 22 Oct 2024 19:29:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VxaEIkFm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729625226; 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=0kiDuJ4tEKZSj0qaWySVrFhdnZUjCFe9iUFsOZ0gkhE=; b=dgfdahi/A3bP/5FIk4VvciM83vk2KobHse2s4cRcmzMWic1E1G/tCHeLnVMW2ctonOWzce SJ+DSTgLry1jVKAZiZBCZvWA/rkTmRMtrs3jB3EPxcL95aj+AikmDBXG59I3OWmmw6P+j1 dG47cHBPshSjHTJ901rQPmArjy0+r8A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729625226; a=rsa-sha256; cv=none; b=RpSVvjtwu6sbIuRGFseqbiHYHCqgzeESSVCH4Qy7KluS6ch6jvogswPSP4/jUONK3+liG2 eEP2HpPoPi84SK1byytXN7OUpz11+5TD7M4ezNEr/LPubXFmVwOCKNQWqYC9tJpaWJV3y4 XVXe69AtSFdSxBEfhS13FOsOFdNE3ZU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VxaEIkFm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=ryncsn@gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-20cb47387ceso54187815ad.1 for ; Tue, 22 Oct 2024 12:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729625391; x=1730230191; 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=0kiDuJ4tEKZSj0qaWySVrFhdnZUjCFe9iUFsOZ0gkhE=; b=VxaEIkFmzek84zeF6gG7r9NvenYP5ZIzu9jcMkZ68d9CCxyL1gVBdLxk7hi+x40mI3 gSzXvSs5jAiy6/x0+62/2OIX+9PtEOB69P3jFwQWX7+CSGNIS4OeNBvbX+1V2fyxrAfL KpPqxg7tNW/Gywfw0VeBQsQdkiJYjnnJ/rX6BR6vuaOB85+EgxdjVxQVph27pxpPREwG fLWK2a4zhEmJp6Jc4VLCh8kpiGq3kavXkVtYrI7R7OJ7yRiQ2eSrrFpNaoY1AuuvzgEj B6nrsqwXnq39bollsJcRbnr2+4Clh9p3bPmLjNztJu7GMgGq7hVUrRY2aRLVKps/hW/S KQ5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729625391; x=1730230191; 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=0kiDuJ4tEKZSj0qaWySVrFhdnZUjCFe9iUFsOZ0gkhE=; b=rzhtxE0kE47jnPkZ8+J8+0cQtqI7yxTAkpuyxySGalmRjM/GNGCfwgtOAfoLRqUD9t o39tHRTj05D4KKT1RzPNTHYpLhWLfCn0MOq7AIjA2RuBWmeNkgoEQJ2Zxy8c67jNVzWs VUhuHbE6McLKNsgopbukmI9nmn09NVSMDrAgCvrcDlW3n9PZ0I5pDRW4djKgofqOoOx0 eGKVrPW/8GEJ1uE77kE+kvCU94+6bjPH/SQ+UN1DI4Zcy4k+WariKGvEiZEdon8FvtxY 3b77KlkiA25dqxJfmNkw7AjpAFSTCBDejrUaW2f5DUGaLuPlYJ/GXP4Y+eh0cJDEgZCf 11gA== X-Gm-Message-State: AOJu0YzRZNR7AbpLkymrl2eXciS716ts4DzGHWABZjH9C/VMJwCskTrw Z+bEJNtv+TptLXS3cj03Mw9vOZRpLhl7/Jc0qV+caofwQfe5X8MgMFB0JV0wTCE= X-Google-Smtp-Source: AGHT+IHJ/mmbPeQO7m1JzLu61hvPRuxTG4vZV7GSls5xo1lWKGBwkK8GicKhDQOEb/5V/S1g/+bTNg== X-Received: by 2002:a17:902:db06:b0:20b:c1e4:2d5d with SMTP id d9443c01a7336-20fa9e72980mr2645385ad.34.1729625390976; Tue, 22 Oct 2024 12:29:50 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([106.37.123.36]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0d9f05sm45895305ad.186.2024.10.22.12.29.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Oct 2024 12:29:50 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , Barry Song , Ryan Roberts , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Tim Chen , Nhat Pham , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 02/13] mm, swap: fold swap_info_get_cont in the only caller Date: Wed, 23 Oct 2024 03:24:40 +0800 Message-ID: <20241022192451.38138-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241022192451.38138-1-ryncsn@gmail.com> References: <20241022192451.38138-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 91E0040010 X-Stat-Signature: 9kxdqomdpxhygxoj4m19911h1pc7kniy X-Rspam-User: X-HE-Tag: 1729625385-104033 X-HE-Meta: U2FsdGVkX1+q46usB763XYKu6qiyrZUx4YVTAQFMBur9LPS/PM7iWVF+5bicCP5bKvODEiRUB0xh2audDjvHLFcCWu6WEr5A/XUuF3LcIdtzu5vTFz+Cfeoya+2iCa2Bn7fTwTLetuIkmP10TqfDRnO/5lRhXdmuB9u00sVfrkRyY08V6nMbqaZMfJ6xoHBVHlCuso3LgP5WowsTVlc1eLF+GXpE6UtMa7SS5vxStUmeh0LCDvWEJvhodIMIaH6RFpmDfF2KuR46M5SReJBIfrdKintrrrEaDLY/AnTLuZTIaFLj+ruukJ4i0GcBmmrVoRRnEd1MOJAIQ9Qs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Cp1Q3wrxiVvr6CI6413k7K9MZRukqMYeygwDlySzaT+PHHg1ggQKK2pkg64ArOeYov0pNmwG5UIFE/PgAl050ia8ff32UhHWj4IQGQe/LOc8iXIKoVAAo7eTKa2en8RNm35nGD8cyU0NaHTIq3bBdOI9c0OHxbUISeb 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: 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 1128cea95c47..e1e4a1ba4fc5 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1359,22 +1359,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) @@ -1671,14 +1655,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. @@ -1688,13 +1672,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)