From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 740CDCA9EAF for ; Thu, 24 Oct 2019 08:51:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3DD7420684 for ; Thu, 24 Oct 2019 08:51:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DD7420684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DB7166B0005; Thu, 24 Oct 2019 04:51:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D676C6B0006; Thu, 24 Oct 2019 04:51:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7CA16B0007; Thu, 24 Oct 2019 04:51:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id A3D336B0005 for ; Thu, 24 Oct 2019 04:51:12 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 596AB1816BB69 for ; Thu, 24 Oct 2019 08:51:12 +0000 (UTC) X-FDA: 76078058784.30.sky13_a664cc93111f X-HE-Tag: sky13_a664cc93111f X-Filterd-Recvd-Size: 2511 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 08:51:11 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2019 01:51:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,224,1569308400"; d="scan'208";a="210110065" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.29]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2019 01:51:08 -0700 From: "Huang\, Ying" To: Chen Wandun Cc: , Subject: Re: [Question] Is there race between swapoff and swapout References: <8860e8b1-7bad-0b4a-60d1-4893973b9cb2@huawei.com> Date: Thu, 24 Oct 2019 16:51:08 +0800 In-Reply-To: <8860e8b1-7bad-0b4a-60d1-4893973b9cb2@huawei.com> (Chen Wandun's message of "Mon, 14 Oct 2019 21:22:35 +0800") Message-ID: <87sgnih6gz.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Chen Wandun 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