From patchwork Tue Jun 8 00:51:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 12304983 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 7B764C47082 for ; Tue, 8 Jun 2021 00:51:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0796661108 for ; Tue, 8 Jun 2021 00:51:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0796661108 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 271266B006C; Mon, 7 Jun 2021 20:51:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 220F06B006E; Mon, 7 Jun 2021 20:51:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C2286B0070; Mon, 7 Jun 2021 20:51:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id CAD216B006C for ; Mon, 7 Jun 2021 20:51:45 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 67202611F for ; Tue, 8 Jun 2021 00:51:45 +0000 (UTC) X-FDA: 78228728970.06.127C0F4 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf24.hostedemail.com (Postfix) with ESMTP id E5688A000241 for ; Tue, 8 Jun 2021 00:51:38 +0000 (UTC) IronPort-SDR: QTzfsbKCiu2WsKL1psTHG6uVXauJk9hNb6iSYACmw2I4GdCjpxuymKcctex4cFLFQPdk+4zq/0 jyxU5Jshtlyg== X-IronPort-AV: E=McAfee;i="6200,9189,10008"; a="204712523" X-IronPort-AV: E=Sophos;i="5.83,256,1616482800"; d="scan'208";a="204712523" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2021 17:51:37 -0700 IronPort-SDR: q/wCTAnYL3WnH3KJ+Ba5oWsrAwn24eYI+tw3G+eSL6UfDKmrh4r0KqVT5225wkYVs28GIXcHNY DdBrIvXRwL9Q== X-IronPort-AV: E=Sophos;i="5.83,256,1616482800"; d="scan'208";a="447695110" Received: from yhuang6-desk2.sh.intel.com ([10.239.159.119]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2021 17:51:33 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Miaohe Lin , Matthew Wilcox , Minchan Kim , Joonsoo Kim , Johannes Weiner , Vlastimil Babka , Hugh Dickins , Mel Gorman , Michal Hocko , Dan Williams , Christoph Hellwig , Ilya Dryomov Subject: [PATCH] swap: Check mapping_empty() for swap cache before being freed Date: Tue, 8 Jun 2021 08:51:21 +0800 Message-Id: <20210608005121.511140-1-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf24.hostedemail.com: domain of ying.huang@intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=ying.huang@intel.com X-Stat-Signature: q84ccz5yqxd5f6g4c36m83c6dzc48bh7 X-Rspamd-Queue-Id: E5688A000241 X-Rspamd-Server: rspam06 X-HE-Tag: 1623113498-567543 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: To check whether all pages and shadow entries in swap cache has been removed before swap cache is freed. Signed-off-by: "Huang, Ying" Cc: Miaohe Lin Cc: Matthew Wilcox Cc: Minchan Kim Cc: Joonsoo Kim Cc: Johannes Weiner Cc: Vlastimil Babka Cc: Hugh Dickins Cc: Mel Gorman Cc: Michal Hocko Cc: Dan Williams Cc: Christoph Hellwig Cc: Ilya Dryomov --- BTW: The patch reverts the following patch in -mm tree in effect. mm/swap: remove unused global variable nr_swapper_spaces --- mm/swap_state.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 95e391f46468..c56aa9ac050d 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -37,6 +37,7 @@ static const struct address_space_operations swap_aops = { }; struct address_space *swapper_spaces[MAX_SWAPFILES] __read_mostly; +static unsigned int nr_swapper_spaces[MAX_SWAPFILES] __read_mostly; static bool enable_vma_readahead __read_mostly = true; #define SWAP_RA_WIN_SHIFT (PAGE_SHIFT / 2) @@ -684,6 +685,7 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages) /* swap cache doesn't use writeback related tags */ mapping_set_no_writeback_tags(space); } + nr_swapper_spaces[type] = nr; swapper_spaces[type] = spaces; return 0; @@ -691,7 +693,13 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages) void exit_swap_address_space(unsigned int type) { - kvfree(swapper_spaces[type]); + int i; + struct address_space *spaces = swapper_spaces[type]; + + for (i = 0; i < nr_swapper_spaces[type]; i++) + VM_WARN_ON_ONCE(!mapping_empty(&spaces[i])); + kvfree(spaces); + nr_swapper_spaces[type] = 0; swapper_spaces[type] = NULL; }