From patchwork Mon Jan 13 17:57:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13937868 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 B60F7C02180 for ; Mon, 13 Jan 2025 18:00:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A8756B0096; Mon, 13 Jan 2025 13:00:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 459A26B0098; Mon, 13 Jan 2025 13:00:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25D246B0099; Mon, 13 Jan 2025 13:00:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F27FF6B0096 for ; Mon, 13 Jan 2025 13:00:01 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A1D9E1401B5 for ; Mon, 13 Jan 2025 18:00:01 +0000 (UTC) X-FDA: 83003192202.01.8250E75 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf24.hostedemail.com (Postfix) with ESMTP id ADC22180003 for ; Mon, 13 Jan 2025 17:59:59 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RPu9rjWC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736791199; a=rsa-sha256; cv=none; b=EwZ26lM0MMMr2RTdXUOw70m/r+H4CVp16BsLteCv1GDA+OFoWzmAOSUF1mEMugTsOr8xnV J7T/wisa788bBgdoTSoc78oH7WBew3lqnf0xc8tovfCZw0xkcpPt/mcgesMoUpDFAe5Pv1 YQLS5aJDHZqJV/vIobspoH0wAJuivJ4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RPu9rjWC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.175 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=1736791199; 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=KIPMfjkfQ89B1WDwc6Z1AsnxOVIeae7YspqiuRkp0ic=; b=tIow03QgMS0IKQvLs34mbmO9ZvhesO6Fy2l719yUx7bXkXq7a4vHnEevUcjSxw8KZRI/hf hZQzL4peVkvF4uQ2hU6Pydz7OdOISwTWyfcdI/qnqiRPskSLULRzMyt1JigFqW7cHIqUKC rDcjz0v2QgcaeGvmLr/rl2VBNd4p+W4= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2161eb95317so80694735ad.1 for ; Mon, 13 Jan 2025 09:59:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736791197; x=1737395997; 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=KIPMfjkfQ89B1WDwc6Z1AsnxOVIeae7YspqiuRkp0ic=; b=RPu9rjWCuTx314LPqUFOFMcEm9vrzmSLfYeWyE09S0tHwo03Bsr+YH0LzQQCkff415 7bTyFaCNY5+2Vmg1ZmVDFnZgMgPR8YQJk/arGyE5MeqeeFN2VyY+xnrYJIVWc5JFZ1Q0 mpJDORVMTub60MXttmnFBn667oyHYMXSQfzP6JVqNaz3c4xSglC1DFoq11gTgCtXV3Ni +G5G30vgjUdKYjkyYob27fGWjJGWlMqD2yiXjI/4tn9/eoAA6pDVtr7J7r/pmSyI3v7M s1p/tTEHcwcWxv0vTa1Uz20K1UwJElJ7oXxUI+6I+7LS1N6JFOkLv7+aMRvO5A07k1JX avvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736791197; x=1737395997; 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=KIPMfjkfQ89B1WDwc6Z1AsnxOVIeae7YspqiuRkp0ic=; b=ru2dpe0MnscFQ2c+7mRww0cgFpu2w7qvRhtMD8BBLW5S2uE5l5rJyqXPy4RLKevTur qNXVDZv3XjWCWyPRvMCN8tc43CbdgRCdO+DPGBW/O7610kCkEMoKTDNjTqkOiz2mDnYf CyXQdeDGBBzC5bjuDYwzh/5sfhn/ctsxNnK1n6QKKnw98m8VqG71Dq/epQ0QJbUn4AwN 921WBlpktIkMTzsa7i0BhZSt3xdlLtgJTfRlK/MeMHrmtPX9JY3J7KIBFR+xqYnAmydO 3cnIzjfCXCPQf+QgL/5AAT/IYkgcWPp8kOUTKjv0f10nj+oUH+cHxPyx9Qec0+RU44Iq vJ1Q== X-Gm-Message-State: AOJu0YxTaWYvXUrmiFw8yHJ8e7+F7/8105tQxpAacUGHy94vh7chpluy 3vMZiKE5TCG3WGBT8iFL1qggqAtfC8WEbnQsQpcGfyfCJk6PgpgDSA0Zhg1RHVk= X-Gm-Gg: ASbGncuVDz2qurp2r7dGmqeaxAme/eYAgkfngQr4UhauDmx9//CG1BdEDDlFYwQsOqt OQIXm6FJyCi9hzVh+1v7mDS9GeJRPRzMZD2bPvNOtZEFLEVOc/nGIWkkXvoXo5ZEdE147K+g1Ye 7iXLUS3tpUELWD1roin3SbSIPHS3Uqxrx+9WTkt8Rh92+SYSNv1VhFVHt8HQFsR/IphS+l8pKFv XIHxZiKiNhQzXzMYdJYu7PXzmwUm7dRWynRsu7Zjsv2W9csh+GsrG5f4AuVXAEnvPuLF76Do0Za Yg== X-Google-Smtp-Source: AGHT+IEnHU1K7n4HvnC+iaw48qp8W3x2ZslOxNgGfCpcaDHl0MYIhads/GivBX4OKMlfg5wSZ5/7JQ== X-Received: by 2002:a17:902:e808:b0:215:b75f:a18d with SMTP id d9443c01a7336-21a83f36d9emr335932635ad.11.1736791197432; Mon, 13 Jan 2025 09:59:57 -0800 (PST) Received: from KASONG-MC4.tencent.com ([115.171.41.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f21aba7sm57023635ad.113.2025.01.13.09.59.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 09:59:57 -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" , Baoquan He , Nhat Pham , Johannes Weiner , Kalesh Singh , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v4 02/13] mm, swap: fold swap_info_get_cont in the only caller Date: Tue, 14 Jan 2025 01:57:21 +0800 Message-ID: <20250113175732.48099-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113175732.48099-1-ryncsn@gmail.com> References: <20250113175732.48099-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Stat-Signature: ge6fyp3aihh7prkzg7ms4gmbcqkcyiey X-Rspam-User: X-Rspamd-Queue-Id: ADC22180003 X-Rspamd-Server: rspam08 X-HE-Tag: 1736791199-480009 X-HE-Meta: U2FsdGVkX1+zrEnc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sjqWpd/CSm65QDzgz4qJb6fMp8YrAUGTCz0ilN63u6fkhS28tJUEbfj6gfFf5ypOESRm63m/ac6fF6NKjCB0FiEKPThciSYf8MUemVRWMxqEPZ/La6NVDMSmNi2+0gAv+D2X+O525/BDN+DIYbbORsokEqfY9p9IEfpMlM4tgQqcBlnyu/iGlwQa7ugOCgU9Qx+TBkEl9Ty4bL4t0govNH5Qz32LiEfvpXL0ajzzhU20B79J1D9yZX7JjAR+3Ar1qiTMow/dpB05i13qly3/zIW1vF2iiw2Yvh4moOmUVkw/b4R4nhgsUQerZHO6PovMx0pOVp5B+FXlWDPgClkkD/rZ+aaG8Lz2FoDb0lBNF3jvz+VYQbMdrN5yk1ohgGlk0lBE8QrQJUK+w5ay1FI/YjtBnIyyoD+GCDzJugCAZ0d2+2nVcTCV4F2sEtvC+yuDbQUG+LfOGAjB2tSap60Et+tj4kyXf6u7cbWld4jWzEldOjI6KJUx1NwO9b1bvGg== 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 Reviewed-by: Baoquan He --- 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)