Now, swap_active_head is only used to find a present swap device when trying to swapoff it. In fact, swap_info[] is a short array which is 32 at maximum, and usually the unused one can be reused, so the searching for target mostly only iterates the foremost several used slots. And swapoff is a rarely used operation, efficiency is not so important. Then it's unnecessary to get a plist to make it. Here go by iterating swap_info[] to find the swap device instead of iterating swap_active_head. Signed-off-by: Baoquan He --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 5d71c748a2fe..18b52cc20749 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2641,6 +2641,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) struct inode *inode; struct filename *pathname; int err, found = 0; + unsigned int type; if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -2658,7 +2659,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) mapping = victim->f_mapping; spin_lock(&swap_lock); - plist_for_each_entry(p, &swap_active_head, list) { + for (type = 0; type < nr_swapfiles; type++) { + p = swap_info[type]; if (p->flags & SWP_WRITEOK) { if (p->swap_file->f_mapping == mapping) { found = 1; -- 2.41.0