[<prev] [next>] [day] [month] [year] [list]
Message-ID: <8a8d3614-9081-3fff-ebca-011deffc4605@huawei.com>
Date: Fri, 13 May 2022 17:40:01 +0800
From: Miaohe Lin <linmiaohe@...wei.com>
To: Linux-MM <linux-mm@...ck.org>,
linux-kernel <linux-kernel@...r.kernel.org>
CC: Huang Ying <ying.huang@...el.com>,
Matthew Wilcox <willy@...radead.org>, <vbabka@...e.cz>,
Suren Baghdasaryan <surenb@...gle.com>,
Stephen Rothwell <sfr@...b.auug.org.au>, <peterx@...hat.com>,
NeilBrown <neilb@...e.de>,
HORIGUCHI NAOYA <naoya.horiguchi@....com>,
Minchan Kim <minchan@...nel.org>,
David Howells <dhowells@...hat.com>,
David Hildenbrand <david@...hat.com>,
Alistair Popple <apopple@...dia.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"liubo (AW)" <liubo254@...wei.com>,
Miaohe Lin <linmiaohe@...wei.com>
Subject: [Question]: Decision-making swapoff process to fix problem
feasibility
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@...alhost ~]# swapon -s
[root@...alhost ~]# 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@...alhost ~]# swapon /dev/nvme0n1p1
[root@...alhost ~]# swapon -s
Filename Type Size Used Priority
/dev/nvme0n1p1 partition 62914556 0 -2
[root@...alhost ~]# echo 1 > /sys/bus/pci/devices/0000:d8:00.0/remove
[root@...alhost ~]# 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@...alhost ~]# swapon -s
Filename Type Size Used Priority
/dev/nvme0n1p1 partition 62914556 0 -2
[root@...alhost ~]# swapoff /dev/nvme0n1p1
swapoff: /dev/nvme0n1p1: swapoff failed: No such file or directory
[root@...alhost ~]# swapoff -a
[root@...alhost ~]# 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! :)
Powered by blists - more mailing lists