From patchwork Mon Jan 13 17:57:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13937877 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 CB66AC02180 for ; Mon, 13 Jan 2025 18:00:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56D496B00A4; Mon, 13 Jan 2025 13:00:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51E056B00A5; Mon, 13 Jan 2025 13:00:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3722E6B00A6; Mon, 13 Jan 2025 13:00:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 15D9F6B00A4 for ; Mon, 13 Jan 2025 13:00:37 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BC3C6160227 for ; Mon, 13 Jan 2025 18:00:36 +0000 (UTC) X-FDA: 83003193672.07.00D7E05 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf11.hostedemail.com (Postfix) with ESMTP id CA45840011 for ; Mon, 13 Jan 2025 18:00:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JSXsIP9a; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736791234; 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=84ptMZMYZj3rVArRcmuRvTI8mbqV19hN4DkCoI7h/g0=; b=aQ9DMl3sSBUK3RkrfAdLdL+zOfprcgjLNl8vTsSxbjyBSolXrmC6z7KSRXxJI1YyCVe2sC ovWYseRP4tuHrqWRXe9Ho13PKVNcxwh8tAU0RD/x3AECgU8YXbuJhPITeEp21VZJh/wnDg ZFpxP82lDqo9l3SOQHm7cLzky0EqDEs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JSXsIP9a; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736791234; a=rsa-sha256; cv=none; b=0z+Iz2fXftoBadp16Nq5v6l0PFxGdISOdL6kPYwsvi2nPbWqIN7WWdt47ZnCSbn4e1LRRd y8aAmFI1glpZSTvrNdrzv38KqtgULdZwuUPzF/z6sMTVwxYtuPDB6ZKPtw2+SJ/etzUx5A ci0v8yOsKNNfp186pszwO9dWFgnEjls= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2167141dfa1so81038985ad.1 for ; Mon, 13 Jan 2025 10:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736791233; x=1737396033; 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=84ptMZMYZj3rVArRcmuRvTI8mbqV19hN4DkCoI7h/g0=; b=JSXsIP9ae/TboQM/WzaoGk0G3rcW0NjKI9EdH3sZ5UFpcWhrA5sSwMRVyOx2OmZL/o nFVR0TqzgWMsDo4DGxFTuof/mmVGhVolQ7eNkV+YKe9CnB4gOtYS9V301UD3MA8H7GqC hKmKbGSvpVxui8EECN0c6f/l8BtTOCFbB8a+A9W9mvoYHoNYncpXpOdRa02c0cI3eZzB 4zThj5CrZnAmetNjkJ0FVxFvf94KjpkwOb5yrWj056b62oN2w1/aBmsQsrvv4Lnh/Oss ouKpyS6hrjfj8IunifO8OG0oQZMLmKAyD/fh4gV9OEaN9xTwcYNhXpzYLBV6+8UVPjN9 1/0g== 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=Xi17FkjFZdzG34TB4iKiut2wMc/9oJnZpov4qjuDCJCtekiQDjiL8DGZGMCGcLSp7e PiKL0KI5QA6ko3hADMrXknuY4UKd4R2OHVMccqoIzI/jLg5wfpTnfwo4/JVt4jQgZi32 VEJkj3y/OKgeL+0ZK5+tY7H9LLuA1hOQC2PCP/qsDxmFaFXQG3UFmuuCGRchsZf04V33 dBhqFQ8spgzFvTX0bswbN12C2VuO9pCiZzio+hQIBiv+Vdy/wfdUtTfRii3kBr6FPHc/ sh4iUoGfrZ1EUf7yJAk5FyEcfSm9WG4eph/i+lL3/659Ob/8xKXGXrcfYTIGyHcpvHn2 qYRg== X-Gm-Message-State: AOJu0YwcSByvZ+s1fH8oHvdmfBHCM0N9TwQuuSN9lQbggmEl0lEPHfyj iaeIsbRrv2G1gk4g1kG4cx0ZOPVL5wrECGllmQUOlGRT/vpKvkQspnUmmRk4XHQ= X-Gm-Gg: ASbGncvWklyMV+SS5Fp+zFYdfelz6FzSxRUZOVmmOIjIDFE1Wig3OE8b2gs9LbdSdbX cgCMr11XdnoLN4wEJ9OcGvUselekGRS/E+wQUkJuHe72zwey7H96ZxMYiMWwSUCtTH1YX+r6eZ7 tJaxw6t4VQrMm7GOcZKmDs9Jz9qn8pUCkfsZsDj/SURn3tqD+QPlKVPm9GcId7WzvpqNiLdvdTS ivdD7GB3qiQzq4KtM9wGGWFuT26cghKYobfeUN0r6LEobtdmGx91WhbJLPLGVPz+yIO9Wd7lrzp Ug== 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: CA45840011 X-Rspamd-Server: rspam12 X-Stat-Signature: dhcik79sfj44ukxzu1zqdeurxqs3waex X-Rspam-User: X-HE-Tag: 1736791234-740572 X-HE-Meta: U2FsdGVkX193yhnQ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yD+Enk0c94kMT/akQdodSeQ4wJhAjvy0aBrWUVdd7HAFwHNSs5abcbq/rI2g/rFBDHYHEa34XnmHU+B9NmKznjT6+yfPcoXR1q758faQMCHFh6StAEZejybY0Bgw7JlOf77hHkrj4KQflz8KxJbE0nUREOKJm4D/nbMfrS+uPwmLSL97lOZMn6m1GwEQ9YgG//CadRZFir2932QDBMtbl/mjSuzHEt+k6DsNk5o90G1p5uiVcXqfyyIe24SOQyJuqrK9bsD4gsaSXo66R0nxBpV3n1strb2kL+eI75URB9/89DnTrEH/PqPniDEOy7CAJi49s7ZQ5YnQ6KiM56EM0rJeKBDSbArzpqat3LiNEwcLZ92nXKKBZKYg8ZtAzllIlQOS1wU/y38S6qMHGRXcul0RlfrydqsQFN1tysdV5Uo3wWUbKUdPe+bI5Tn9EOWBuvQ34Fo= 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 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_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; @@ -1480,10 +1486,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_empty(ci)); VM_BUG_ON(ci->count < nr_pages);