[Question]: Decision-making swapoff process to fix problem feasibility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Background:
	When the swap partition is mounted through the swapon command,
	the kernel will create the swap_info_struct data structure
	and initialize it, and save it in the swap_info global array.
	When the swap partition is no longer in use, the disk is
	unloaded through the swapoff command.

	However, if the disk is pulled out after swapon, an error will
	occur when swapoff the disk, causing the swap_info_struct
	data structure to remain in the kernel and cannot be cleared.

Example:
	[root@localhost ~]# swapon -s
	[root@localhost ~]# lsblk
	NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
	sda                8:0    0  1.1T  0 disk
	├─sda1             8:1    0  600M  0 part /boot/efi
	├─sda2             8:2    0    1G  0 part /boot
	└─sda3             8:3    0  1.1T  0 part
	  ├─root 253:0    0   70G  0 lvm  /
	  ├─swap 253:1    0    4G  0 lvm
	  └─home 253:2    0    1T  0 lvm  /home
	nvme0n1          259:0    0  3.6T  0 disk
	└─nvme0n1p1      259:5    0   60G  0 part
	[root@localhost ~]# swapon /dev/nvme0n1p1
	[root@localhost ~]# swapon -s
	Filename                                Type            Size    Used    Priority
	/dev/nvme0n1p1                          partition       62914556        0       -2
	[root@localhost ~]# echo 1 > /sys/bus/pci/devices/0000:d8:00.0/remove
	[root@localhost ~]# lsblk
	NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
	sda                8:0    0  1.1T  0 disk
	├─sda1             8:1    0  600M  0 part /boot/efi
	├─sda2             8:2    0    1G  0 part /boot
	└─sda3             8:3    0  1.1T  0 part
	  ├─root 253:0    0   70G  0 lvm  /
	  ├─swap 253:1    0    4G  0 lvm
	  └─home 253:2    0    1T  0 lvm  /home
	[root@localhost ~]# swapon -s
	Filename                                Type            Size    Used    Priority
	/dev/nvme0n1p1                          partition       62914556        0       -2
	[root@localhost ~]# swapoff /dev/nvme0n1p1
	swapoff: /dev/nvme0n1p1: swapoff failed: No such file or directory
	[root@localhost ~]# swapoff -a
	[root@localhost ~]# swapon -s
	Filename                                Type            Size    Used    Priority
	/dev/nvme0n1p1                          partition       62914556        0       -2
	
Reason:
	In the swapoff command, the device is acquired in the following ways,
	but the device has been unplugged at this time, causing the "victim"
	acquisition to fail, thus returning an error directly.
	And the invalid swap_info_struct cannot be effectively released.

	sys_swapoff

	pathname = getname(specialfile);
	if (IS_ERR(pathname))
		return PTR_ERR(pathname);

	victim = file_open_name(pathname, O_RDWR|O_LARGEFILE, 0);
	err = PTR_ERR(victim);
	if (IS_ERR(victim))
		goto out;

Possible Solution:
	In order to solve the above problems, by adding traversal of
	swap_avail_heads (available swap partitions) in the swapoff
	and swapon processes, find the swap_info_struct whose disk
	partition has been unplugged, and release resources.

	swapoff/swapon process:
	
	...
	spin_lock(&swap_lock);
	plist_for_each_entry(p, &swap_active_head, list) {
			if (p->flags & SWP_WRITEOK) {
					swap_file = p->swap_file;
					swap_name = d_path(&swap_file->f_path, tmp, PAGE_SIZE);

					if (strstr(swap_name, "deleted")) {
							found = 1;
							break;
					}
			}
	}
	spin_unlock(&swap_lock);
	...
	/* do the resource release process */
	
	The reason why the judgment of unavailable swap information is also
	added to the swapon process is that the swapoff is executed by the
	user, and the timing is uncontrollable.
	The system supports swapon multiple disks, and the unavailable swap
	can be deleted at the same time as swapon is mounted.

It will be very appreciative if anyone can give any suggestions and comment! Thanks a lot in advance! :)




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux