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=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 816B0ECE587 for ; Mon, 14 Oct 2019 13:23:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5903C2089C for ; Mon, 14 Oct 2019 13:23:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5903C2089C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F1B828E0010; Mon, 14 Oct 2019 09:23:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECBDD8E0007; Mon, 14 Oct 2019 09:23:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBAAB8E0010; Mon, 14 Oct 2019 09:23:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id BA2CB8E0007 for ; Mon, 14 Oct 2019 09:23:28 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 4B4403CEA for ; Mon, 14 Oct 2019 13:23:28 +0000 (UTC) X-FDA: 76042456896.14.gate74_3b32f3434fc45 X-HE-Tag: gate74_3b32f3434fc45 X-Filterd-Recvd-Size: 2123 Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Oct 2019 13:23:26 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9088B629E7A7AEA2E9A1; Mon, 14 Oct 2019 21:22:52 +0800 (CST) Received: from [127.0.0.1] (10.119.195.53) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Mon, 14 Oct 2019 21:22:50 +0800 From: Chen Wandun Subject: [Question] Is there race between swapoff and swapout To: , , Message-ID: <8860e8b1-7bad-0b4a-60d1-4893973b9cb2@huawei.com> Date: Mon, 14 Oct 2019 21:22:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.119.195.53] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000219, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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