Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp258651rwn; Wed, 14 Sep 2022 20:21:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR7/lL+2Zp8vwzigel6qUc1LRwGk9IiuB5MQSMZUIiZlNTaUrfmjvD/Xv9JJweZ1w/73HmOQ X-Received: by 2002:a63:81c1:0:b0:434:f41f:496 with SMTP id t184-20020a6381c1000000b00434f41f0496mr32353336pgd.208.1663212098672; Wed, 14 Sep 2022 20:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663212098; cv=none; d=google.com; s=arc-20160816; b=CRCapguC+mA0f/kkA/4uc+xZiUOInK0CtAupjgvDwUqZG9H9DgnNizpCiGFpJU86X/ TxT7awb5SXsSC0LGCoafk/YxERxIZB5Dg8a+w3p5sBLtNjBx6Kf798wuxyyyDuyUtuuN BBLXm0hZRLSP4RloyLBO77Mg+GpKt+6iOjALEmxudJiMIzpoMYYxS08eRNkAtmnyJXZv BKhecK/9hXV33e4qyKPx51szWrTahVoYyOIoIAVLHgoOR+oUPi/Vua21UHHiJcGEK4Lr uHYQoAdbe2AU3R8SF/WWa+tOv0V7xFYS/qFy26f1iSzmQ9gb9VT5zUyJjbfZ3MhV8iKG pvQQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e87pXlfq5sH3cXetgQMtMEqoeRX04CP2aZV8Hxkmp+s=; b=pA6ms42qmvze/8D858qjnM8s5sMe9dDv0K4vIalSot+bAnW73en+jngNvSGS2Av4wK 0P0FGdWJkry4XszKN0RVmxelTP0WrgHXo1N60Z+fU42oL3LPLX8YNJlA6HgdKMb/dOnf pG4uwTHFMttNTWDu1rYyA4DEwxEXh6tLjipUJW5gaRjGJfrZ2dINDGP7c6CvokQMP5Nv WQ2ROHayN8FYcaAU6BqhquvqjB7Ztxr6aXc8Occ8K6vjn008HPofdJLPKlPXfblnH94q zIskCcmhQbtOCfFxIH6lgqKeq8riWQlpJU7rNAti3DaIRXbpwTtE6Nbn8HMmhU1kFpwB 42nQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i1-20020a17090332c100b001784c98bfddsi6708388plr.24.2022.09.14.20.21.26; Wed, 14 Sep 2022 20:21:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiIODQO (ORCPT + 99 others); Wed, 14 Sep 2022 23:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiIODQL (ORCPT ); Wed, 14 Sep 2022 23:16:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5314B910BB for ; Wed, 14 Sep 2022 20:16:09 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MSj1J5yqJzmV89; Thu, 15 Sep 2022 11:12:20 +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; Thu, 15 Sep 2022 11:16:07 +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; Thu, 15 Sep 2022 11:16:06 +0800 From: Liu Shixin To: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Nathan Chancellor , "Christoph Hellwig" CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH v5 2/5] Revert "frontswap: simplify frontswap_register_ops" Date: Thu, 15 Sep 2022 11:50:00 +0800 Message-ID: <20220915035003.3347466-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220915035003.3347466-1-liushixin2@huawei.com> References: <20220915035003.3347466-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mm/frontswap.c b/mm/frontswap.c index 279e55b4ed87..aa3a1e3ddf91 100644 --- a/mm/frontswap.c +++ b/mm/frontswap.c @@ -96,11 +96,53 @@ 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) + 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)) + ops->init(i); + else if (test_bit(i, a) && !test_bit(i, b)) + ops->invalidate_area(i); + } + } + return 0; } -- 2.25.1