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 DBF55ECAAD4 for ; Mon, 29 Aug 2022 12:48:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C80194000D; Mon, 29 Aug 2022 08:48:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 04C63940008; Mon, 29 Aug 2022 08:48:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E113594000B; Mon, 29 Aug 2022 08:48:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CE96F940007 for ; Mon, 29 Aug 2022 08:48:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 924D74035A for ; Mon, 29 Aug 2022 12:48:39 +0000 (UTC) X-FDA: 79852609158.08.801CBC2 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id AFFBD80004 for ; Mon, 29 Aug 2022 12:48:38 +0000 (UTC) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MGVWt2QRCzkWl8; Mon, 29 Aug 2022 20:44:58 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 29 Aug 2022 20:48:35 +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; Mon, 29 Aug 2022 20:48:34 +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 v4 3/6] Revert "frontswap: simplify frontswap_register_ops" Date: Mon, 29 Aug 2022 21:22:59 +0800 Message-ID: <20220829132302.3367054-4-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220829132302.3367054-1-liushixin2@huawei.com> References: <20220829132302.3367054-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: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661777319; a=rsa-sha256; cv=none; b=k72ozokLyMiIcn2VOEVMpOszxgRUuQ9R5hVdlMTxwlWrDai888OPcl4nDB2CCNod2jzZ1t QLbHpF2vBVf51gasAgJlm4lle3/ccERALGovCjnJ82bFKh9MUJEfNIR8FazVUM1UrRf2g5 1Qjbg85SMtTj2kSdylKyt0xvn7cQx5c= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 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=1661777319; 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=Re72uGpyAlkE/Hx3Ivoco2SPz+25s5x0LHc/2dIHkcs=; b=rIfK+hbVVnbJ3VVyapunMNRewhbTVpbLX0fADIrUnmMGgqXTATmFCAcchtn6EObPz7z0RH sIsPSW4x0qS9bY3pxA9uLe0WmQAl8u6Bh/SgNzI97uhCWlH8K1r9YJUG0Qk00yLosjBLkl rVZ453z7Usa59OorpFd8vuim8b16b44= X-Stat-Signature: 9dxrkkdwhh9nfof6qptqetxz913o516c X-Rspamd-Queue-Id: AFFBD80004 X-Rspam-User: X-Rspamd-Server: rspam01 Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-HE-Tag: 1661777318-612161 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: This reverts commit f328c1d16e4c764992895ac9c9425cea861b2ca0. 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. Signed-off-by: Liu Shixin --- mm/frontswap.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mm/frontswap.c b/mm/frontswap.c index 8d644f56a1d2..555e78f9529d 100644 --- a/mm/frontswap.c +++ b/mm/frontswap.c @@ -99,6 +99,25 @@ static inline void inc_frontswap_invalidates(void) { } */ void frontswap_register_ops(struct frontswap_ops *ops) { + DECLARE_BITMAP(a, MAX_SWAPFILES); + DECLARE_BITMAP(b, MAX_SWAPFILES); + struct swap_info_struct *si; + unsigned int i; + + 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) + ops->init(i); + /* * Setting frontswap_ops must happen after the ops->init() calls * above; cmpxchg implies smp_mb() which will ensure the init is @@ -109,6 +128,28 @@ void frontswap_register_ops(struct frontswap_ops *ops) } while (cmpxchg(&frontswap_ops, ops->next, ops) != ops->next); 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)) + ops->init(i); + else if (test_bit(i, a) && !test_bit(i, b)) + ops->invalidate_area(i); + } + } } /* -- 2.25.1