On Mon, May 29, 2023 at 02:13:51PM +0800, Huang Ying wrote: > get/put_swap_device() are added to __swap_count() in commit > eb085574a752 ("mm, swap: fix race between swapoff and some swap > operations"). Later, in commit 2799e77529c2 ("swap: fix > do_swap_page() race with swapoff"), get/put_swap_device() are added to > do_swap_page(). And they enclose the only call site of > __swap_count(). So, it's safe to remove get/put_swap_device() in > __swap_count() now. > > Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx> > Reviewed-by: Yosry Ahmed <yosryahmed@xxxxxxxxxx> > Reviewed-by: David Hildenbrand <david@xxxxxxxxxx> > Cc: Hugh Dickins <hughd@xxxxxxxxxx> > Cc: Johannes Weiner <hannes@xxxxxxxxxxx> > Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> > Cc: Michal Hocko <mhocko@xxxxxxxx> > Cc: Minchan Kim <minchan@xxxxxxxxxx> > Cc: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx> > Cc: Yang Shi <shy828301@xxxxxxxxx> > Cc: Yu Zhao <yuzhao@xxxxxxxxxx> > Cc: Chris Li <chrisl@xxxxxxxxxx> Reviewed-By: Chris Li (Google) <chrisl@xxxxxxxxxx> Chris > --- > mm/swapfile.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 274bbf797480..8419cba9c192 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1432,16 +1432,10 @@ void swapcache_free_entries(swp_entry_t *entries, int n) > > int __swap_count(swp_entry_t entry) > { > - struct swap_info_struct *si; > + struct swap_info_struct *si = swp_swap_info(entry); > pgoff_t offset = swp_offset(entry); > - int count = 0; > > - si = get_swap_device(entry); > - if (si) { > - count = swap_count(si->swap_map[offset]); > - put_swap_device(si); > - } > - return count; > + return swap_count(si->swap_map[offset]); > } > > /* > -- > 2.39.2 >