From patchwork Tue Oct 22 19:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13846085 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 8F7EBCDD0CB for ; Tue, 22 Oct 2024 19:30:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE4636B00A2; Tue, 22 Oct 2024 15:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E91E86B00A3; Tue, 22 Oct 2024 15:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBDAA6B00A4; Tue, 22 Oct 2024 15:30:28 -0400 (EDT) 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 A70F96B00A2 for ; Tue, 22 Oct 2024 15:30:28 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 90DDBC047F for ; Tue, 22 Oct 2024 19:30:10 +0000 (UTC) X-FDA: 82702228686.20.926740B Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf19.hostedemail.com (Postfix) with ESMTP id 325671A0024 for ; Tue, 22 Oct 2024 19:30:05 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LOw8tnSy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729625303; a=rsa-sha256; cv=none; b=apkSIVY5lfGFY6Ai5dpRPPy6GjXkGW1nF0cmXSBsYl9olsQQJZaBhJj2jaLxU0FtGvfYbj URicqrrwkPKqMci7XReMZoKGpgg4Hn0I1u4aiPxxv8XWlcJjEJF28FlWEQiydirSv3BlOw Xf0RIXfvdEJwemSA1GpJ0LClJSyFXbU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LOw8tnSy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729625303; 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=58sEe9Vj5/e+n1OUXtAWiattRyV+UTZMgvOaHIMS+fY=; b=7gRJMhTb2+UfY+M/NO4lHv2V5TGpGJ2LEwISMwWwUASYV2bDwLXLJXMSkRkTtx5J+VIcE8 5uL6wul/okVBXQYFF6BzulHNIqMySiPKjAmgRgUjFne1+/B8a677d0Kcb+0nU/EAwkURmv EbWyZGF79yP9wVsXygnWqaxLM8tscM4= Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2e34a089cd3so4906198a91.3 for ; Tue, 22 Oct 2024 12:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729625425; x=1730230225; 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=58sEe9Vj5/e+n1OUXtAWiattRyV+UTZMgvOaHIMS+fY=; b=LOw8tnSyYkpRa9MGlOi3QUeD9KV7XOOZxgxvZk2WopdcQG8zCivq5gfL/RKF3r5alD pVzCaNCnuSacqCEXWCASexgriEZ7DzSTXKDZ4tLbO0gteF5eGNzN17ekMTnA6Xis844E +1K4YPIC/sp0nGK/J5VL3J+2kYlvaPSufT8x2qjE0f75Yqi1nLLxlA0fSbyOLo1rhIle b3V8/oaYq6idBBFR3b8i+l9imO2pnua5SB0kK9AIlf9oCTjWmi04rtiinE3hzD9lIJsE vmPobFkMYx8BzIO2CoM+Mc/1CAJv/zeDiASfB7i7tydF6s5oU2AupgGlUkOK+OAuEnrI ZuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729625425; x=1730230225; 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=58sEe9Vj5/e+n1OUXtAWiattRyV+UTZMgvOaHIMS+fY=; b=p2CrtSzELz7afYrP4kr2HPW+gd5OG4q+wzy0QHcTtAkE+fP7M+1g4jeZUxKuTUxVmr 45r+mFgGiyBtFWZw9n8fZ20zdpTkVqWCefktmhlmPBJh4JfNPzvQF6dOe3v6g05GgRrU MYVWPodCUoVzsJ/yfCs1ZQNFpHh38cC5ejm7DRyKg4yxoihVQKMcQxPZtNOHmc950pnQ cmUSLxiMCnDKzLL48DC4ncDdT+ScHnwVzFu6btL+4f/XefAmAWhNadm78n7Pmxe7B8C4 74u06ZITYaQjhJGWk58aBu6AIZ3qj/hKFBDQoAv0/kvEnFGTA2mRpBF1xH1382PdVuo/ NeUg== X-Gm-Message-State: AOJu0YxfpUqS8V4jB9PXBBpO1y1lMKjV6wfBzug2ohBTc6P8HQzXut7N MUEQ4GfHaPQjZ1c+ITAf2nBnybEfSmDoWuXFbQyveGjHI3pJAYjSgpLn6Om+iVI= X-Google-Smtp-Source: AGHT+IH//2l1S5Hl16buo+tJ0OBYMYhrYsRemVW2E65MZE0w+xwxw5pa87HO3zq6jV4yi+SknPNUlg== X-Received: by 2002:a17:90a:de8e:b0:2e2:bd68:b8d8 with SMTP id 98e67ed59e1d1-2e76b5b59a9mr38950a91.8.1729625424694; Tue, 22 Oct 2024 12:30:24 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([106.37.123.36]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0d9f05sm45895305ad.186.2024.10.22.12.30.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Oct 2024 12:30:24 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , Barry Song , Ryan Roberts , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Tim Chen , Nhat Pham , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 11/13] mm, swap: introduce a helper for retrieving cluster from offset Date: Wed, 23 Oct 2024 03:24:49 +0800 Message-ID: <20241022192451.38138-12-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241022192451.38138-1-ryncsn@gmail.com> References: <20241022192451.38138-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 325671A0024 X-Stat-Signature: 6hujkh7xww7n6ep7thxccf3japwmgbzu X-Rspam-User: X-HE-Tag: 1729625405-716034 X-HE-Meta: U2FsdGVkX1+ujsQQEoO5vM9zSjFene5vRHkHEksWVNwCBeaJeUT5iMZPklyUG2p87Bl5YCAw9VdLxcuyoEkMGwNpNHYgpH+G4IdCmnQHCpqV8XT9CtWqCTSnT+Nn4rqZEiGaevH78zRX8zyci/SwOXM/VeWzNtv8DaXuhuVCcSmga24uwbrf10t7jU9blwWRWOAIECukj6qyc050dbcw+FNs10CiqT1VPv5kKo53Fl3DLEPY7Wu1gGZyhh5Dy3EJDvH2UYl19+icchsAU/cSCa465QsLLDvzYW9XfNqYC+ljaO0EZ+D6RUcVHc5Zf+OOfbuC2dT/OTbil2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VmwNXvPIHjF5G7uqKqYJIv/KOPJ8q7nKi/qqSwqMszlaUe2kHAeuqAzZgahNod+6AC4LMhC6X/H0HgEhwbrWfHTb6W5+KvnpsP69IoleRe/UuPsKhxaraFvfl9tuNeUKHWKTXzeVu2FhdfDUzUiWbrfeOBNG4w= 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 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index f529e2ce2019..f25d697f6736 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -423,6 +423,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) { @@ -434,7 +440,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; @@ -756,7 +762,7 @@ static unsigned int alloc_swap_scan_cluster(struct swap_info_struct *si, bool need_reclaim, ret; struct swap_cluster_info *ci; - ci = &si->cluster_info[offset / SWAPFILE_CLUSTER]; + ci = offset_to_cluster(si, offset); lockdep_assert_held(&ci->lock); if (end < nr_pages || ci->count + nr_pages > SWAPFILE_CLUSTER) @@ -1457,10 +1463,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);