Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3355202pxb; Tue, 20 Apr 2021 06:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgY9seTIzSNnIjtUQEhHygKH/o2q2lmDiqEpTkSEJ4IqqZ1jeARTLXCqCGM6fZ9ae3W0J8 X-Received: by 2002:a17:906:f2c8:: with SMTP id gz8mr28135121ejb.242.1618925762744; Tue, 20 Apr 2021 06:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618925762; cv=none; d=google.com; s=arc-20160816; b=AjAD8Z+eoeUUVyQRAeLwviHV7MIlwc7obAtZfBU+4Ikt8MGM4bnetglESuTvEGzR8m NS0xiTkH5aaD9QGYdcXif/QmMro//RZLpoEUKCjttU1S68ooemj8zwKKV7iyokbKc+Sc WMkx460DdNTiKkKSGI+5SFIchU6+NYcHgYAN7DgU5Fdx9x/TzZZ+pSI5+rVLnE+1mLkR GaihPyOrvxsM/GfHOs540kjCtlGH+EaQd52EZNronO1wNEI1mmTiDR92hZUBPc1+5KZd uFDCcTJ/a4b/kXFrg35cREqiNJqzNVeBDta8X0RDXTgmAfC14a8cz8UvzeRkmcgRGwa4 FCYg== 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=3CT9QD5mRAhEg5pqM9RvQMqDJC7FJHcOL/Zyjdug4oc=; b=0jdzHDzM1IwUK9wtz9tCpBGkRjGThPU6hmsG4ykkp7oF1IGH1YxPI+I7/YQzLDT491 ifEg+t/4MbhR0IQYtHz/VYBcvHpE8kE5CflDU27POndPbqCSA3xxtpC1pKjGe+pUGqYl 3YcO5/uaZEFeQkFXfH2tcrftmB3NIFgS19fLQh3x2oFK9degvrFIqaAbs9VNy/5grMg4 ZiC+Qgic+JwKwmyI+ZUU+ZQjZrpfZGUn+R0XceLo23vi71imq09FGrWVSMpcdrhjz9wP BfclfZ1Z31ZsSCWSH2V9z5ocJozNMRlfe1U4aPDeP7AuuRQzWKu/zvKZZ3jhVJJAUI97 B4nA== 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 b3si15216949ejc.453.2021.04.20.06.35.39; Tue, 20 Apr 2021 06:36:02 -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 S232496AbhDTNc1 (ORCPT + 99 others); Tue, 20 Apr 2021 09:32:27 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17802 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231718AbhDTNcS (ORCPT ); Tue, 20 Apr 2021 09:32:18 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FPl022LFTzBrVN; Tue, 20 Apr 2021 21:29:22 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.498.0; Tue, 20 Apr 2021 21:31:36 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , Subject: [PATCH v3 0/4] close various race windows for swap Date: Tue, 20 Apr 2021 09:30:44 -0400 Message-ID: <20210420133048.6773-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! 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 | 9 +++++ mm/shmem.c | 6 ++++ mm/swap_state.c | 6 ---- mm/swapfile.c | 79 +++++++++++++++++++++++++++----------------- 5 files changed, 76 insertions(+), 38 deletions(-) -- 2.19.1