From mboxrd@z Thu Jan 1 00:00:00 1970 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 A9328C3ABD8 for ; Wed, 14 May 2025 20:18:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CF936B009C; Wed, 14 May 2025 16:18:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17E466B009E; Wed, 14 May 2025 16:18:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F33446B009D; Wed, 14 May 2025 16:18:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C47B56B0083 for ; Wed, 14 May 2025 16:18:19 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AA6E85EBD8 for ; Wed, 14 May 2025 20:18:19 +0000 (UTC) X-FDA: 83442625518.27.3227EF7 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf15.hostedemail.com (Postfix) with ESMTP id AB56CA0008 for ; Wed, 14 May 2025 20:18:17 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WGBjQgNg; spf=pass (imf15.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.47 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=1747253897; 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=hMZ4uysUw5XmBRCOMbR111V6yRnZBa1kOqJbE6cary8=; b=QtWuc5S53esFm9N7iNKTeTGYpMHp907yKv+tUZLKvYrZ6GBiOjXAn30zxstRJu6n1L+dnV AQMRv27clclj1KIp/LJlxjwGhKk/CEc6wQM0iPAWhny5kChOrpF6zhRZjVGcxXqDzePTuk xAPP0AXdECEV+53eiF/XpkcQKPhzmOQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WGBjQgNg; spf=pass (imf15.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.47 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=1747253897; a=rsa-sha256; cv=none; b=yWv3ZxtIHdJ29LZy8zbh5gjMfQJ/0JpDOUzfGJctEd2u9T9cLxjuEfF/NW2irkT5iduS08 pSyH5QmQTLnssfP7IEwbh5bIwTy7+eEJT4prxku0N8hyoc4ZnZfageampBBknqdTXMf5Qw IdqAr/ABqathGLU3ATviXE7SrpQoFBI= Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-30ac55f595fso269487a91.2 for ; Wed, 14 May 2025 13:18:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747253895; x=1747858695; 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=hMZ4uysUw5XmBRCOMbR111V6yRnZBa1kOqJbE6cary8=; b=WGBjQgNgudjIq1m3jrKZpEVfbAIsZqF3eWliKv7ez0aMiU203XekGowQ/U1SxJi4TS /YbUQiQdRIa8AHkPcsX5igb2U+AJYms41BIXkJMGjA6i5DdoNktpRMefRyXE3GIluJj3 eJ0S8JeEDdKEN8MOIdWbHPPlQAA8+ZTGy2BiHnuz0y4TT8SPAYkMFmndHOp5uH/LR3qg 9prPvGTTlAJKjGk0L+LBA1vo7YKRZK55ETjEiL6MUUjux98m2nac/XOJEuPoBlGI5/WL OKGmGWXM888cm9WJajeegOxvsUIJEvXwmsIDzK1VsMIZhgqlz+V2fzLxqKVOwBgFzblI 9kEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747253895; x=1747858695; 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=hMZ4uysUw5XmBRCOMbR111V6yRnZBa1kOqJbE6cary8=; b=Y+3uR977IqZ1ADxL8I2udHo3i1+2KgZ5FwKQLpqAjCKfx7+JouoMK2y+AtIaXFM6nf EHBClxZX43CHI/6Xto/o60g4AGziBLQnQDRmV98uAe5hzG9KTT2aFgDaSqdFpH11E1Rh qMqSHkxc1tyf/mMdmGZ7E+cdqQGPmf4T6fXmJt921Ex336dTTqgdokdYHFXeVYIoQ51O 6DBIAUEJBZsYLs0Q35Uh0ZKmVjDsUQ6cjOMczLv+k04o8jtsl+BrFIzkx/KPOBhzpmw8 3CXfDXFZdUrgQmxUriQ3YWS37SrVYcSopEtI5UJiWQg5+sZrPrSILPYUp2ot1YVtQ8Ad L2xg== X-Gm-Message-State: AOJu0YxHyfEZpYPQvbh2ZzHbKyqNg4Bg4E13uwjs/p19sVYqhkR4hyvB NTMCStGQ7QZKcN/4bVRPvpv6SI3LkEmzkIWLbWNQ3brEEPir6nEdMEcfyRXOMDU= X-Gm-Gg: ASbGncuvpgEtVkZZpi0zmdki5SkrwfM7eLRwNCYBXGlybfolEjo9xhMSyh7biMtF43d z3zkC7GBQm+UhNL6jn58Wo8QEgn/UnzhR+oJX5ZaJo4uK9CaUG+REZbm0fZaLDys4pKFyX6ZjsP O3H7XnwrpieZqn4YTkymzD7rBdsTo3zYMbRlF92nVMS9aL4VA3g+H2uEmNJmcKd3dKxypi4K7Eo Uk5fqLeNvL6tI++HiKt41ICM6p2E1hCpDwrv1Eoy4Lqg6HrkA4AUiVrNj7sPhWbzD9/gNPpV+PD wPkFs/5cTwjfq68XDXkcf93eVa0qKVNqPvTXugyP9fYcPBw/60DIyPSJ3kiT/Wgq8HANIRt7Pls 01NzeuzE= X-Google-Smtp-Source: AGHT+IEUaI3tR4+A2EceQwbSasO0BEEqnAS6T39gRBWH2JvFh4nLt22ieE6sc3PwNU8lBlnMxoYivA== X-Received: by 2002:a17:90b:2d4b:b0:2fe:e0a9:49d4 with SMTP id 98e67ed59e1d1-30e2e5818bcmr7861484a91.2.1747253895294; Wed, 14 May 2025 13:18:15 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30e33401934sm2003692a91.9.2025.05.14.13.18.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 14 May 2025 13:18:14 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Hugh Dickins , Chris Li , David Hildenbrand , Yosry Ahmed , "Huang, Ying" , Nhat Pham , Johannes Weiner , Baolin Wang , Baoquan He , Barry Song , Kalesh Singh , Kemeng Shi , Tim Chen , Ryan Roberts , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 07/28] mm, swap: tidy up swap device and cluster info helpers Date: Thu, 15 May 2025 04:17:07 +0800 Message-ID: <20250514201729.48420-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250514201729.48420-1-ryncsn@gmail.com> References: <20250514201729.48420-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: tbr545i578yq7xmcofpdzfibbwgeqwqj X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: AB56CA0008 X-HE-Tag: 1747253897-446644 X-HE-Meta: U2FsdGVkX18s1Tp3Fku0+fBjxPWXW+K3QHnLSAmH+r5Edgiztinfin+JLWw6OP13aZ6fvVKXdkaC0ZaiUV4gXpHWi8etBwy4oZQpFXDGSR42zei3V0XoZ+1HHs0nNWwISqwwGZPa2Q13iHqfNV5R6lZjBWhc0/cEmYCnUcBw/dcFxCbCAaRErbHwL1CorPXtspAGFH6Am2EgqnnAWTL04Dyt999A5V6gWs0nE4uCFeNV/K7I1x1QTxVOHCj+af89oRxXSDpv/1nzHw/Jv2QzO9fpPxcFmqbjUfpYgAgKdbzPBYiMM2cxj6jrNFmREZBVqp+Io3ynJyJkYRTixFulZyGodpfk+EvGP6ecE6BhD+HECCm7SSYnz6Elkkn6uDM/aoQ2v5RspIhBbjekoVAafwNfsIUIaM98UFhbm0/QYet+sHdTh2ZVbrdhiqAs0PlMbg4yNhR5krAqX5OVKDDx+3SVsUsqqLGmZfgRfB+//FHECBbQmSIQT9PbV40nzgkON4idiNpceiSQGmknMw4/+f2LKWM2TjQdw/ly7p6LCMMLf/4WhbjEaB8PBmP1/Lcwi62pYybi4I2hT41yDOEFGKsvAG/4RrIp+k9Nzi+a/wsWLax8WSzP1t70KwbFUIyFUOZwTLskQf1Sr+1ynWDzhittpTQYBE7aGbJX6c4oDpCXNCwyPUlWtPuOP/iCP4PtID58eSsk5KK8HUdoPusG8hEo7DGtQnAC0Bo3pG4SwPVI7gge5NwmfI+ShOBCFsyrTO/YgGxgVpgSu9v5NJ82Po4v51pf+Kv911dSd7I9fvShhSzDsdtuGfdcWLSF6jdECxqGFOKtzSYy5EcoGuhpkxNXaiDbFH9R7hU+npR9UPm6g6GToCcOaHwqeke9DYb0eJYE8XrkKXRe5aHZT4K/RRzIOumYemWsDPVIR0T1ARuEtDXqA8/j/B9lIG0/NBm8hERjo5fsNouxQiuC2sz 38tQwQUw IGNOCg00OSQtpwa0MFAZNizvFnoRHH0gvIULoYktWErzM+L4iwPoRsi+JqDMOC685GH2w6ZSJ+R/TjWKcJWthhCO8ozCYs5ZPr9y/dh5akFvNVGpyrn0ss4BqBc3P5P3syRkhdz8jtMv0T0+a6nnh1XedtNF6SPrKPIFQRPHJktxgtpEntZlEoekH23XBlKx31yDdNEm29W/cVlxS+5OmOPaRZzDoUOcqsmAjAUdLvmGACaXTtwa6Zl650P+VqCgze/urTt8OuSegjgkz36I1tTWLSYHhr3oJCJaig9ttoVjzWcmKfQnfYdzo4OhfdkeuZwlPx5AZMD9XWyh1cRXsDSzTo8oWcilbaj3y/akVVdrlowbZdzKb3tnj9Eua6g/G/M4hE4KalO8gRAy8roHA1L1idahbxbcMAGm4JKizojiW2w2PH4L3hz8mkcarWvikcrkZh2trxueh4AWPCaOkiYGSytPFsvaQmZpRkNxg1m06o9/tCNh6pumtjVNi3/fP8ljMm2otLYcbvgVtESwBP7TlLcGX1APhfkBrvfl1LObvK2mCBFWDNZjRa/8JxaHt33GP 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 swp_swap_info is the common helper used for retrieving swap info in many places. It has an internal check that may lead to a NULL return value, but almost none of its caller checks the return value, and the internal check is pointless. In fact, most of these callers already ensure the entry is valid during that period and never expect a NULL value. Tidy this up. If the caller ensures the swap entry / type is valid and device is pinned, use swp_info / swp_type_info instead, which has more debug checks and lower overhead as they are inline. Caller that may expect a NULL value could use swp_get_info / swp_type_get_info instead. No feature change as the rearranged codes have no effect since they were mostly ignored in some way, some new sanity checks are added for debug built to catch potential misuse. Signed-off-by: Kairui Song --- include/linux/swap.h | 6 ------ mm/memory.c | 2 +- mm/page_io.c | 12 ++++++------ mm/swap.h | 32 ++++++++++++++++++++++++++++++-- mm/swap_state.c | 4 ++-- mm/swapfile.c | 35 ++++++++++++++++++----------------- 6 files changed, 57 insertions(+), 34 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 1e7d9d55c39a..4239852fd203 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -453,7 +453,6 @@ extern sector_t swapdev_block(int, pgoff_t); extern int __swap_count(swp_entry_t entry); extern bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t entry); extern int swp_swapcount(swp_entry_t entry); -struct swap_info_struct *swp_swap_info(swp_entry_t entry); struct backing_dev_info; extern int init_swap_address_space(unsigned int type, unsigned long nr_pages); extern void exit_swap_address_space(unsigned int type); @@ -466,11 +465,6 @@ static inline void put_swap_device(struct swap_info_struct *si) } #else /* CONFIG_SWAP */ -static inline struct swap_info_struct *swp_swap_info(swp_entry_t entry) -{ - return NULL; -} - static inline struct swap_info_struct *get_swap_device(swp_entry_t entry) { return NULL; diff --git a/mm/memory.c b/mm/memory.c index 254be0e88801..cc1f6891cf99 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4315,7 +4315,7 @@ static struct folio *__alloc_swap_folio(struct vm_fault *vmf) #ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline int non_swapcache_batch(swp_entry_t entry, int max_nr) { - struct swap_info_struct *si = swp_swap_info(entry); + struct swap_info_struct *si = swp_info(entry); pgoff_t offset = swp_offset(entry); int i; diff --git a/mm/page_io.c b/mm/page_io.c index 4bce19df557b..eaf6319b81ab 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -204,7 +204,7 @@ static bool is_folio_zero_filled(struct folio *folio) static void swap_zeromap_folio_set(struct folio *folio) { struct obj_cgroup *objcg = get_obj_cgroup_from_folio(folio); - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); int nr_pages = folio_nr_pages(folio); swp_entry_t entry; unsigned int i; @@ -223,7 +223,7 @@ static void swap_zeromap_folio_set(struct folio *folio) static void swap_zeromap_folio_clear(struct folio *folio) { - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); swp_entry_t entry; unsigned int i; @@ -375,7 +375,7 @@ static void sio_write_complete(struct kiocb *iocb, long ret) static void swap_writepage_fs(struct folio *folio, struct writeback_control *wbc) { struct swap_iocb *sio = NULL; - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); struct file *swap_file = sis->swap_file; loff_t pos = swap_dev_pos(folio->swap); @@ -452,7 +452,7 @@ static void swap_writepage_bdev_async(struct folio *folio, void __swap_writepage(struct folio *folio, struct writeback_control *wbc) { - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio); /* @@ -543,7 +543,7 @@ static bool swap_read_folio_zeromap(struct folio *folio) static void swap_read_folio_fs(struct folio *folio, struct swap_iocb **plug) { - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); struct swap_iocb *sio = NULL; loff_t pos = swap_dev_pos(folio->swap); @@ -614,7 +614,7 @@ static void swap_read_folio_bdev_async(struct folio *folio, void swap_read_folio(struct folio *folio, struct swap_iocb **plug) { - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); bool synchronous = sis->flags & SWP_SYNCHRONOUS_IO; bool workingset = folio_test_workingset(folio); unsigned long pflags; diff --git a/mm/swap.h b/mm/swap.h index 38d37d241f1c..4982e6c2ad95 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -13,6 +13,8 @@ extern int page_cluster; #define swap_entry_order(order) 0 #endif +extern struct swap_info_struct *swap_info[]; + /* * We use this to track usage of a cluster. A cluster is a block of swap disk * space with SWAPFILE_CLUSTER pages long and naturally aligns in disk. All @@ -51,9 +53,29 @@ enum swap_cluster_flags { #include /* for swp_offset */ #include /* for bio_end_io_t */ +/* + * All swp_* function callers must ensure the entry is valid, and hold the + * swap device reference or pin the device in other ways. E.g, a locked + * folio in the swap cache makes sure its entries (folio->swap) are valid + * and won't be freed, the device is also pinned by its entries. + */ +static inline struct swap_info_struct *swp_type_info(int type) +{ + struct swap_info_struct *si; + si = READ_ONCE(swap_info[type]); /* rcu_dereference() */ + VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */ + return si; +} + +static inline struct swap_info_struct *swp_info(swp_entry_t entry) +{ + return swp_type_info(swp_type(entry)); +} + static inline struct swap_cluster_info *swp_offset_cluster( struct swap_info_struct *si, pgoff_t offset) { + VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */ return &si->cluster_info[offset / SWAPFILE_CLUSTER]; } @@ -62,6 +84,7 @@ static inline struct swap_cluster_info *swap_lock_cluster( unsigned long offset) { struct swap_cluster_info *ci = swp_offset_cluster(si, offset); + VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */ spin_lock(&ci->lock); return ci; } @@ -154,7 +177,7 @@ void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma, static inline unsigned int folio_swap_flags(struct folio *folio) { - return swp_swap_info(folio->swap)->flags; + return swp_info(folio->swap)->flags; } /* @@ -165,7 +188,7 @@ static inline unsigned int folio_swap_flags(struct folio *folio) static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr, bool *is_zeromap) { - struct swap_info_struct *sis = swp_swap_info(entry); + struct swap_info_struct *sis = swp_info(entry); unsigned long start = swp_offset(entry); unsigned long end = start + max_nr; bool first_bit; @@ -184,6 +207,11 @@ static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr, #else /* CONFIG_SWAP */ struct swap_iocb; +static inline struct swap_info_struct *swp_info(swp_entry_t entry) +{ + return NULL; +} + static inline void swap_read_folio(struct folio *folio, struct swap_iocb **plug) { } diff --git a/mm/swap_state.c b/mm/swap_state.c index 07c41676486a..db9efa64f64e 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -330,7 +330,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct mempolicy *mpol, pgoff_t ilx, bool *new_page_allocated, bool skip_if_exists) { - struct swap_info_struct *si = swp_swap_info(entry); + struct swap_info_struct *si = swp_info(entry); struct folio *folio; struct folio *new_folio = NULL; struct folio *result = NULL; @@ -554,7 +554,7 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, unsigned long offset = entry_offset; unsigned long start_offset, end_offset; unsigned long mask; - struct swap_info_struct *si = swp_swap_info(entry); + struct swap_info_struct *si = swp_info(entry); struct blk_plug plug; struct swap_iocb *splug = NULL; bool page_allocated; diff --git a/mm/swapfile.c b/mm/swapfile.c index ba3fd99eb5fa..2f834069b7ad 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -102,7 +102,7 @@ static PLIST_HEAD(swap_active_head); static struct plist_head *swap_avail_heads; static DEFINE_SPINLOCK(swap_avail_lock); -static struct swap_info_struct *swap_info[MAX_SWAPFILES]; +struct swap_info_struct *swap_info[MAX_SWAPFILES]; static DEFINE_MUTEX(swapon_mutex); @@ -124,14 +124,20 @@ static DEFINE_PER_CPU(struct percpu_swap_cluster, percpu_swap_cluster) = { .lock = INIT_LOCAL_LOCK(), }; -static struct swap_info_struct *swap_type_to_swap_info(int type) +/* May return NULL on invalid type, caller must check for NULL return */ +static struct swap_info_struct *swp_type_get_info(int type) { if (type >= MAX_SWAPFILES) return NULL; - return READ_ONCE(swap_info[type]); /* rcu_dereference() */ } +/* May return NULL on invalid entry, caller must check for NULL return */ +static struct swap_info_struct *swp_get_info(swp_entry_t entry) +{ + return swp_type_get_info(swp_type(entry)); +} + static inline unsigned char swap_count(unsigned char ent) { return ent & ~SWAP_HAS_CACHE; /* may include COUNT_CONTINUED flag */ @@ -343,7 +349,7 @@ offset_to_swap_extent(struct swap_info_struct *sis, unsigned long offset) sector_t swap_folio_sector(struct folio *folio) { - struct swap_info_struct *sis = swp_swap_info(folio->swap); + struct swap_info_struct *sis = swp_info(folio->swap); struct swap_extent *se; sector_t sector; pgoff_t offset; @@ -1272,7 +1278,7 @@ static struct swap_info_struct *_swap_info_get(swp_entry_t entry) if (!entry.val) goto out; - si = swp_swap_info(entry); + si = swp_get_info(entry); if (!si) goto bad_nofile; if (data_race(!(si->flags & SWP_USED))) @@ -1381,7 +1387,7 @@ struct swap_info_struct *get_swap_device(swp_entry_t entry) if (!entry.val) goto out; - si = swp_swap_info(entry); + si = swp_get_info(entry); if (!si) goto bad_nofile; if (!get_swap_device_info(si)) @@ -1560,7 +1566,7 @@ void put_swap_folio(struct folio *folio, swp_entry_t entry) int __swap_count(swp_entry_t entry) { - struct swap_info_struct *si = swp_swap_info(entry); + struct swap_info_struct *si = swp_info(entry); pgoff_t offset = swp_offset(entry); return swap_count(si->swap_map[offset]); @@ -1791,7 +1797,7 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) swp_entry_t get_swap_page_of_type(int type) { - struct swap_info_struct *si = swap_type_to_swap_info(type); + struct swap_info_struct *si = swp_type_get_info(type); unsigned long offset; swp_entry_t entry = {0}; @@ -1872,7 +1878,7 @@ int find_first_swap(dev_t *device) */ sector_t swapdev_block(int type, pgoff_t offset) { - struct swap_info_struct *si = swap_type_to_swap_info(type); + struct swap_info_struct *si = swp_type_get_info(type); struct swap_extent *se; if (!si || !(si->flags & SWP_WRITEOK)) @@ -2801,7 +2807,7 @@ static void *swap_start(struct seq_file *swap, loff_t *pos) if (!l) return SEQ_START_TOKEN; - for (type = 0; (si = swap_type_to_swap_info(type)); type++) { + for (type = 0; (si = swp_type_get_info(type)); type++) { if (!(si->flags & SWP_USED) || !si->swap_map) continue; if (!--l) @@ -2822,7 +2828,7 @@ static void *swap_next(struct seq_file *swap, void *v, loff_t *pos) type = si->type + 1; ++(*pos); - for (; (si = swap_type_to_swap_info(type)); type++) { + for (; (si = swp_type_get_info(type)); type++) { if (!(si->flags & SWP_USED) || !si->swap_map) continue; return si; @@ -3483,7 +3489,7 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage, int nr) unsigned char has_cache; int err, i; - si = swp_swap_info(entry); + si = swp_get_info(entry); if (WARN_ON_ONCE(!si)) { pr_err("%s%08lx\n", Bad_file, entry.val); return -EINVAL; @@ -3598,11 +3604,6 @@ void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry, int nr) swap_entries_put_cache(si, entry, nr); } -struct swap_info_struct *swp_swap_info(swp_entry_t entry) -{ - return swap_type_to_swap_info(swp_type(entry)); -} - /* * add_swap_count_continuation - called when a swap count is duplicated * beyond SWAP_MAP_MAX, it allocates a new page and links that to the entry's -- 2.49.0