From nobody Thu Dec 18 20:36:27 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 DF3EA1C5F1C for ; Mon, 13 Jan 2025 18:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736791235; cv=none; b=oAf707o3tHW9abxncHYpKCtGj6k8Oepv6ia0INcVgBifF8etwg7S+KVQRrB1b30+RvP8oH4ywI2dddqlmEmSCTb1VQKJeRcNSLAhTWw34OBsL7kVftfSTibIthmYH/Z3bw2kG7hH/Ot6dkp04eTFtgR63ClDhIoGfiHObNkIdPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736791235; c=relaxed/simple; bh=Btpk8Q4K9TruqKsylbnCNcfi6xBpUcgdCeqlnyeFJbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JbdEX5Bb/qkcMQlq9mJRk05mW0kg/l2KjBJdqxPG0aDeWHZs6P4YFfgh1Sd0pxxruehdVKdkAFL5vBCNmyGi5J5EP02P4Yo6Sp3tP4NV3N2SNdrv04H+a1LklERGhF+hg/K0zTcMgHA925l9J0eou0+g4akRqsTZN77WFLvbjJE= 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=EmW7idgz; arc=none smtp.client-ip=209.85.214.171 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="EmW7idgz" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-216395e151bso56011225ad.0 for ; Mon, 13 Jan 2025 10:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736791233; x=1737396033; 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=84ptMZMYZj3rVArRcmuRvTI8mbqV19hN4DkCoI7h/g0=; b=EmW7idgzu6jAHcUNDyVg8Ikt+bra3UKpeZfY+Eyy9LQsdZnUgPDauf/sE3Di3OIcaf lhWXjbh+tCN45W2DWanEv2M+CpJC9HVQ3da7/8emcPE98t/BFoJ5cFMGijSt9mtjxxiI hqNUe8aEfUQzinnCwr8eSv3agwsGuDC1m1UXNoDX7m5Q//zmSUiGjX0pSRy3SWsdmB+j kY3d77AtRLBY+98sI2cb3+LPssJy+62/SmRkATnLUVFpyjuEkfNTFKNISt/uls5i4Sg2 SLexRuf5hdmFW8PlgYMdyMF297QoA2VHmWnMfpAWXnfYjg5vaHUSxlUBObzIx7epSUhq XkEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736791233; x=1737396033; 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=84ptMZMYZj3rVArRcmuRvTI8mbqV19hN4DkCoI7h/g0=; b=qGZ1ZNH0CHFPou92e4PNL2s6DaXD2N2yYUfqkYNkmste3nldiJYNdicyzku47vqxPK 1pXf5FzhePbCYHqk5CrD8D2I8WfqUdK11b1j4RWWaMEtqi5tIaIL6Y3vW7i3P2jama+5 0mSjnVb8RADsj+m/++JNeydRcWFdPJrvoS3FnDBIY0cxXPfIOUcHMvP6FvtGGsSJdZa4 5Gr9ch9dV8uKopHQISvzw3bg5ckYKcyPxvSViRujq8FrNtKWwbp5TGMxuHa/fI6VkNLt DAcPmVO5td5R47nWpjuwhMVCXPCJjp5HFKW3JuAzyEfgXI++4tH2ACzku9+/oDXiXuVG m0QQ== X-Forwarded-Encrypted: i=1; AJvYcCUDbzrSeWRWDaCYTgZrcWlPJQRiDhJ/e9WsteUScZoyCaUY8MEEGrsqLjF3Dt2bFAmNeuYGHMEDnpW4Mds=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6Rjl0XHPDnUchSNuOB9azlr7JDOjUHJev8Gn2ANbKNKWqFDMY htlXUlIlgod1Nqut87jhKcYrIcjiLzN1wFa5quwhpq56cH+qghNY X-Gm-Gg: ASbGncv/VkOsgdMwkJBxz75AkcNcsPdgk99t8tzPkNeSFrXSdfQQbbi2P3V7Bp3HVmo C5SXR0XkvspthBywSwtvW80Ci/WbW/aSc6KeUiYMzINS4o/V5TqgFWY1t8N8xNM99SMcaCdV5+w NGSeLgJ8YD50R1ysus7McAiu34snGz1hzfe/aTugiLXoL2z818CJ29WzoNr3OhNXVU2HcjZOJ5G GHXd1F+Pq2AIjQRtWzWrDFDUSMI3oKZMrFNn9CllqFUKMM+ypZECIHFTOe8+UxoSVrhiVRJb/us wA== X-Google-Smtp-Source: AGHT+IHndLsitkjnbmdqmvdITPRrE8bpKXtfyrzCQgnWcbfVYdpyJsxfkIpMOC/VykeL5wA03UubJA== X-Received: by 2002:a17:902:fc47:b0:215:7e49:8202 with SMTP id d9443c01a7336-21ad9f3c0a0mr170609865ad.13.1736791233083; Mon, 13 Jan 2025 10:00:33 -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.10.00.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 10:00:32 -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 11/13] mm, swap: introduce a helper for retrieving cluster from offset Date: Tue, 14 Jan 2025 01:57:30 +0800 Message-ID: <20250113175732.48099-12-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 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 6da2f3aa55fb..37d540fa0310 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; @@ -1480,10 +1486,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_empty(ci)); VM_BUG_ON(ci->count < nr_pages); =20 --=20 2.47.1