Skip to content

Commit 2872bb2

Browse files
yhuang-inteltorvalds
authored andcommitted
mm, swap: avoid lock swap_avail_lock when held cluster lock
Cluster lock is used to protect the swap_cluster_info and corresponding elements in swap_info_struct->swap_map[]. But it is found that now in scan_swap_map_slots(), swap_avail_lock may be acquired when cluster lock is held. This does no good except making the locking more complex and improving the potential locking contention, because the swap_info_struct->lock is used to protect the data structure operated in the code already. Fix this via moving the corresponding operations in scan_swap_map_slots() out of cluster lock. Link: http://lkml.kernel.org/r/20170317064635.12792-3-ying.huang@intel.com Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Acked-by: Tim Chen <tim.c.chen@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0ef017d commit 2872bb2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎mm/swapfile.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
672672
else
673673
goto done;
674674
}
675+
si->swap_map[offset] = usage;
676+
inc_cluster_info_page(si, si->cluster_info, offset);
677+
unlock_cluster(ci);
675678

676679
if (offset == si->lowest_bit)
677680
si->lowest_bit++;
@@ -685,9 +688,6 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
685688
plist_del(&si->avail_list, &swap_avail_head);
686689
spin_unlock(&swap_avail_lock);
687690
}
688-
si->swap_map[offset] = usage;
689-
inc_cluster_info_page(si, si->cluster_info, offset);
690-
unlock_cluster(ci);
691691
si->cluster_next = offset + 1;
692692
slots[n_ret++] = swp_entry(si->type, offset);
693693

0 commit comments

Comments
 (0)