linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chen Wandun <chenwandun@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	<ying.huang@intel.com>
Subject: [Question] Is there race between swapoff and swapout
Date: Mon, 14 Oct 2019 21:22:35 +0800	[thread overview]
Message-ID: <8860e8b1-7bad-0b4a-60d1-4893973b9cb2@huawei.com> (raw)

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



             reply	other threads:[~2019-10-14 13:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 13:22 Chen Wandun [this message]
2019-10-24  8:51 ` Huang, Ying

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8860e8b1-7bad-0b4a-60d1-4893973b9cb2@huawei.com \
    --to=chenwandun@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox