Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp975447pxb; Sat, 17 Apr 2021 02:43:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyctoSj/jgzyPFIhteq9yDcYhI2xxd2gDmExupILv01zv7SGZR1tzZdcL1aUtRzLqBe+u18 X-Received: by 2002:a17:90b:120b:: with SMTP id gl11mr14282114pjb.143.1618652618145; Sat, 17 Apr 2021 02:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618652618; cv=none; d=google.com; s=arc-20160816; b=Dfw0jSHnDu3Ue4g3//9yejqDd/oy0ODfy6gEYWJOY7RENc5C+FgbkEoNmKBEbCT5SD nOBtzcFMfVKZVJ/E+phKYb5dbShhV0bxy8oPsSt3SoN4cqp0uiD7M6N+DhJR7oJBieMX 13zqrLkgUg/1VK7QsWVhomkQBDdOTgfNwKNo3aA9VLJ6zN6WsaY0PnhClK032FPXkiae /0g4CZwef5xueZ9Vw9NkIaNDMQfPOUs/C7W9kK0v9x0h6Sg/WF8aDQEvYC5QkJ6quKZa n0kyXcpPfaR6lJdcLbtDax5yVVKmuWr3YLaYu2VFUbZmWo8tdrQWJ5a9fZ7pYSt6RT6r E3Zw== 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=iN5771XMTnIsFHp5QLh0KMCxSbJRdNtvVZs8zgoeoq0=; b=DKBJq+wEmOurftTcj+eKeV4Zkpj09IvMdPmS8oTRfdcnYRkWzFf6/KXCrNeyTAKOU0 p74PrmxYM3jnuvO5mK7O2BVQbtO7DD36G/jZqDQAuZ5AN1s/fuILru9qW+FBiNDNuYXc DaQblBrCRGfFF86lg9lpqXbJqxbZIz6If53OUxkR5Ynr/HgGfsNAtUKsswnBTRmM7YDG 5zQMEZGE8FKS14sCtEniK7z0Y3CaDuSpbpCRbsBaGyXlXi04i5GUwEAXiWmAElBemeco VIx2zDF/0WH+BlhGJt4MBiLTiomIN49MWXUAtazN8UeuRVyjwBolO/uxQSUU3sxV0cNH PxZw== 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 j18si9973960plj.249.2021.04.17.02.43.26; Sat, 17 Apr 2021 02:43:38 -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 S236006AbhDQJmP (ORCPT + 99 others); Sat, 17 Apr 2021 05:42:15 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:17369 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231387AbhDQJmN (ORCPT ); Sat, 17 Apr 2021 05:42:13 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FMp2b4JhZzlYjX; Sat, 17 Apr 2021 17:39:51 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Sat, 17 Apr 2021 17:41:36 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , Subject: [PATCH v2 0/5] close various race windows for swap Date: Sat, 17 Apr 2021 05:40:34 -0400 Message-ID: <20210417094039.51711-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.175] 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! 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 (5): mm/swapfile: add percpu_ref support for swap 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 | 15 +++++++-- mm/memory.c | 9 ++++++ mm/shmem.c | 6 ++++ mm/swap_state.c | 6 ---- mm/swapfile.c | 74 +++++++++++++++++++++++++++----------------- 5 files changed, 73 insertions(+), 37 deletions(-) -- 2.19.1