diff mbox series

[v2,05/13] mm, swap: clean up device availability check

Message ID 20241224143811.33462-6-ryncsn@gmail.com (mailing list archive)
State New
Headers show
Series mm, swap: rework of swap allocator locks | expand

Commit Message

Kairui Song Dec. 24, 2024, 2:38 p.m. UTC
From: Kairui Song <kasong@tencent.com>

Remove highest_bit and lowest_bit. After the HDD allocation path
has been removed, the only purpose of these two fields is to determine
whether the device is full or not, which can instead be determined
by checking the inuse_pages.

Signed-off-by: Kairui Song <kasong@tencent.com>
---
 fs/btrfs/inode.c     |  1 -
 fs/iomap/swapfile.c  |  1 -
 include/linux/swap.h |  2 --
 mm/page_io.c         |  1 -
 mm/swapfile.c        | 38 ++++++++------------------------------
 5 files changed, 8 insertions(+), 35 deletions(-)

Comments

kernel test robot Dec. 24, 2024, 6:48 p.m. UTC | #1
Hi Kairui,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Kairui-Song/mm-swap-minor-clean-up-for-swap-entry-allocation/20241224-224136
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241224143811.33462-6-ryncsn%40gmail.com
patch subject: [PATCH v2 05/13] mm, swap: clean up device availability check
config: arm64-randconfig-001-20241224 (https://download.01.org/0day-ci/archive/20241225/202412250203.RvEcTtUz-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241225/202412250203.RvEcTtUz-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412250203.RvEcTtUz-lkp@intel.com/

All errors (new ones prefixed by >>):

   fs/f2fs/data.c: In function 'check_swap_activate':
>> fs/f2fs/data.c:4046:12: error: 'struct swap_info_struct' has no member named 'highest_bit'
    4046 |         sis->highest_bit = cur_lblock - 1;
         |            ^~


vim +4046 fs/f2fs/data.c

859fca6b706e00 Chao Yu              2021-05-26  3940  
0b8fc00601c0d8 Chao Yu              2021-05-26  3941  static int check_swap_activate(struct swap_info_struct *sis,
af4b6b8edf6aad Chao Yu              2020-10-12  3942  				struct file *swap_file, sector_t *span)
af4b6b8edf6aad Chao Yu              2020-10-12  3943  {
af4b6b8edf6aad Chao Yu              2020-10-12  3944  	struct address_space *mapping = swap_file->f_mapping;
af4b6b8edf6aad Chao Yu              2020-10-12  3945  	struct inode *inode = mapping->host;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3946  	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
aa4074e8fec4d2 Wu Bo                2024-04-28  3947  	block_t cur_lblock;
aa4074e8fec4d2 Wu Bo                2024-04-28  3948  	block_t last_lblock;
aa4074e8fec4d2 Wu Bo                2024-04-28  3949  	block_t pblock;
aa4074e8fec4d2 Wu Bo                2024-04-28  3950  	block_t lowest_pblock = -1;
aa4074e8fec4d2 Wu Bo                2024-04-28  3951  	block_t highest_pblock = 0;
af4b6b8edf6aad Chao Yu              2020-10-12  3952  	int nr_extents = 0;
aa4074e8fec4d2 Wu Bo                2024-04-28  3953  	unsigned int nr_pblocks;
859fca6b706e00 Chao Yu              2021-05-26  3954  	unsigned int blks_per_sec = BLKS_PER_SEC(sbi);
ca298241bc2293 Jaegeuk Kim          2021-05-11  3955  	unsigned int not_aligned = 0;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3956  	int ret = 0;
af4b6b8edf6aad Chao Yu              2020-10-12  3957  
af4b6b8edf6aad Chao Yu              2020-10-12  3958  	/*
af4b6b8edf6aad Chao Yu              2020-10-12  3959  	 * Map all the blocks into the extent list.  This code doesn't try
af4b6b8edf6aad Chao Yu              2020-10-12  3960  	 * to be very smart.
af4b6b8edf6aad Chao Yu              2020-10-12  3961  	 */
af4b6b8edf6aad Chao Yu              2020-10-12  3962  	cur_lblock = 0;
7461f370941802 Chao Yu              2024-11-08  3963  	last_lblock = F2FS_BYTES_TO_BLK(i_size_read(inode));
af4b6b8edf6aad Chao Yu              2020-10-12  3964  
1da66103837077 huangjianan@oppo.com 2021-02-27  3965  	while (cur_lblock < last_lblock && cur_lblock < sis->max) {
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3966  		struct f2fs_map_blocks map;
859fca6b706e00 Chao Yu              2021-05-26  3967  retry:
af4b6b8edf6aad Chao Yu              2020-10-12  3968  		cond_resched();
af4b6b8edf6aad Chao Yu              2020-10-12  3969  
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3970  		memset(&map, 0, sizeof(map));
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3971  		map.m_lblk = cur_lblock;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3972  		map.m_len = last_lblock - cur_lblock;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3973  		map.m_next_pgofs = NULL;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3974  		map.m_next_extent = NULL;
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3975  		map.m_seg_type = NO_CHECK_TYPE;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3976  		map.m_may_create = false;
af4b6b8edf6aad Chao Yu              2020-10-12  3977  
cd8fc5226bef3a Christoph Hellwig    2022-11-28  3978  		ret = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_FIEMAP);
af4b6b8edf6aad Chao Yu              2020-10-12  3979  		if (ret)
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3980  			goto out;
af4b6b8edf6aad Chao Yu              2020-10-12  3981  
af4b6b8edf6aad Chao Yu              2020-10-12  3982  		/* hole */
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3983  		if (!(map.m_flags & F2FS_MAP_FLAGS)) {
833dcd35453713 Joe Perches          2021-05-26  3984  			f2fs_err(sbi, "Swapfile has holes");
f395183f9544ba Jaegeuk Kim          2021-05-12  3985  			ret = -EINVAL;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3986  			goto out;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3987  		}
af4b6b8edf6aad Chao Yu              2020-10-12  3988  
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3989  		pblock = map.m_pblk;
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3990  		nr_pblocks = map.m_len;
af4b6b8edf6aad Chao Yu              2020-10-12  3991  
aa4074e8fec4d2 Wu Bo                2024-04-28  3992  		if ((pblock - SM_I(sbi)->main_blkaddr) % blks_per_sec ||
aa4074e8fec4d2 Wu Bo                2024-04-28  3993  				nr_pblocks % blks_per_sec ||
9703d69d9d153b Daeho Jeong          2024-02-13  3994  				!f2fs_valid_pinned_area(sbi, pblock)) {
9703d69d9d153b Daeho Jeong          2024-02-13  3995  			bool last_extent = false;
9703d69d9d153b Daeho Jeong          2024-02-13  3996  
ca298241bc2293 Jaegeuk Kim          2021-05-11  3997  			not_aligned++;
859fca6b706e00 Chao Yu              2021-05-26  3998  
859fca6b706e00 Chao Yu              2021-05-26  3999  			nr_pblocks = roundup(nr_pblocks, blks_per_sec);
859fca6b706e00 Chao Yu              2021-05-26  4000  			if (cur_lblock + nr_pblocks > sis->max)
859fca6b706e00 Chao Yu              2021-05-26  4001  				nr_pblocks -= blks_per_sec;
859fca6b706e00 Chao Yu              2021-05-26  4002  
859fca6b706e00 Chao Yu              2021-05-26  4003  			/* this extent is last one */
9703d69d9d153b Daeho Jeong          2024-02-13  4004  			if (!nr_pblocks) {
9703d69d9d153b Daeho Jeong          2024-02-13  4005  				nr_pblocks = last_lblock - cur_lblock;
9703d69d9d153b Daeho Jeong          2024-02-13  4006  				last_extent = true;
ca298241bc2293 Jaegeuk Kim          2021-05-11  4007  			}
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  4008  
859fca6b706e00 Chao Yu              2021-05-26  4009  			ret = f2fs_migrate_blocks(inode, cur_lblock,
859fca6b706e00 Chao Yu              2021-05-26  4010  							nr_pblocks);
9703d69d9d153b Daeho Jeong          2024-02-13  4011  			if (ret) {
9703d69d9d153b Daeho Jeong          2024-02-13  4012  				if (ret == -ENOENT)
9703d69d9d153b Daeho Jeong          2024-02-13  4013  					ret = -EINVAL;
859fca6b706e00 Chao Yu              2021-05-26  4014  				goto out;
9703d69d9d153b Daeho Jeong          2024-02-13  4015  			}
9703d69d9d153b Daeho Jeong          2024-02-13  4016  
9703d69d9d153b Daeho Jeong          2024-02-13  4017  			if (!last_extent)
859fca6b706e00 Chao Yu              2021-05-26  4018  				goto retry;
859fca6b706e00 Chao Yu              2021-05-26  4019  		}
9703d69d9d153b Daeho Jeong          2024-02-13  4020  
af4b6b8edf6aad Chao Yu              2020-10-12  4021  		if (cur_lblock + nr_pblocks >= sis->max)
af4b6b8edf6aad Chao Yu              2020-10-12  4022  			nr_pblocks = sis->max - cur_lblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4023  
af4b6b8edf6aad Chao Yu              2020-10-12  4024  		if (cur_lblock) {	/* exclude the header page */
af4b6b8edf6aad Chao Yu              2020-10-12  4025  			if (pblock < lowest_pblock)
af4b6b8edf6aad Chao Yu              2020-10-12  4026  				lowest_pblock = pblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4027  			if (pblock + nr_pblocks - 1 > highest_pblock)
af4b6b8edf6aad Chao Yu              2020-10-12  4028  				highest_pblock = pblock + nr_pblocks - 1;
af4b6b8edf6aad Chao Yu              2020-10-12  4029  		}
af4b6b8edf6aad Chao Yu              2020-10-12  4030  
af4b6b8edf6aad Chao Yu              2020-10-12  4031  		/*
af4b6b8edf6aad Chao Yu              2020-10-12  4032  		 * We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
af4b6b8edf6aad Chao Yu              2020-10-12  4033  		 */
af4b6b8edf6aad Chao Yu              2020-10-12  4034  		ret = add_swap_extent(sis, cur_lblock, nr_pblocks, pblock);
af4b6b8edf6aad Chao Yu              2020-10-12  4035  		if (ret < 0)
af4b6b8edf6aad Chao Yu              2020-10-12  4036  			goto out;
af4b6b8edf6aad Chao Yu              2020-10-12  4037  		nr_extents += ret;
af4b6b8edf6aad Chao Yu              2020-10-12  4038  		cur_lblock += nr_pblocks;
af4b6b8edf6aad Chao Yu              2020-10-12  4039  	}
af4b6b8edf6aad Chao Yu              2020-10-12  4040  	ret = nr_extents;
af4b6b8edf6aad Chao Yu              2020-10-12  4041  	*span = 1 + highest_pblock - lowest_pblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4042  	if (cur_lblock == 0)
af4b6b8edf6aad Chao Yu              2020-10-12  4043  		cur_lblock = 1;	/* force Empty message */
af4b6b8edf6aad Chao Yu              2020-10-12  4044  	sis->max = cur_lblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4045  	sis->pages = cur_lblock - 1;
af4b6b8edf6aad Chao Yu              2020-10-12 @4046  	sis->highest_bit = cur_lblock - 1;
af4b6b8edf6aad Chao Yu              2020-10-12  4047  out:
859fca6b706e00 Chao Yu              2021-05-26  4048  	if (not_aligned)
d7e9a9037de27b Daniel Rosenberg     2023-10-02  4049  		f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)",
859fca6b706e00 Chao Yu              2021-05-26  4050  			  not_aligned, blks_per_sec * F2FS_BLKSIZE);
af4b6b8edf6aad Chao Yu              2020-10-12  4051  	return ret;
af4b6b8edf6aad Chao Yu              2020-10-12  4052  }
af4b6b8edf6aad Chao Yu              2020-10-12  4053
kernel test robot Dec. 24, 2024, 7:08 p.m. UTC | #2
Hi Kairui,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Kairui-Song/mm-swap-minor-clean-up-for-swap-entry-allocation/20241224-224136
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241224143811.33462-6-ryncsn%40gmail.com
patch subject: [PATCH v2 05/13] mm, swap: clean up device availability check
config: i386-buildonly-randconfig-001-20241224 (https://download.01.org/0day-ci/archive/20241225/202412250259.S5ew5ZrN-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241225/202412250259.S5ew5ZrN-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412250259.S5ew5ZrN-lkp@intel.com/

All errors (new ones prefixed by >>):

>> fs/f2fs/data.c:4046:7: error: no member named 'highest_bit' in 'struct swap_info_struct'
    4046 |         sis->highest_bit = cur_lblock - 1;
         |         ~~~  ^
   1 error generated.


vim +4046 fs/f2fs/data.c

859fca6b706e00 Chao Yu              2021-05-26  3940  
0b8fc00601c0d8 Chao Yu              2021-05-26  3941  static int check_swap_activate(struct swap_info_struct *sis,
af4b6b8edf6aad Chao Yu              2020-10-12  3942  				struct file *swap_file, sector_t *span)
af4b6b8edf6aad Chao Yu              2020-10-12  3943  {
af4b6b8edf6aad Chao Yu              2020-10-12  3944  	struct address_space *mapping = swap_file->f_mapping;
af4b6b8edf6aad Chao Yu              2020-10-12  3945  	struct inode *inode = mapping->host;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3946  	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
aa4074e8fec4d2 Wu Bo                2024-04-28  3947  	block_t cur_lblock;
aa4074e8fec4d2 Wu Bo                2024-04-28  3948  	block_t last_lblock;
aa4074e8fec4d2 Wu Bo                2024-04-28  3949  	block_t pblock;
aa4074e8fec4d2 Wu Bo                2024-04-28  3950  	block_t lowest_pblock = -1;
aa4074e8fec4d2 Wu Bo                2024-04-28  3951  	block_t highest_pblock = 0;
af4b6b8edf6aad Chao Yu              2020-10-12  3952  	int nr_extents = 0;
aa4074e8fec4d2 Wu Bo                2024-04-28  3953  	unsigned int nr_pblocks;
859fca6b706e00 Chao Yu              2021-05-26  3954  	unsigned int blks_per_sec = BLKS_PER_SEC(sbi);
ca298241bc2293 Jaegeuk Kim          2021-05-11  3955  	unsigned int not_aligned = 0;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3956  	int ret = 0;
af4b6b8edf6aad Chao Yu              2020-10-12  3957  
af4b6b8edf6aad Chao Yu              2020-10-12  3958  	/*
af4b6b8edf6aad Chao Yu              2020-10-12  3959  	 * Map all the blocks into the extent list.  This code doesn't try
af4b6b8edf6aad Chao Yu              2020-10-12  3960  	 * to be very smart.
af4b6b8edf6aad Chao Yu              2020-10-12  3961  	 */
af4b6b8edf6aad Chao Yu              2020-10-12  3962  	cur_lblock = 0;
7461f370941802 Chao Yu              2024-11-08  3963  	last_lblock = F2FS_BYTES_TO_BLK(i_size_read(inode));
af4b6b8edf6aad Chao Yu              2020-10-12  3964  
1da66103837077 huangjianan@oppo.com 2021-02-27  3965  	while (cur_lblock < last_lblock && cur_lblock < sis->max) {
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3966  		struct f2fs_map_blocks map;
859fca6b706e00 Chao Yu              2021-05-26  3967  retry:
af4b6b8edf6aad Chao Yu              2020-10-12  3968  		cond_resched();
af4b6b8edf6aad Chao Yu              2020-10-12  3969  
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3970  		memset(&map, 0, sizeof(map));
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3971  		map.m_lblk = cur_lblock;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3972  		map.m_len = last_lblock - cur_lblock;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3973  		map.m_next_pgofs = NULL;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3974  		map.m_next_extent = NULL;
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3975  		map.m_seg_type = NO_CHECK_TYPE;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3976  		map.m_may_create = false;
af4b6b8edf6aad Chao Yu              2020-10-12  3977  
cd8fc5226bef3a Christoph Hellwig    2022-11-28  3978  		ret = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_FIEMAP);
af4b6b8edf6aad Chao Yu              2020-10-12  3979  		if (ret)
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3980  			goto out;
af4b6b8edf6aad Chao Yu              2020-10-12  3981  
af4b6b8edf6aad Chao Yu              2020-10-12  3982  		/* hole */
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3983  		if (!(map.m_flags & F2FS_MAP_FLAGS)) {
833dcd35453713 Joe Perches          2021-05-26  3984  			f2fs_err(sbi, "Swapfile has holes");
f395183f9544ba Jaegeuk Kim          2021-05-12  3985  			ret = -EINVAL;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3986  			goto out;
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  3987  		}
af4b6b8edf6aad Chao Yu              2020-10-12  3988  
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3989  		pblock = map.m_pblk;
b876f4c94c3d16 Jaegeuk Kim          2020-11-24  3990  		nr_pblocks = map.m_len;
af4b6b8edf6aad Chao Yu              2020-10-12  3991  
aa4074e8fec4d2 Wu Bo                2024-04-28  3992  		if ((pblock - SM_I(sbi)->main_blkaddr) % blks_per_sec ||
aa4074e8fec4d2 Wu Bo                2024-04-28  3993  				nr_pblocks % blks_per_sec ||
9703d69d9d153b Daeho Jeong          2024-02-13  3994  				!f2fs_valid_pinned_area(sbi, pblock)) {
9703d69d9d153b Daeho Jeong          2024-02-13  3995  			bool last_extent = false;
9703d69d9d153b Daeho Jeong          2024-02-13  3996  
ca298241bc2293 Jaegeuk Kim          2021-05-11  3997  			not_aligned++;
859fca6b706e00 Chao Yu              2021-05-26  3998  
859fca6b706e00 Chao Yu              2021-05-26  3999  			nr_pblocks = roundup(nr_pblocks, blks_per_sec);
859fca6b706e00 Chao Yu              2021-05-26  4000  			if (cur_lblock + nr_pblocks > sis->max)
859fca6b706e00 Chao Yu              2021-05-26  4001  				nr_pblocks -= blks_per_sec;
859fca6b706e00 Chao Yu              2021-05-26  4002  
859fca6b706e00 Chao Yu              2021-05-26  4003  			/* this extent is last one */
9703d69d9d153b Daeho Jeong          2024-02-13  4004  			if (!nr_pblocks) {
9703d69d9d153b Daeho Jeong          2024-02-13  4005  				nr_pblocks = last_lblock - cur_lblock;
9703d69d9d153b Daeho Jeong          2024-02-13  4006  				last_extent = true;
ca298241bc2293 Jaegeuk Kim          2021-05-11  4007  			}
36e4d95891ed37 huangjianan@oppo.com 2021-03-01  4008  
859fca6b706e00 Chao Yu              2021-05-26  4009  			ret = f2fs_migrate_blocks(inode, cur_lblock,
859fca6b706e00 Chao Yu              2021-05-26  4010  							nr_pblocks);
9703d69d9d153b Daeho Jeong          2024-02-13  4011  			if (ret) {
9703d69d9d153b Daeho Jeong          2024-02-13  4012  				if (ret == -ENOENT)
9703d69d9d153b Daeho Jeong          2024-02-13  4013  					ret = -EINVAL;
859fca6b706e00 Chao Yu              2021-05-26  4014  				goto out;
9703d69d9d153b Daeho Jeong          2024-02-13  4015  			}
9703d69d9d153b Daeho Jeong          2024-02-13  4016  
9703d69d9d153b Daeho Jeong          2024-02-13  4017  			if (!last_extent)
859fca6b706e00 Chao Yu              2021-05-26  4018  				goto retry;
859fca6b706e00 Chao Yu              2021-05-26  4019  		}
9703d69d9d153b Daeho Jeong          2024-02-13  4020  
af4b6b8edf6aad Chao Yu              2020-10-12  4021  		if (cur_lblock + nr_pblocks >= sis->max)
af4b6b8edf6aad Chao Yu              2020-10-12  4022  			nr_pblocks = sis->max - cur_lblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4023  
af4b6b8edf6aad Chao Yu              2020-10-12  4024  		if (cur_lblock) {	/* exclude the header page */
af4b6b8edf6aad Chao Yu              2020-10-12  4025  			if (pblock < lowest_pblock)
af4b6b8edf6aad Chao Yu              2020-10-12  4026  				lowest_pblock = pblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4027  			if (pblock + nr_pblocks - 1 > highest_pblock)
af4b6b8edf6aad Chao Yu              2020-10-12  4028  				highest_pblock = pblock + nr_pblocks - 1;
af4b6b8edf6aad Chao Yu              2020-10-12  4029  		}
af4b6b8edf6aad Chao Yu              2020-10-12  4030  
af4b6b8edf6aad Chao Yu              2020-10-12  4031  		/*
af4b6b8edf6aad Chao Yu              2020-10-12  4032  		 * We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
af4b6b8edf6aad Chao Yu              2020-10-12  4033  		 */
af4b6b8edf6aad Chao Yu              2020-10-12  4034  		ret = add_swap_extent(sis, cur_lblock, nr_pblocks, pblock);
af4b6b8edf6aad Chao Yu              2020-10-12  4035  		if (ret < 0)
af4b6b8edf6aad Chao Yu              2020-10-12  4036  			goto out;
af4b6b8edf6aad Chao Yu              2020-10-12  4037  		nr_extents += ret;
af4b6b8edf6aad Chao Yu              2020-10-12  4038  		cur_lblock += nr_pblocks;
af4b6b8edf6aad Chao Yu              2020-10-12  4039  	}
af4b6b8edf6aad Chao Yu              2020-10-12  4040  	ret = nr_extents;
af4b6b8edf6aad Chao Yu              2020-10-12  4041  	*span = 1 + highest_pblock - lowest_pblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4042  	if (cur_lblock == 0)
af4b6b8edf6aad Chao Yu              2020-10-12  4043  		cur_lblock = 1;	/* force Empty message */
af4b6b8edf6aad Chao Yu              2020-10-12  4044  	sis->max = cur_lblock;
af4b6b8edf6aad Chao Yu              2020-10-12  4045  	sis->pages = cur_lblock - 1;
af4b6b8edf6aad Chao Yu              2020-10-12 @4046  	sis->highest_bit = cur_lblock - 1;
af4b6b8edf6aad Chao Yu              2020-10-12  4047  out:
859fca6b706e00 Chao Yu              2021-05-26  4048  	if (not_aligned)
d7e9a9037de27b Daniel Rosenberg     2023-10-02  4049  		f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)",
859fca6b706e00 Chao Yu              2021-05-26  4050  			  not_aligned, blks_per_sec * F2FS_BLKSIZE);
af4b6b8edf6aad Chao Yu              2020-10-12  4051  	return ret;
af4b6b8edf6aad Chao Yu              2020-10-12  4052  }
af4b6b8edf6aad Chao Yu              2020-10-12  4053
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 488edca8333a..a1ba78afab2c 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -10044,7 +10044,6 @@  static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
 	*span = bsi.highest_ppage - bsi.lowest_ppage + 1;
 	sis->max = bsi.nr_pages;
 	sis->pages = bsi.nr_pages - 1;
-	sis->highest_bit = bsi.nr_pages - 1;
 	return bsi.nr_extents;
 }
 #else
diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c
index 5fc0ac36dee3..b90d0eda9e51 100644
--- a/fs/iomap/swapfile.c
+++ b/fs/iomap/swapfile.c
@@ -189,7 +189,6 @@  int iomap_swapfile_activate(struct swap_info_struct *sis,
 	*pagespan = 1 + isi.highest_ppage - isi.lowest_ppage;
 	sis->max = isi.nr_pages;
 	sis->pages = isi.nr_pages - 1;
-	sis->highest_bit = isi.nr_pages - 1;
 	return isi.nr_extents;
 }
 EXPORT_SYMBOL_GPL(iomap_swapfile_activate);
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 0c681aa5cb98..0c222017b5c6 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -306,8 +306,6 @@  struct swap_info_struct {
 	struct list_head frag_clusters[SWAP_NR_ORDERS];
 					/* list of cluster that are fragmented or contented */
 	unsigned int frag_cluster_nr[SWAP_NR_ORDERS];
-	unsigned int lowest_bit;	/* index of first free in swap_map */
-	unsigned int highest_bit;	/* index of last free in swap_map */
 	unsigned int pages;		/* total of usable pages of swap */
 	unsigned int inuse_pages;	/* number of those currently in use */
 	struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */
diff --git a/mm/page_io.c b/mm/page_io.c
index 4b4ea8e49cf6..9b983de351f9 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -163,7 +163,6 @@  int generic_swapfile_activate(struct swap_info_struct *sis,
 		page_no = 1;	/* force Empty message */
 	sis->max = page_no;
 	sis->pages = page_no - 1;
-	sis->highest_bit = page_no - 1;
 out:
 	return ret;
 bad_bmap:
diff --git a/mm/swapfile.c b/mm/swapfile.c
index d0e5b9fa0c48..7963a0c646a4 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -55,7 +55,7 @@  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
 static void free_swap_count_continuations(struct swap_info_struct *);
 static void swap_entry_range_free(struct swap_info_struct *si, swp_entry_t entry,
 				  unsigned int nr_pages);
-static void swap_range_alloc(struct swap_info_struct *si, unsigned long offset,
+static void swap_range_alloc(struct swap_info_struct *si,
 			     unsigned int nr_entries);
 static bool folio_swapcache_freeable(struct folio *folio);
 static struct swap_cluster_info *lock_cluster(struct swap_info_struct *si,
@@ -650,7 +650,7 @@  static bool cluster_alloc_range(struct swap_info_struct *si, struct swap_cluster
 	}
 
 	memset(si->swap_map + start, usage, nr_pages);
-	swap_range_alloc(si, start, nr_pages);
+	swap_range_alloc(si, nr_pages);
 	ci->count += nr_pages;
 
 	if (ci->count == SWAPFILE_CLUSTER) {
@@ -888,19 +888,11 @@  static void del_from_avail_list(struct swap_info_struct *si)
 	spin_unlock(&swap_avail_lock);
 }
 
-static void swap_range_alloc(struct swap_info_struct *si, unsigned long offset,
+static void swap_range_alloc(struct swap_info_struct *si,
 			     unsigned int nr_entries)
 {
-	unsigned int end = offset + nr_entries - 1;
-
-	if (offset == si->lowest_bit)
-		si->lowest_bit += nr_entries;
-	if (end == si->highest_bit)
-		WRITE_ONCE(si->highest_bit, si->highest_bit - nr_entries);
 	WRITE_ONCE(si->inuse_pages, si->inuse_pages + nr_entries);
 	if (si->inuse_pages == si->pages) {
-		si->lowest_bit = si->max;
-		si->highest_bit = 0;
 		del_from_avail_list(si);
 
 		if (si->cluster_info && vm_swap_full())
@@ -933,15 +925,8 @@  static void swap_range_free(struct swap_info_struct *si, unsigned long offset,
 	for (i = 0; i < nr_entries; i++)
 		clear_bit(offset + i, si->zeromap);
 
-	if (offset < si->lowest_bit)
-		si->lowest_bit = offset;
-	if (end > si->highest_bit) {
-		bool was_full = !si->highest_bit;
-
-		WRITE_ONCE(si->highest_bit, end);
-		if (was_full && (si->flags & SWP_WRITEOK))
-			add_to_avail_list(si);
-	}
+	if (si->inuse_pages == si->pages)
+		add_to_avail_list(si);
 	if (si->flags & SWP_BLKDEV)
 		swap_slot_free_notify =
 			si->bdev->bd_disk->fops->swap_slot_free_notify;
@@ -1051,15 +1036,12 @@  int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_order)
 		plist_requeue(&si->avail_lists[node], &swap_avail_heads[node]);
 		spin_unlock(&swap_avail_lock);
 		spin_lock(&si->lock);
-		if (!si->highest_bit || !(si->flags & SWP_WRITEOK)) {
+		if ((si->inuse_pages == si->pages) || !(si->flags & SWP_WRITEOK)) {
 			spin_lock(&swap_avail_lock);
 			if (plist_node_empty(&si->avail_lists[node])) {
 				spin_unlock(&si->lock);
 				goto nextsi;
 			}
-			WARN(!si->highest_bit,
-			     "swap_info %d in list but !highest_bit\n",
-			     si->type);
 			WARN(!(si->flags & SWP_WRITEOK),
 			     "swap_info %d in list but !SWP_WRITEOK\n",
 			     si->type);
@@ -2441,8 +2423,8 @@  static void _enable_swap_info(struct swap_info_struct *si)
 	 */
 	plist_add(&si->list, &swap_active_head);
 
-	/* add to available list iff swap device is not full */
-	if (si->highest_bit)
+	/* add to available list if swap device is not full */
+	if (si->inuse_pages < si->pages)
 		add_to_avail_list(si);
 }
 
@@ -2606,7 +2588,6 @@  SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	drain_mmlist();
 
 	/* wait for anyone still in scan_swap_map_slots */
-	p->highest_bit = 0;		/* cuts scans short */
 	while (p->flags >= SWP_SCANNING) {
 		spin_unlock(&p->lock);
 		spin_unlock(&swap_lock);
@@ -2941,8 +2922,6 @@  static unsigned long read_swap_header(struct swap_info_struct *si,
 		return 0;
 	}
 
-	si->lowest_bit  = 1;
-
 	maxpages = swapfile_maximum_size;
 	last_page = swap_header->info.last_page;
 	if (!last_page) {
@@ -2959,7 +2938,6 @@  static unsigned long read_swap_header(struct swap_info_struct *si,
 		if ((unsigned int)maxpages == 0)
 			maxpages = UINT_MAX;
 	}
-	si->highest_bit = maxpages - 1;
 
 	if (!maxpages)
 		return 0;