From patchwork Tue Dec 24 14:38:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13920199 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 D326DE7718D for ; Tue, 24 Dec 2024 14:40:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6081A6B00A3; Tue, 24 Dec 2024 09:40:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 591406B00A4; Tue, 24 Dec 2024 09:40:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3714C6B00A5; Tue, 24 Dec 2024 09:40:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 12D6F6B00A3 for ; Tue, 24 Dec 2024 09:40:19 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B640D1C7D7E for ; Tue, 24 Dec 2024 14:40:18 +0000 (UTC) X-FDA: 82930110606.09.5537D48 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 3498C180004 for ; Tue, 24 Dec 2024 14:39:48 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bYtwUEGF; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 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=1735051198; 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=Bzlbcu02fLqLzv6kaO1DSu6E6WlQUI1ISyd8RxZxJr8=; b=oXlYKLpBBbyFy/j+8YugSrpBIBVqydr2+lFfUUtyhOQ94dA7htR9VmSs0yXZvs0RYprevt Br26+l5jDgIXgWlOO4HX3Bkh7cOoCfUka2ylhTDa2SIJFjr3jTHFgLLsaX5WZA4vbcYogZ rvq53HPoXEy4oDDNjKmGqUsSNSXTdQM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735051198; a=rsa-sha256; cv=none; b=gBofY70lkm+jYaHXaTMGikpLVdM+cEGQop6C1QUd6A7TqKP40iaYqmPYjjdF/4mlqQRLyY JSTTA10aIStnwBRyJeak0TZXIPtrxgleHiqrxcaJ9eP8SF9Fp9DFoApunbJrfCdn/vKqot 1WS9+1h7NvZMKLP0TnDO/r5LjjAjsjY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bYtwUEGF; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-219f8263ae0so21236405ad.0 for ; Tue, 24 Dec 2024 06:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735051215; x=1735656015; 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=Bzlbcu02fLqLzv6kaO1DSu6E6WlQUI1ISyd8RxZxJr8=; b=bYtwUEGFmmcA6wA/vtwlrImRE74D6LhJpkUlxWFu3KmbwDLpM+2DEQANu/N9sGp3F9 CGChjW60OfWl2oBWyq1kdj6u0nIqTuM5XAoIM6bvzR4RGJ7uf3hoXnGO1PrVy/LLpeI6 sEVb1ZrV8I8srrLQMQxkGnp21Ec0xBLuVdWpC/EW1j0cQqfNTvWEa/cPOPoiSfqb2S8u fCJAWUCZ+YPtxd48RQ/usC2+GO9uRGbixNUV55ge1YclbScxH2BBJdeRVpz2N1ifa6T7 c6pQ83lMx9qjMs6ssYYMBji1hzBVEEipyw/AMsyHHdF/4JRvqhw67DLOBJxvArK+3Epz C1Ow== 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=MCp8rPc3NFxN3h7bFb8BDn4knkITf7ufOqVtWtl0+nvCI2NE/H464rdeYnw7509oSn Tfa2jCglXXN7nsm/v6FQR3VBvO3PT9GR7JpdihnrjC3ZI/djVyrB1wH6XQ2nDyjZv2uY 1BXZO0ONPLCBYzW30iLQc2mBPWuN8QAiDX5Kwk9B0yWc6LahGM3Q9QSU7qm4b4w7dYAw wMEgnpu1QgQeccP0hHTJEGx6D8jT5Vib1RgReL7TRG0QhA+uWiQ6GH8S/0SAlTqKsxZx Albn5VfJaQClx5hzw+VKYwAqiT2UIZoBbA9DWe6XFC1JAfCjjNVRHu4dvTdI4kH8ZKon opVg== X-Gm-Message-State: AOJu0YwX18f2sqr/PqqmhB8H3CV2pWyHhj/N/SxU+TBbDyorVyOIQXvi 1McK30BLlUYnll3iA3gYexNcNh1FTYyC/68iPxFBruZzjlPMBwBNL7KVP5yU0NQ= X-Gm-Gg: ASbGncvGp8a2ocIwLkp5TkOtS+IDQM2fhz+ytbRLkYEvnwyCyNRUzNgnO2Ph06Vq7DU m7I/WJZma4n8nzUHoYG3769mOnjntLw37EoJMP+FDOFwnqh0K4awZPLP5Eeh0PQDYKbQqu/PN7I yxJNwoEiDB+ZoArKB6AMidhCEI8DrNWwjY1i27RKM7Ayx7TZqLaQd0wcbsRVyV8ovsiDhKoHmHx /XK6yPBTOeX+HnkmCgIzn0+O7yOfayWo1aYJIYBvD8PxUQsim9MmqnRVA0kBIxXMukDRm0KyPpA zQ== 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 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3498C180004 X-Stat-Signature: 58iymxs74g3514ib1gn33fmaqkag6mwr X-Rspam-User: X-HE-Tag: 1735051188-462441 X-HE-Meta: U2FsdGVkX185fO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YLbZYghb2mBrnnxmY8dTMxkfGvjwai9MRjVxuAhiU4eCcdjy2axBSTBxUKuq/Zo8RkuuFicE+4a4+H0M32WS5fih3k924wFZ7slch4iwP5gc1VGSxb/ZvSMeLYSa7tUxhdNxgokpy1+OZbbAAA1uk5qAMxmWLQP5HXidr3+l9uBQ88OWFFEtaeCL8MNaPRX0dDf9MpKzDIC0/yZdntkcP51Boqa8b7w3V3b9d3Jc/ArzshWwrXnemrWA5UU3Ooty0lrUJ4g0mKrNaOrlmNZL10teLYVv7TduyARWymC0SuLKk4i+2PlEhd5mpS86BIwazqFBO7gnNIlLbeuL0wa2XdF7/YgutX6nTZihFznrfTOBNvKQtHitRnXr58O1RAC/WIyW+dQOEd/7HC3+RmFCmb9Wy75vCah/r0bMz33B7IwyIQQzRvcF7x2YPS9tpzW+sd4/sFOKo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000708, 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 ac170acf55a7..0445a2db8492 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; @@ -1473,10 +1479,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);