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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EFCCECAAD2 for ; Sat, 27 Aug 2022 10:12:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D14D96B007D; Sat, 27 Aug 2022 06:12:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9D3B940007; Sat, 27 Aug 2022 06:12:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B17386B0080; Sat, 27 Aug 2022 06:12:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9F0276B007D for ; Sat, 27 Aug 2022 06:12:00 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7F149401A6 for ; Sat, 27 Aug 2022 10:12:00 +0000 (UTC) X-FDA: 79844956800.22.02BF3DB Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id 93095A0030 for ; Sat, 27 Aug 2022 10:11:59 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MFC7B0rL5zYcvD; Sat, 27 Aug 2022 18:07:34 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 27 Aug 2022 18:11:40 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 27 Aug 2022 18:11:40 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , "Christoph Hellwig" CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH -next v3 2/5] frontswap: invoke ops->init for online swap device in frontswap_register_ops Date: Sat, 27 Aug 2022 18:45:57 +0800 Message-ID: <20220827104600.1813214-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220827104600.1813214-1-liushixin2@huawei.com> References: <20220827104600.1813214-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661595120; a=rsa-sha256; cv=none; b=DkzBxSNn5mt7ox+GeC/ye5wgTbeFsZ4FMMbtuHyMah+HR0+YbwLpflNorVPkWygl6bhdHj jhrSBII1wYSRrNTIn71Ly7WITlHyhwE9V3U4T3q7hZPoSPYwBgVn+DdQ2ryeYcxK2eu+Kf PdQL0O9khvnOXSem+vzEEMYYnkambcE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661595120; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zRIPDag2YeWHohjil1GglkEtDNoYgibW7Nrmfe15w0M=; b=y9X283VOQ+8IsRu81MVcM6qtBI5rgJAZFoFXX5K58817wVzXzJtlAhq/42XWWjvRoJCF70 DEYi5Mfq2LlVRdTwgvNWxi866y5ed5uTBO2qm02epce5bIyZ82wIJFxOxJ197/C3Y2VPDr Fn5SzAeIToxi948ej/6EOUszIcmElFU= X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam08 X-Stat-Signature: 8rpuzwxk8cwdb4zktuohfmoka8icwwdh X-Rspamd-Queue-Id: 93095A0030 X-HE-Tag: 1661595119-7256 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: Since we are supported to delay zswap initializaton, we need to invoke ops->init for the swap device which is already online when register backend. This patch is a revert of f328c1d16e4c ("frontswap: simplify frontswap_register_ops") and 633423a09cb5 ("mm: mark swap_lock and swap_active_head static") Signed-off-by: Liu Shixin --- include/linux/swapfile.h | 2 ++ mm/frontswap.c | 47 ++++++++++++++++++++++++++++++++++++++++ mm/swapfile.c | 4 ++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h index 2fbcc9afd814..75fc069594a5 100644 --- a/include/linux/swapfile.h +++ b/include/linux/swapfile.h @@ -6,6 +6,8 @@ * these were static in swapfile.c but frontswap.c needs them and we don't * want to expose them to the dozens of source files that include swap.h */ +extern spinlock_t swap_lock; +extern struct plist_head swap_active_head; extern struct swap_info_struct *swap_info[]; extern unsigned long generic_max_swapfile_size(void); /* Maximum swapfile size supported for the arch (not inclusive). */ diff --git a/mm/frontswap.c b/mm/frontswap.c index 620f95af81dd..449e6f499b88 100644 --- a/mm/frontswap.c +++ b/mm/frontswap.c @@ -96,11 +96,58 @@ static inline void inc_frontswap_invalidates(void) { } */ int frontswap_register_ops(const struct frontswap_ops *ops) { + DECLARE_BITMAP(a, MAX_SWAPFILES); + DECLARE_BITMAP(b, MAX_SWAPFILES); + struct swap_info_struct *si; + unsigned int i; + if (frontswap_ops) return -EINVAL; + bitmap_zero(a, MAX_SWAPFILES); + bitmap_zero(b, MAX_SWAPFILES); + + spin_lock(&swap_lock); + plist_for_each_entry(si, &swap_active_head, list) { + if (!WARN_ON(!si->frontswap_map)) + __set_bit(si->type, a); + } + spin_unlock(&swap_lock); + + /* the new ops needs to know the currently active swap devices */ + for_each_set_bit(i, a, MAX_SWAPFILES) { + pr_err("init frontswap_ops\n"); + ops->init(i); + } + frontswap_ops = ops; static_branch_inc(&frontswap_enabled_key); + + spin_lock(&swap_lock); + plist_for_each_entry(si, &swap_active_head, list) { + if (si->frontswap_map) + __set_bit(si->type, b); + } + spin_unlock(&swap_lock); + + /* + * On the very unlikely chance that a swap device was added or + * removed between setting the "a" list bits and the ops init + * calls, we re-check and do init or invalidate for any changed + * bits. + */ + if (unlikely(!bitmap_equal(a, b, MAX_SWAPFILES))) { + for (i = 0; i < MAX_SWAPFILES; i++) { + if (!test_bit(i, a) && test_bit(i, b)) { + pr_err("init frontswap_ops re\n"); + ops->init(i); + } else if (test_bit(i, a) && !test_bit(i, b)) { + pr_err("inval frontswap_ops re\n"); + ops->invalidate_area(i); + } + } + } + return 0; } diff --git a/mm/swapfile.c b/mm/swapfile.c index 469d9af86be2..d383b282f269 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -51,7 +51,7 @@ static bool swap_count_continued(struct swap_info_struct *, pgoff_t, unsigned char); static void free_swap_count_continuations(struct swap_info_struct *); -static DEFINE_SPINLOCK(swap_lock); +DEFINE_SPINLOCK(swap_lock); static unsigned int nr_swapfiles; atomic_long_t nr_swap_pages; /* @@ -77,7 +77,7 @@ static const char Unused_offset[] = "Unused swap offset entry "; * all active swap_info_structs * protected with swap_lock, and ordered by priority. */ -static PLIST_HEAD(swap_active_head); +PLIST_HEAD(swap_active_head); /* * all available (active, not full) swap_info_structs -- 2.25.1