From nobody Sun Feb 8 21:47:17 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E88E1D9329 for ; Tue, 24 Dec 2024 14:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735051178; cv=none; b=pirI69DKG+GPD88FUjQq4KRR9GS/6q/m9gD4oU1Qv84yF/QeJ5yz+/xeKfHTaKor7wPpVB/xc0fa9z0eGGwmc35o8Dk8AgCCkfxgT2DowSn/3XAzUkwuERIKcjXDST88RYtTdypMSAJv+QuCCovOaI8GWd1NrmqFZ7Txr1KTWLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735051178; c=relaxed/simple; bh=d2i28bIgwgBE/CLwLqgga3NoAc+ItA80i0MhwxzUBek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iInD71HnTRStSYwKTYMhPAzQ6O1ashjXpkqN3VpJv4wjNTzqG1V1OS79VhNr9j462WHKCGEeP1s8PfHn0I07xMF4Y9eYDBwFgbYeBNHBT3YxeAgEVjjU03Ju9u0LLnBAgm5AYudQItql7+XoeG6Opvq/PsAncbhPNDuMpqIQiKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D9h687YR; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D9h687YR" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21670dce0a7so69351625ad.1 for ; Tue, 24 Dec 2024 06:39:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735051176; x=1735655976; darn=vger.kernel.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=D9h687YRkv3ZoQZC7OWEvNlo9VyCZoBi3ac4tIK4CtLlgyza0ev1F2VHNO0+zM/gvQ iQYS0k9nNJIRa4cOUb/BBJYMCU0Gz9Qtrz0edAY7Fg9HAwBHP40QavP3kACpV9v/gwj7 NFKUfdJkbwN+aIpdR8iEQHIiKea/axhNHjoIVajH2s+0eKTHJV49+wgFCea3ZNkev4g2 m9mg4ugbnP42Jy6uWezmdy+Vg5XU/+3iQ0r8dUR+PNCYB39Y3qaZvXD+/xrbKV8qmHh6 xffRPZb5+a21zwOicOkk8uqVRAP+JZ6bdCIO4IPdhLzizotbMIaCKV/+VH/1/Jf/KOVi ozYQ== 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=me82zR+/b5b6yqG47znNmy9TLPICU8Mn5rWCLL3+vABakkJ3lTQlmKM1T15C2S3whK x6a4XIlck1GBnugdmW/teOwIcdo2n9rivi/rKGHkwhs9tbHFDNvonlxM/Jtr4i13bQPx IoFxx8MxEnSRFDWzbOhrOk0aleqB6F1Qzy7h9Bu74yIE0SwzeVraN+oBY8lreGV99ZoN MSMN9C38hOm+8gSvBJG9lGqv9hzlMZzo/1R09RWQOduShEg3WuEE4HBXXb1ocaBV1qsH z9nAeoguk0Fez6ZzSijPznEneAry3N6n3XXvSws3DJ+3oAk1/iU7VEQ/Y3mcaCybZuUC 9Gzw== X-Forwarded-Encrypted: i=1; AJvYcCUQ/y8PDeiLZTtQ0u5fDWeh9uD9FcO9lgWl8i8JMXKdL9skhnY9omYFSQ4F0dPL420eUNNBG8R44xYSjLQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxvJEaUR6j3oSPiv2NSHl7/JXSolkDqFPOIy64sYiQlX84V76xX Kw6C37+9OBucc8lol17DJshYgJte25s67vHQqUscUh++ILD+UN+g X-Gm-Gg: ASbGnctzwnHilznMmQAEjQdjLainMjI8+Ncg6yoIeATWHmavOMeEzD1x8GLJe5/J0bq D2HLD/Ixz++yF4G+GeLsP6rFzn1dlPHGQ9EuSJU+KEHQprtyxmTCYjDU7CkSmg82280v0c0rRp6 trFDmufBsoWQi/o8WkD0xfCvnqHTxxzvZTLWkcyvQTW/ba8/JuWhTahT7KDbVXeIOmAtN4Rg33d wzWIIormsRfIjuMHywH5zJLqncKYqJWQysvQZo6iBYMkQNBVAVaB0KPortKZQL9COzDEXd6o5Vy sA== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_e= ntry_t entry) return NULL; } =20 -static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry, - struct swap_info_struct *q) -{ - struct swap_info_struct *p; - - p =3D _swap_info_get(entry); - - if (p !=3D q) { - if (q !=3D NULL) - spin_unlock(&q->lock); - if (p !=3D 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 vo= id *ent2) =20 void swapcache_free_entries(swp_entry_t *entries, int n) { - struct swap_info_struct *p, *prev; + struct swap_info_struct *si, *prev; int i; =20 if (n <=3D 0) return; =20 prev =3D NULL; - p =3D NULL; + si =3D NULL; =20 /* * 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, i= nt n) if (nr_swapfiles > 1) sort(entries, n, sizeof(entries[0]), swp_entry_cmp, NULL); for (i =3D 0; i < n; ++i) { - p =3D swap_info_get_cont(entries[i], prev); - if (p) - swap_entry_range_free(p, entries[i], 1); - prev =3D p; + si =3D _swap_info_get(entries[i]); + + if (si !=3D prev) { + if (prev !=3D NULL) + spin_unlock(&prev->lock); + if (si !=3D NULL) + spin_lock(&si->lock); + } + if (si) + swap_entry_range_free(si, entries[i], 1); + prev =3D si; } - if (p) - spin_unlock(&p->lock); + if (si) + spin_unlock(&si->lock); } =20 int __swap_count(swp_entry_t entry) --=20 2.47.1