Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3480544rwb; Tue, 16 Aug 2022 03:59:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR41aD0aQKDvzay8IiuE/tXJBJ6OmcfMkSe5bW/qjtBdKNePpXMR7BaAw+WjTKRwh4ZmC7Qc X-Received: by 2002:a05:6402:3206:b0:43d:4e0e:b693 with SMTP id g6-20020a056402320600b0043d4e0eb693mr18135299eda.316.1660647590411; Tue, 16 Aug 2022 03:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660647590; cv=none; d=google.com; s=arc-20160816; b=ZVBqI/73vFnPSmrUkqmsYkCwEnv8EgGmkjpPi1Ew1Z8z04FRSRT1Jje1iUJhnn36cY ZaGWdU5uAr/1Rh3AEiDLIPp/K8ji143bVOHNK2NwvszrLhJ6pD2QRy1Wee9mRc0LioE9 wk+o52Y7tiXJGXs9au/pJ0u0v8trG6dJr211C8Hm3n6F1+AZuKQ7xS0E9TADncoiAJbJ 5w60hW/srCKugDLgxXoHBYZlelE1LVpZGiL8aj+uWsDaOrh1pVR+Nd3wmS/ZGoiT2rOd GxikPXaILw4KMgGsnB2UVEmO5jrGpUD1utdSd1cnIn6kHPjIOF/DGYvJWaCsWoHKy6JF Y5lg== 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=H7zj1q+fUjV0R6GsuXwaIWs1xK+MvvcLibCpCZApSm0=; b=RAbSwrlfboXBPNItUJC7arYI2zuL4K3fLFjKzgCLgSWHt3i9EtJ7B5bcyH6Ao0qslo TTsJRzNPOAHpcBOpF79eLWXqr3NOfcSk6y5QN+Fa0Amo7FAKLW5NMM/3EmKe6dywUTjG 8p3Su2RgH0eA783py89Ah9mQAUVCm0JGpgtHMyaEU3cQuwVvr6ENFCO8fs+peYQV5R42 hsQ2e54D1DhspZG5XkwHosZb8IhvCmgyKPe+IySXBe/U18iV/g8U41nmmfovAhTfA19b XAfR7BOIN527Ilql4c2ckPPlSk67/ucskvEDMEW3VGjuZLXmHqjrDG1OnmNGmA78c2jL VWpQ== 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=virtuozzo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb26-20020a170907961a00b00711ca931feasi11127764ejc.998.2022.08.16.03.59.24; Tue, 16 Aug 2022 03:59:50 -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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234759AbiHPKpR (ORCPT + 99 others); Tue, 16 Aug 2022 06:45:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235038AbiHPKox (ORCPT ); Tue, 16 Aug 2022 06:44:53 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B216E4330B for ; Tue, 16 Aug 2022 02:54:43 -0700 (PDT) Received: from dev011.ch-qa.sw.ru ([172.29.1.16]) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1oNt3o-00FxfB-BO; Tue, 16 Aug 2022 11:41:43 +0200 From: Alexander Atanasov To: "Michael S. Tsirkin" , David Hildenbrand , Andrew Morton Cc: kernel@openvz.org, Alexander Atanasov , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 2/4] Enable balloon drivers to report inflated memory Date: Tue, 16 Aug 2022 12:41:15 +0300 Message-Id: <20220816094117.3144881-3-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220816094117.3144881-1-alexander.atanasov@virtuozzo.com> References: <20220816094117.3144881-1-alexander.atanasov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 Add counters to be updated by the balloon drivers. Create balloon notifier to propagate changes. Signed-off-by: Alexander Atanasov --- include/linux/balloon_common.h | 18 ++++++++++++++++++ mm/balloon_common.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/linux/balloon_common.h b/include/linux/balloon_common.h index a45e9fd76235..e707f57f58da 100644 --- a/include/linux/balloon_common.h +++ b/include/linux/balloon_common.h @@ -59,6 +59,24 @@ struct balloon_dev_info { struct page *page, enum migrate_mode mode); }; +extern atomic_long_t mem_balloon_inflated_total_kb; +extern atomic_long_t mem_balloon_inflated_free_kb; + +void balloon_set_inflated_total(long inflated_kb); +void balloon_set_inflated_free(long inflated_kb); + +#define BALLOON_CHANGED_TOTAL 0 +#define BALLOON_CHANGED_FREE 1 + +extern int register_balloon_notifier(struct notifier_block *nb); +extern void unregister_balloon_notifier(struct notifier_block *nb); + +#define balloon_notifier(fn, pri) ({ \ + static struct notifier_block fn##_mem_nb __meminitdata =\ + { .notifier_call = fn, .priority = pri }; \ + register_balloon_notifier(&fn##_mem_nb); \ +}) + extern struct page *balloon_page_alloc(void); extern void balloon_page_enqueue(struct balloon_dev_info *b_dev_info, struct page *page); diff --git a/mm/balloon_common.c b/mm/balloon_common.c index 54ed98653c78..abeee6882649 100644 --- a/mm/balloon_common.c +++ b/mm/balloon_common.c @@ -9,8 +9,42 @@ #include #include #include +#include #include +atomic_long_t mem_balloon_inflated_total_kb = ATOMIC_LONG_INIT(0); +atomic_long_t mem_balloon_inflated_free_kb = ATOMIC_LONG_INIT(0); +SRCU_NOTIFIER_HEAD_STATIC(balloon_chain); + +int register_balloon_notifier(struct notifier_block *nb) +{ + return srcu_notifier_chain_register(&balloon_chain, nb); +} +EXPORT_SYMBOL(register_balloon_notifier); + +void unregister_balloon_notifier(struct notifier_block *nb) +{ + srcu_notifier_chain_unregister(&balloon_chain, nb); +} +EXPORT_SYMBOL(unregister_balloon_notifier); + +static int balloon_notify(unsigned long val) +{ + return srcu_notifier_call_chain(&balloon_chain, val, NULL); +} + +void balloon_set_inflated_total(long inflated_kb) +{ + atomic_long_set(&mem_balloon_inflated_total_kb, inflated_kb); + balloon_notify(BALLOON_CHANGED_TOTAL); +} + +void balloon_set_inflated_free(long inflated_kb) +{ + atomic_long_set(&mem_balloon_inflated_free_kb, inflated_kb); + balloon_notify(BALLOON_CHANGED_FREE); +} + static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info, struct page *page) { -- 2.31.1