From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 AE0231B392C for ; Mon, 30 Dec 2024 17:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735580839; cv=none; b=rA8l8dREqALc1rmjcLWtnQI6Y11vUFDwPfMc1jLSpKSxMKh2haciqZlZhxB3SBgMCAGfQphEtb9RW6pbKiq/gm/nmd6Pad7WMO0v2vOAh9cgD02LfZK3yHa4eTmN4WPJCaDUG1OJZFRbacAqzl749jLdmaNz7XQTY0nrJeR7DfQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735580839; c=relaxed/simple; bh=FOUJp4yUs8STmIPXv9y0b49fl3yoP3ysTs/uvb/K80U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pKv+ZGMhJsRxDXqyB+7lbIOMpB9F8e3tSqF6Agr+KJaY6G2ZWU9vt2PEvA/wiC8bUPIAToK4wAdmEfnOgEvUdPUpZmSliq/9caEe3a1rXSofb0MuIdB6nuv1u+lv1/ZxpCpirTJcs+MHlH0t7Yfzem8hZP2pV+EveYRshLYwgQQ= 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=ZwOwnnF0; arc=none smtp.client-ip=209.85.214.179 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="ZwOwnnF0" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21680814d42so106494625ad.2 for ; Mon, 30 Dec 2024 09:47:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735580836; x=1736185636; 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=OsT4sLdVe9hCMPuRvzlfY9IxFp2eLdf3+7xkxYCm7K8=; b=ZwOwnnF0v1Dv2bPSVYi29RVXwGfrJEggRknVbzi2ns/2Xdoztjsr88RdrHuxMXqQN0 UYMRfDmjHgbCNEymTqibUr8OARj2p0MYZII5w7OPVCl2VhAUdHja/TggT+cNuNB9Dyy2 XUAhfr+PBwir0Dvx0b22m3yAosg1skA0dj5zbDUOjshtm/9xEZT7DIfPG+oLAnuHf8yY lOgOIdKy/odsET6OMVKoy0ySudZVztfD+WPvXmTusTpLxtyLqNmcGuAX/2Hu0RyRJZmR LdKocvcKU0R5p2TxXcYV+enGhZE5D6vrqDBS1XpwByxMBqLxo3t6jETw20vcv5pbLqrj 15yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735580836; x=1736185636; 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=OsT4sLdVe9hCMPuRvzlfY9IxFp2eLdf3+7xkxYCm7K8=; b=SSaBi+o0DhReeqDQz8OToMwtMjDLrwOFDavZOc1o39lAXGya/OrS6CCByzJxQtI4UP wMbpkS385bZ3VgOtYpDtLOLK5GHo1QS58rzxjSYLucyf4WWYazQiAYHgJ0FHLQpXSoCu Vb20nn/v+xGZqZue76fw5dAqKM/m361YjStMhgDiyo3K5P8f5yeH6XOQxSHvRYnKuAKg z7hMg2nkufL7M5U/vRI0u/mo4sP/kn55e1u69M5Z2M6Hba1kgcIbXGZEkp+EJXsUcNqj i02jCOlgcwS9jGpmldGOsp4Px7QpghfS8Tzp10J3gqO7YEVC8GFlqNnz3LRP2+1atacm T4Iw== X-Forwarded-Encrypted: i=1; AJvYcCUpSFIuUZaL9FD9nthprS//bmskjmN+BsK8q4ZSJWDXjGgWAqfau9cclzciXYAoz9QxPLr9EGTAof285A4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyv1pvv/u2vBy0JY2iH19khiYcWzA98KiN/2XH6PgqppxvBCkqP m4G6lwvfrdgRMgbwqWbL+oJLlIXk5vNGP1EiNc5geRKy8DN36eER X-Gm-Gg: ASbGncuq5bmAhP6QNNgOUveNOduZjuPy9BLkF/Mdguh1E876D+9WZnJXsPrFOGx2Om+ 87E8nfGe/rHQ7CiW1H//F28W7ILWq+S2tXthhw79NcJ1YMGOg3RPC4dfyw4nN2ejPYO1AQO8oG7 kfDPNkOFWt0QUZ2KRNMLJCf48/YvHxKFtHSuKpTh59ODnMxerwKOKaX4rDwCh1tE9pqe/K5NSTm nBiSpbYZycUm1AeOIdaWvydiwvKd0NzjO0cyShjyI6i4FQFLxCl/0ZgsaiSDnr4vHXJAwU++oLk X-Google-Smtp-Source: AGHT+IGPvpYXhXtnW4rHEEOtWEli3yi6N/9jP3Hzf2YcEEXLkgTW0xIcXQNV1qxoFOuaB/N2UyZHvQ== X-Received: by 2002:a17:902:e80b:b0:215:7cd0:758d with SMTP id d9443c01a7336-219e70bf2femr561117935ad.36.1735580835940; Mon, 30 Dec 2024 09:47:15 -0800 (PST) Received: from KASONG-MC4.tencent.com ([1.203.117.231]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9cdf25sm180687695ad.118.2024.12.30.09.47.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Dec 2024 09:47:15 -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 v3 11/13] mm, swap: introduce a helper for retrieving cluster from offset Date: Tue, 31 Dec 2024 01:46:19 +0800 Message-ID: <20241230174621.61185-12-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241230174621.61185-1-ryncsn@gmail.com> References: <20241230174621.61185-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: 8bit 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 60a650ba88fd..a3d1239d944b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -424,6 +424,12 @@ static inline unsigned int cluster_index(struct swap_info_struct *si, return ci - si->cluster_info; } +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(struct swap_info_struct *si { struct swap_cluster_info *ci; - ci = &si->cluster_info[offset / SWAPFILE_CLUSTER]; + ci = offset_to_cluster(si, offset); spin_lock(&ci->lock); return ci; @@ -1477,10 +1483,10 @@ static void swap_entry_range_free(struct swap_info_struct *si, swp_entry_t entry unsigned char *map_end = map + nr_pages; struct swap_cluster_info *ci; - /* It should never free entries across different clusters */ - VM_BUG_ON((offset / SWAPFILE_CLUSTER) != ((offset + nr_pages - 1) / SWAPFILE_CLUSTER)); - ci = lock_cluster(si, offset); + + /* It should never free entries across different clusters */ + VM_BUG_ON(ci != offset_to_cluster(si, offset + nr_pages - 1)); VM_BUG_ON(cluster_is_free(ci)); VM_BUG_ON(ci->count < nr_pages); -- 2.47.1