From nobody Sun Feb 8 20:52:15 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 EA4F91DDC02 for ; Tue, 24 Dec 2024 14:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735051218; cv=none; b=jBaPpSGAtkgYVkC9R1SVdzoiO+vA9V55K+YYReTxSxiWgayCFNDd22nWU40Z26UOzk1cJAh5HM2zHKAnN6/S6Bjs0UUyaxIqUyEPrcuMVge20/MYk3BWt4CfbZOwUYeMXHqu6N2mrD42mkat9SEdT/LBNON0GW3f60noQMIxnVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735051218; c=relaxed/simple; bh=q+ZBnuXjSMW/VMrrlhQcdfffqJIgLNXBnSJjonGwDWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A5FrFN0omzvHbFrLOEerlQu8i+RlbvpAb5P5pm8118lXzf22tPH3wSHfxeQwKxRehivF8sx7Llon3baizFVvZ8QHgFEw+cuDo8fcGMoVdlpZCgry1bzkgyg2POSbbhZxqDEKo3vJHjT+dNpvx1CYJleqWMBra9u5LZsDfk5HY3I= 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=e9Lwti8E; arc=none smtp.client-ip=209.85.214.175 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="e9Lwti8E" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21683192bf9so58668165ad.3 for ; Tue, 24 Dec 2024 06:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735051215; x=1735656015; 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=Bzlbcu02fLqLzv6kaO1DSu6E6WlQUI1ISyd8RxZxJr8=; b=e9Lwti8EP8jb1NnPQueO6Kk8YNXhV6NktRErYjAzqACdanvCJzwoQgt0z6Zi0yeref KUAYptCvXXhxKlQp6QpRU9oglK9sTAQE5pyIYgCh1gFKI/AYYn0WYJG98f79IJDtnmZ5 BAtmqU9VO9TAF5QjEMfXipyTjw9QXkRIp2ZuebaPzjM0/AR8o6Cp+Ul+s81WDK5lbYIH mGKy4hpQK5vw1ytLq//Lk7iNjwzKU9uOmjTkgDRtIFquLFw8VwhDYQtJSnpIwOay99Hc tkVO6eCt/npMXvoWPGU0cnAPMcCZk9mIPNwjxY9ryHFbBWxK3xANeof046zUtLZr9rcX VorA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735051215; x=1735656015; 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=Bzlbcu02fLqLzv6kaO1DSu6E6WlQUI1ISyd8RxZxJr8=; b=qB5XQyGffHIc5f2a2PrvFyyVuLDJTHo2ufq3p0cq2Xy/d8TDSgtFcfKhyFT9MDzQ9G 3VP+aZLw1xiQFgtzueO4x5t2XE2YU01SoYfdQPDp9f6Bhopp5eTQE+uCfCjN0hhs+/Dl KRO2y6vNRacmNBCY2o8ZrEbMjAvWBd50N7NpdgiSNXJTSD0ERG7D9Rbd0jhHQkBcvQ+3 EIIkNq2eGW+vNmo9wKoh1f4POq8MsWFWSLfjoKG8QUIRhJY1MaiWkYXZ4pHfF56crxMe UQGjmP0VaYlBx9RUeK00kJu4zOc+xhhefjLo7LSd7YgY2sSJVvpwCxmlZTZ9FxP0Ny5K 5/YA== X-Forwarded-Encrypted: i=1; AJvYcCW1JzStL8gQn/FKyGXQ8be55bfqF0SLjdAjZ3Qtnt06Y/IaYDi/oNy9XQFgjS8F7e5udT49RYoEUnvja4w=@vger.kernel.org X-Gm-Message-State: AOJu0YznhxlxsXY5oxTdq+p/wze3fUfvbkjtEGTcNPeAq+QaDhWMc4Y/ x8SC6kwVNrWh84AWYpbVNJxgThr5ghsBlLWHLunD1Vlo5jKrhL9FvRJAApxXJSM= X-Gm-Gg: ASbGnctZz57Erzcg520NkqDLx9DEtZuwOAC4j/ssw0VB0b4dp/PUIQLXlhXqf++KkiL x/6E5oxptw/f6eJgdyuL91yqzOXfeirCO+mBTt1NCc3AGIpWCN6rAdWaRU6ol4SUw10I3W1Nj8T WUY7u0MRp0szfCb2oSPAr3HsgWLU5QhWweE/t2BZh6m7DPCT/mz3S7rVUGWTq6v3DfKyPgLGJVU 4frj58Y519dQKVe/I4ajzwbreTPRJtZrUIQA4GNUFIVtg4Sh/80PpmSgRETqe8tLycp7wCwvdPg oQ== X-Google-Smtp-Source: AGHT+IHfsTNBsjv0bUq65kgG9hxJHF1KnAgYhU8hlG8rshYiEPh2IPMtkj25JK/GiuQVbqe7HXA/wQ== X-Received: by 2002:a17:902:f70f:b0:211:8404:a957 with SMTP id d9443c01a7336-219e70c01a2mr271220915ad.41.1735051215184; Tue, 24 Dec 2024 06:40:15 -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.40.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Dec 2024 06:40:14 -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 11/13] mm, swap: introduce a helper for retrieving cluster from offset Date: Tue, 24 Dec 2024 22:38:09 +0800 Message-ID: <20241224143811.33462-12-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 It's a common operation to retrieve the cluster info from offset, introduce a helper for this. Suggested-by: Chris Li Signed-off-by: Kairui Song --- mm/swapfile.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index ac170acf55a7..0445a2db8492 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -424,6 +424,12 @@ static inline unsigned int cluster_index(struct swap_i= nfo_struct *si, return ci - si->cluster_info; } =20 +static inline struct swap_cluster_info *offset_to_cluster(struct swap_info= _struct *si, + unsigned long offset) +{ + return &si->cluster_info[offset / SWAPFILE_CLUSTER]; +} + static inline unsigned int cluster_offset(struct swap_info_struct *si, struct swap_cluster_info *ci) { @@ -435,7 +441,7 @@ static inline struct swap_cluster_info *lock_cluster(st= ruct swap_info_struct *si { struct swap_cluster_info *ci; =20 - ci =3D &si->cluster_info[offset / SWAPFILE_CLUSTER]; + ci =3D offset_to_cluster(si, offset); spin_lock(&ci->lock); =20 return ci; @@ -1473,10 +1479,10 @@ static void swap_entry_range_free(struct swap_info_= struct *si, swp_entry_t entry unsigned char *map_end =3D map + nr_pages; struct swap_cluster_info *ci; =20 - /* It should never free entries across different clusters */ - VM_BUG_ON((offset / SWAPFILE_CLUSTER) !=3D ((offset + nr_pages - 1) / SWA= PFILE_CLUSTER)); - ci =3D lock_cluster(si, offset); + + /* It should never free entries across different clusters */ + VM_BUG_ON(ci !=3D offset_to_cluster(si, offset + nr_pages - 1)); VM_BUG_ON(cluster_is_free(ci)); VM_BUG_ON(ci->count < nr_pages); =20 --=20 2.47.1