linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [Question] Is there race between swapoff and swapout
@ 2019-10-14 13:22 Chen Wandun
  2019-10-24  8:51 ` Huang, Ying
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Wandun @ 2019-10-14 13:22 UTC (permalink / raw)
  To: linux-kernel, linux-mm, ying.huang

I analysied the code about swapoff and swapout, and I suspected there may be a race.
The kernel version is 4.14 stable.

CPU0						CPU1
swapoff						swap out
						add_to_swap
							get_swap_page
	......							get_swap_pages						
									spin_lock(&swap_avail_lock)
									get swap_info_struct
									spin_unlock(&swap_avail_lock)		
	spin_lock(&swap_avail_lock)									
	__def_from_avail_list(swap_info_struct)								
     	spin_unlock(&swap_avail_lock)					......	
	try_to_unuse  // unuse all slot
									/* get a free slot from swap_info_struct,
									 * and write data to slot later
									 */	
									scan_swap_map_slots
	free swap_info_struct
	.......

	
If CPU1 get the swap_info_struct first, then CPU0 delete it from list and
unuse all slot in swap_info_struct, before CPU0 free swap_info_struct CPU1
call scan_swap_map_slots to alloc a free slot.

I am not sure the analysis above is correct,
Please let me know if there is any mistake

Thanks
ChenWandun



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Question] Is there race between swapoff and swapout
  2019-10-14 13:22 [Question] Is there race between swapoff and swapout Chen Wandun
@ 2019-10-24  8:51 ` Huang, Ying
  0 siblings, 0 replies; 2+ messages in thread
From: Huang, Ying @ 2019-10-24  8:51 UTC (permalink / raw)
  To: Chen Wandun; +Cc: linux-kernel, linux-mm

Chen Wandun <chenwandun@huawei.com> writes:

> I analysied the code about swapoff and swapout, and I suspected there may be a race.
> The kernel version is 4.14 stable.
>
> CPU0						CPU1
> swapoff						swap out
> 						add_to_swap
> 							get_swap_page
> 	......							get_swap_pages						
> 									spin_lock(&swap_avail_lock)
> 									get swap_info_struct
> 									spin_unlock(&swap_avail_lock)		
> 	spin_lock(&swap_avail_lock)									
> 	__def_from_avail_list(swap_info_struct)								
>     	spin_unlock(&swap_avail_lock)					......	
> 	try_to_unuse  // unuse all slot
> 									/* get a free slot from swap_info_struct,
> 									 * and write data to slot later
> 									 */	
> 									scan_swap_map_slots
> 	free swap_info_struct
> 	.......
>
> 	
> If CPU1 get the swap_info_struct first, then CPU0 delete it from list and
> unuse all slot in swap_info_struct, before CPU0 free swap_info_struct CPU1
> call scan_swap_map_slots to alloc a free slot.
>
> I am not sure the analysis above is correct,
> Please let me know if there is any mistake

SWP_WRITEOK will be cleared during swapoff, and it is checked during
swap slots allocation.

Best Regards,
Huang, Ying

> Thanks
> ChenWandun


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-24  8:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 13:22 [Question] Is there race between swapoff and swapout Chen Wandun
2019-10-24  8:51 ` Huang, Ying

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).