From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (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 4A25034E75D for ; Fri, 20 Mar 2026 19:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774034861; cv=none; b=exc/QHL3WXv9uSowape8CZm5oLEfAJ5Cp7/F8/SCqcujE66fXO+PHbeOVkiqBIIIMR+O+fnOUXl2fuE1TLqE4sJ0Uz4NPrbO9Ok3QsUxoTM7391aOvWs4sWsC+yxiELzgJBhh9X3+Vk6gK/Yc1/t+gGVwFogzH2nxHoiGBC97V4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774034861; c=relaxed/simple; bh=E7IvwqT01r9Y9AARhPTA4kVsR7QTb37BUUQJU1OMnqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n9esIll7Jx77focRasGIWkfZl2ytIttCbVTksJ4jQz2lMch9YSUj+Myrp0rejKAhl0g3IhgvRNWc8aiTXFPyMbwcyp8rYpj45mm00GrR2rgLAZEKz5RAGgMW7a66zwGAnQBfrAqNbgpTKxdt61wxkG16n5GeKhlUkjG38J+ud3I= 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=bTHP6NNO; arc=none smtp.client-ip=209.85.167.180 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="bTHP6NNO" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-466f59dbe4bso486629b6e.0 for ; Fri, 20 Mar 2026 12:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774034859; x=1774639659; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lQz9gXtG0BjRbamDLXajf4zSV33YchOog2Zf6fZXOug=; b=bTHP6NNOOOBWwNzOYVSLxqxd3JWxnfEPnUL9p5qSoS8xWh/o3/wwoD3ZifS3M9zupP UoUdsWpEKcGkX8bDy1Xq/zb64gDbTw9B7+8BUIEoLUzuKMcKCEgP7/WsPt/KTLFUFi60 OZucRlE7qbhRO7/loFA0uIvvJOLn2v+MSx6ULqiY9rwIhi8sNvJuN4YK0L/PSeCFOPog KNlrPg57brPtAbmHDwrXSFcHjGFStEAU2K4B3WTxxkzT9OQlkN940QtIMMjYGpW/tvr8 tadkWRTmOdj14o2yXSphyGdGmOOr2/QGbDQUrncyV4FQ+EqOJtcz2myym4FFIjmBwQ0z 7Kzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774034859; x=1774639659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lQz9gXtG0BjRbamDLXajf4zSV33YchOog2Zf6fZXOug=; b=mT++Y94b0KOVhKzcjPv9Ccgh0q8tXJyC0FSUKAeW2e2you4eq1qw7BHGlUVkUALUXh 3lINwNbjzMFldzW1lO/LqIh+ZjISdprlQdaOEAl3yMSlA0zyAivU9rcjLdkhJ2yMja6n 6B34R6fx3jYesTUeOWWFRR6jkIF5E0Jx2ZGloQb/0jTh0WAATJeqRdME/hfI1ijAVW+d j/kO5imM+12mDsh6eLM9El1v6wUm7XXmkiWGFJVRP64YwuZKn91Qpb6hMpo14iPPVUqE S5U+J1jUVei/EQ5SDPB0Z0sXrLFDQCncalWqmA5QcJr/1YgzkMU4AIaNeFrWSZZmXsTB jQaA== X-Forwarded-Encrypted: i=1; AJvYcCVGkO8tZIKMvnbiqOn/YRKxJwwR+z8u/4aH1f/vmSUfGj2Kn8+3H9pPhwHE17VVVyIh21FR4aTsKA==@vger.kernel.org X-Gm-Message-State: AOJu0Ywaj99wUl1VWYlcnyoxDmJtDJtVdv/ld4j1wyW0LhPISXOaG1F0 zYngDSNfFNUHo+f6MOKWTV9ePpXevwqbfWIu1HlapvbCNExxiU/L4XLG X-Gm-Gg: ATEYQzyXlLLZm/Dypr8yYC7p1nr5LMg1lyZumd3T3hUggcwnZYyAr+U5GCpifUj7olZ mhFHNelGzmmjyPWgFCGzQh3YdIVhi9jY4isOURgfbMIibbE5oLGEmz8qds9efGBO+cKo8FwCiIL EXQ3StiNJaudq5ZBq/bn27yN1YYZ5DVPPprTFGNOAiPrOsKgoQVQEZh+yfLkf5SDhNfzKSslrXf y5jgJnQ98PD+WnbQCgJ7jyqhI01MOtBeS7QqxJ4m2cNR4NoMjgckjJxBMNZwtcnU2KCpM4Lu6up M6gEnNp4CdV/2KVLThJY7/Y3FLvopFz3+wTZqNjk170qNP54xDmcGTuzwForztyFaHggoPZQjmY r/gAQXaXjc98YI2T741OGNWL7sGOj65SqJCuyOy/P+7jD20HbqH1+yuExGsGuhJMylotiRk5O0Y Hrx1fS1sgSQ2umtxj2gjVRs00yEioDQ94hpZiGItRG6m135Q== X-Received: by 2002:a05:6808:1645:b0:462:dc57:f8ba with SMTP id 5614622812f47-467e5f095d0mr2364034b6e.27.1774034859050; Fri, 20 Mar 2026 12:27:39 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:51::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-41c14ddbca8sm2951988fac.15.2026.03.20.12.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Mar 2026 12:27:38 -0700 (PDT) From: Nhat Pham To: kasong@tencent.com Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org, apopple@nvidia.com, axelrasmussen@google.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, bhe@redhat.com, byungchul@sk.com, cgroups@vger.kernel.org, chengming.zhou@linux.dev, chrisl@kernel.org, corbet@lwn.net, david@kernel.org, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, hughd@google.com, jannh@google.com, joshua.hahnjy@gmail.com, lance.yang@linux.dev, lenb@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pm@vger.kernel.org, lorenzo.stoakes@oracle.com, matthew.brost@intel.com, mhocko@suse.com, muchun.song@linux.dev, npache@redhat.com, nphamcs@gmail.com, pavel@kernel.org, peterx@redhat.com, peterz@infradead.org, pfalcato@suse.de, rafael@kernel.org, rakie.kim@sk.com, roman.gushchin@linux.dev, rppt@kernel.org, ryan.roberts@arm.com, shakeel.butt@linux.dev, shikemeng@huaweicloud.com, surenb@google.com, tglx@kernel.org, vbabka@suse.cz, weixugc@google.com, ying.huang@linux.alibaba.com, yosry.ahmed@linux.dev, yuanchu@google.com, zhengqi.arch@bytedance.com, ziy@nvidia.com, kernel-team@meta.com, riel@surriel.com Subject: [PATCH v5 02/21] swap: rearrange the swap header file Date: Fri, 20 Mar 2026 12:27:16 -0700 Message-ID: <20260320192735.748051-3-nphamcs@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260320192735.748051-1-nphamcs@gmail.com> References: <20260320192735.748051-1-nphamcs@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In the swap header file (include/linux/swap.h), group the swap API into the following categories: 1. Lifecycle swap functions (i.e the function that changes the reference count of the swap entry). 2. Swap cache API. 3. Physical swapfile allocator and swap device API. Also remove extern in the functions that are rearranged. This is purely a clean up. No functional change intended. Signed-off-by: Nhat Pham --- include/linux/swap.h | 53 +++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 38ca3df687160..aa29d8ac542d1 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -423,20 +423,34 @@ extern void __meminit kswapd_stop(int nid); #ifdef CONFIG_SWAP -int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page, - unsigned long nr_pages, sector_t start_block); -int generic_swapfile_activate(struct swap_info_struct *, struct file *, - sector_t *); - +/* Lifecycle swap API (mm/swapfile.c) */ +int folio_alloc_swap(struct folio *folio); +bool folio_free_swap(struct folio *folio); +void put_swap_folio(struct folio *folio, swp_entry_t entry); +void swap_shmem_alloc(swp_entry_t, int); +int swap_duplicate(swp_entry_t); +int swapcache_prepare(swp_entry_t entry, int nr); +void swap_free_nr(swp_entry_t entry, int nr_pages); +void free_swap_and_cache_nr(swp_entry_t entry, int nr); +int __swap_count(swp_entry_t entry); +bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t entry); +int swp_swapcount(swp_entry_t entry); + +/* Swap cache API (mm/swap_state.c) */ static inline unsigned long total_swapcache_pages(void) { return global_node_page_state(NR_SWAPCACHE); } - -void free_swap_cache(struct folio *folio); void free_folio_and_swap_cache(struct folio *folio); void free_pages_and_swap_cache(struct encoded_page **, int); -/* linux/mm/swapfile.c */ +void free_swap_cache(struct folio *folio); + +/* Physical swap allocator and swap device API (mm/swapfile.c) */ +int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page, + unsigned long nr_pages, sector_t start_block); +int generic_swapfile_activate(struct swap_info_struct *, struct file *, + sector_t *); + extern atomic_long_t nr_swap_pages; extern long total_swap_pages; extern atomic_t nr_rotate_swap; @@ -452,26 +466,15 @@ static inline long get_nr_swap_pages(void) return atomic_long_read(&nr_swap_pages); } -extern void si_swapinfo(struct sysinfo *); -int folio_alloc_swap(struct folio *folio); -bool folio_free_swap(struct folio *folio); -void put_swap_folio(struct folio *folio, swp_entry_t entry); -extern swp_entry_t get_swap_page_of_type(int); -extern int add_swap_count_continuation(swp_entry_t, gfp_t); -extern void swap_shmem_alloc(swp_entry_t, int); -extern int swap_duplicate(swp_entry_t); -extern int swapcache_prepare(swp_entry_t entry, int nr); -extern void swap_free_nr(swp_entry_t entry, int nr_pages); -extern void free_swap_and_cache_nr(swp_entry_t entry, int nr); +void si_swapinfo(struct sysinfo *); +swp_entry_t get_swap_page_of_type(int); +int add_swap_count_continuation(swp_entry_t, gfp_t); int swap_type_of(dev_t device, sector_t offset); int find_first_swap(dev_t *device); -extern unsigned int count_swap_pages(int, int); -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); +unsigned int count_swap_pages(int, int); +sector_t swapdev_block(int, pgoff_t); struct backing_dev_info; -extern struct swap_info_struct *get_swap_device(swp_entry_t entry); +struct swap_info_struct *get_swap_device(swp_entry_t entry); sector_t swap_folio_sector(struct folio *folio); static inline void put_swap_device(struct swap_info_struct *si) -- 2.52.0