swapfile.c (9d4d8572a539ef807e21c196f145aa365fd52f0e) | swapfile.c (f885056a48ccf4ad4332def91e973f3993fa8695) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * linux/mm/swapfile.c 4 * 5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds 6 * Swap reorganised 29.12.95, Stephen Tweedie 7 */ 8 --- 33 unchanged lines hidden (view full) --- 42 43#include <asm/tlbflush.h> 44#include <linux/swapops.h> 45#include <linux/swap_cgroup.h> 46 47static bool swap_count_continued(struct swap_info_struct *, pgoff_t, 48 unsigned char); 49static void free_swap_count_continuations(struct swap_info_struct *); | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * linux/mm/swapfile.c 4 * 5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds 6 * Swap reorganised 29.12.95, Stephen Tweedie 7 */ 8 --- 33 unchanged lines hidden (view full) --- 42 43#include <asm/tlbflush.h> 44#include <linux/swapops.h> 45#include <linux/swap_cgroup.h> 46 47static bool swap_count_continued(struct swap_info_struct *, pgoff_t, 48 unsigned char); 49static void free_swap_count_continuations(struct swap_info_struct *); |
50static sector_t map_swap_entry(swp_entry_t, struct block_device**); | |
51 52DEFINE_SPINLOCK(swap_lock); 53static unsigned int nr_swapfiles; 54atomic_long_t nr_swap_pages; 55/* 56 * Some modules use swappable objects and may try to swap them out under 57 * memory pressure (via the shrinker). Before doing so, they may wish to 58 * check to see if any swap space is available. --- 1786 unchanged lines hidden (view full) --- 1845} 1846 1847/* 1848 * Get the (PAGE_SIZE) block corresponding to given offset on the swapdev 1849 * corresponding to given index in swap_info (swap type). 1850 */ 1851sector_t swapdev_block(int type, pgoff_t offset) 1852{ | 50 51DEFINE_SPINLOCK(swap_lock); 52static unsigned int nr_swapfiles; 53atomic_long_t nr_swap_pages; 54/* 55 * Some modules use swappable objects and may try to swap them out under 56 * memory pressure (via the shrinker). Before doing so, they may wish to 57 * check to see if any swap space is available. --- 1786 unchanged lines hidden (view full) --- 1844} 1845 1846/* 1847 * Get the (PAGE_SIZE) block corresponding to given offset on the swapdev 1848 * corresponding to given index in swap_info (swap type). 1849 */ 1850sector_t swapdev_block(int type, pgoff_t offset) 1851{ |
1853 struct block_device *bdev; | |
1854 struct swap_info_struct *si = swap_type_to_swap_info(type); | 1852 struct swap_info_struct *si = swap_type_to_swap_info(type); |
1853 struct swap_extent *se; |
|
1855 1856 if (!si || !(si->flags & SWP_WRITEOK)) 1857 return 0; | 1854 1855 if (!si || !(si->flags & SWP_WRITEOK)) 1856 return 0; |
1858 return map_swap_entry(swp_entry(type, offset), &bdev); | 1857 se = offset_to_swap_extent(si, offset); 1858 return se->start_block + (offset - se->start_page); |
1859} 1860 1861/* 1862 * Return either the total number of swap pages of given type, or the number 1863 * of free pages of that type (depending on @free) 1864 * 1865 * This is needed for software suspend 1866 */ --- 410 unchanged lines hidden (view full) --- 2277 return; 2278 spin_lock(&mmlist_lock); 2279 list_for_each_safe(p, next, &init_mm.mmlist) 2280 list_del_init(p); 2281 spin_unlock(&mmlist_lock); 2282} 2283 2284/* | 1859} 1860 1861/* 1862 * Return either the total number of swap pages of given type, or the number 1863 * of free pages of that type (depending on @free) 1864 * 1865 * This is needed for software suspend 1866 */ --- 410 unchanged lines hidden (view full) --- 2277 return; 2278 spin_lock(&mmlist_lock); 2279 list_for_each_safe(p, next, &init_mm.mmlist) 2280 list_del_init(p); 2281 spin_unlock(&mmlist_lock); 2282} 2283 2284/* |
2285 * Use this swapdev's extent info to locate the (PAGE_SIZE) block which 2286 * corresponds to page offset for the specified swap entry. 2287 * Note that the type of this function is sector_t, but it returns page offset 2288 * into the bdev, not sector offset. 2289 */ 2290static sector_t map_swap_entry(swp_entry_t entry, struct block_device **bdev) 2291{ 2292 struct swap_info_struct *sis; 2293 struct swap_extent *se; 2294 pgoff_t offset; 2295 2296 sis = swp_swap_info(entry); 2297 *bdev = sis->bdev; 2298 2299 offset = swp_offset(entry); 2300 se = offset_to_swap_extent(sis, offset); 2301 return se->start_block + (offset - se->start_page); 2302} 2303 2304/* 2305 * Returns the page offset into bdev for the specified page's swap entry. 2306 */ 2307sector_t map_swap_page(struct page *page, struct block_device **bdev) 2308{ 2309 swp_entry_t entry; 2310 entry.val = page_private(page); 2311 return map_swap_entry(entry, bdev); 2312} 2313 2314/* | |
2315 * Free all of a swapdev's extent information 2316 */ 2317static void destroy_swap_extents(struct swap_info_struct *sis) 2318{ 2319 while (!RB_EMPTY_ROOT(&sis->swap_extent_root)) { 2320 struct rb_node *rb = sis->swap_extent_root.rb_node; 2321 struct swap_extent *se = rb_entry(rb, struct swap_extent, rb_node); 2322 --- 1521 unchanged lines hidden --- | 2285 * Free all of a swapdev's extent information 2286 */ 2287static void destroy_swap_extents(struct swap_info_struct *sis) 2288{ 2289 while (!RB_EMPTY_ROOT(&sis->swap_extent_root)) { 2290 struct rb_node *rb = sis->swap_extent_root.rb_node; 2291 struct swap_extent *se = rb_entry(rb, struct swap_extent, rb_node); 2292 --- 1521 unchanged lines hidden --- |