Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp2746576pxy; Sun, 25 Apr 2021 02:55:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1r4Xf/ladukc11cf2i2BfZ18RfxLyFMNtVz38jk8hRjetZsyAL0iHrJDNGQ88KTqIALkb X-Received: by 2002:aa7:d14a:: with SMTP id r10mr14872981edo.385.1619344552308; Sun, 25 Apr 2021 02:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619344552; cv=none; d=google.com; s=arc-20160816; b=N7htcqgvcIEswVMf7dwsRXyd82zDQQjh/05pWKY7J+Yti1ZATiEuBJp7uXulEi9VKF 4qLQiWkPzNwUatYGEfiyBOTN6tdn2dDbZFsE/+2G1BxnwNv9AdzeNJMscBHUQT3v6nDC WYZUz7kHnsbtLvD65/GmaimSylWovdwpyBR6k/bH3VrdRI9SfwWEnMkYfFyYd+WQNpN9 lcnD8itvipnibB9+NXAYfg0EyOrkD6lHVLRsxoXDe34BaW1hqAMh8DNRawRN2ym/7De1 7Aon+GrIL0m/o1g5D2GOpFsb1X3tC7eJcZqy6cR9lVb/iNsqs4ssZ3UiuWpjtbvIXHav fRMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6JLMdPi86cojNz7eqLOVrre4eItpR9UiZSKdLZq03rA=; b=KioIoCao9BgpZf6mFx67bphM3PdDmWzkSLPg8/EEXFtWJnetpgDZvBRqSqfTEquPl1 yOlwhKfJfcpp/zx1EPW778bYMGlHLpufDP7kJUBMy2qDF7YspKr1IFiPtMPnEqa/ROAk 4K0P/ttqPGoguwTeghxVglu4Lq9B27yFec8TdNPRr9DpsYdsyEtwQmAs84VnvhLEGzrT 148Bg1YJOIwxYZwVq1qT4DXDIGOngIB1Jbl2i35J3CFrG0yChVrWC/VNiEbLV21jH0mA 29IxnxsZroGRWH9rKIMrMz301opw72F/6LGTMMphaogEm8gmk24bS/wy/gVOlhTs6iIe GMNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si12116104ejb.254.2021.04.25.02.55.29; Sun, 25 Apr 2021 02:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229966AbhDYJzH (ORCPT + 99 others); Sun, 25 Apr 2021 05:55:07 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3531 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbhDYJzH (ORCPT ); Sun, 25 Apr 2021 05:55:07 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4FSjx721DgzRgwp; Sun, 25 Apr 2021 17:52:11 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 25 Apr 2021 17:54:23 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , Subject: [PATCH v5 0/4] close various race windows for swap Date: Sun, 25 Apr 2021 17:54:15 +0800 Message-ID: <20210425095419.3830298-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, When I was investigating the swap code, I found some possible race windows. This series aims to fix all these races. But using current get/put_swap_device() to guard against concurrent swapoff for swap_readpage() looks terrible because swap_readpage() may take really long time. And to reduce the performance overhead on the hot-path as much as possible, it appears we can use the percpu_ref to close this race window(as suggested by Huang, Ying). The patch 1 adds percpu_ref support for swap and most of the remaining patches try to use this to close various race windows. More details can be found in the respective changelogs. Thanks! v4->v5: collect Reviewed-by tag do put_swap_device() before returning from the function per Huang, Ying v3->v4: some commit log and comment enhance per Huang, Ying put get/put_swap_device() in shmem_swapin_page() per Huang, Ying collect Reviewed-by tag v2->v3: some commit log and comment enhance per Huang, Ying remove ref_initialized field squash PATCH 1-2 v1->v2: reorganize the patch-2/5 various enhance and fixup per Huang, Ying Many thanks for the comments of Huang, Ying, Dennis Zhou and Tim Chen. Miaohe Lin (4): mm/swapfile: use percpu_ref to serialize against concurrent swapoff swap: fix do_swap_page() race with swapoff mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info() mm/shmem: fix shmem_swapin() race with swapoff include/linux/swap.h | 14 ++++++-- mm/memory.c | 11 ++++-- mm/shmem.c | 12 +++++++ mm/swap_state.c | 6 ---- mm/swapfile.c | 79 +++++++++++++++++++++++++++----------------- 5 files changed, 82 insertions(+), 40 deletions(-) -- 2.23.0