Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2239849rwa; Mon, 22 Aug 2022 04:46:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4xOjycBdI/bxYCq6KMrXVv2c51hDZRMefpLen0paVFS1e0tKFPuX9PCz+h4bNdjFG+JTaE X-Received: by 2002:a17:907:2cd8:b0:73d:8af4:e0ba with SMTP id hg24-20020a1709072cd800b0073d8af4e0bamr1365986ejc.586.1661168768278; Mon, 22 Aug 2022 04:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661168768; cv=none; d=google.com; s=arc-20160816; b=slr9Fu8NO3nSD1yx4eGIEpeIkWjO+VM6mWyCDSAe6+TfRl7zia6VG/Rdf0j+87jxL5 PP80lMhwRmCGW1Zer20x+Fsms/Gi9mrLCco8NkIeeilHyZW4j5KHiJH+KtHwLXQEHa+k IaoawlSQ+uB+mvwDr2cyDmy7HwF/q1a2lK3ZJnI36kw67/nBLv4apVtOu2/yXkOn//Sj JzLaZk75p+Mp8efJgehgHQMtwGu93kZ9qGbEaSgoy4HipOGpz4DERTpeERjBDnjTFP2t eAp+FG9x+DY5LdwcDbzebxxBCWoX+IfVGRsqpiiklHSVUMNX6xj2i74RMFZGNQ2QrS2o jDXg== 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=W1Qualv07jAb7hBW1fXyEkKq4YxXnRaD0fxYQrBWXEw=; b=d4MuMCRVASc9u/+RiO3UaBQcO7fQULRwibaerIfC4U03b9q4/UfpfwjGzCnxHDOdY7 SlEMHzDQW8+RnUARDoS+tsIYSEiL3F8IKeACB3AzkvsWDvOY2bq5+KKEeIAu8oTJ4RkM vfI1WuE0ngy54zevnBh05+qDmlYN+sRrIPQ1iiXcMyvGVkCPUdBuWFHAdHaojqjlUChb TwltvT+qZcMgwlsSBFUqCpRIkJXJaC7RsOGYFDSGbyW0gpvzAUqqCQ0HnNEIKaNcFy8y bxe0HAzu4eUBceuzXTCoCDZUHF6Ech7tMHzHLQ1fbq7bdrE4cFHCzS68IJ4yHIT3+HG9 m62w== 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 i6-20020a1709064fc600b0073d6a126ca1si6165030ejw.541.2022.08.22.04.45.42; Mon, 22 Aug 2022 04:46:08 -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 S233522AbiHVLiV (ORCPT + 99 others); Mon, 22 Aug 2022 07:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234270AbiHVLiS (ORCPT ); Mon, 22 Aug 2022 07:38:18 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF5E72608 for ; Mon, 22 Aug 2022 04:38:16 -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 1oQ5jW-00Gyo9-Jf; Mon, 22 Aug 2022 13:38:05 +0200 From: Alexander Atanasov To: Andrew Morton Cc: kernel@openvz.org, Alexander Atanasov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 2/4] Enable balloon drivers to report inflated memory Date: Mon, 22 Aug 2022 14:37:45 +0300 Message-Id: <20220822113747.3630776-3-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822113747.3630776-1-alexander.atanasov@virtuozzo.com> References: <20220822113747.3630776-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.h | 18 ++++++++++++++++++ mm/balloon.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/linux/balloon.h b/include/linux/balloon.h index 46ac8f61f607..59657da77d95 100644 --- a/include/linux/balloon.h +++ b/include/linux/balloon.h @@ -57,6 +57,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 + +int register_balloon_notifier(struct notifier_block *nb); +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); \ +}) + struct page *balloon_page_alloc(void); void balloon_page_enqueue(struct balloon_dev_info *b_dev_info, struct page *page); diff --git a/mm/balloon.c b/mm/balloon.c index 22b3e876bc78..8e1d5855fef8 100644 --- a/mm/balloon.c +++ b/mm/balloon.c @@ -7,8 +7,44 @@ #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); +} +EXPORT_SYMBOL(balloon_set_inflated_total); + +void balloon_set_inflated_free(long inflated_kb) +{ + atomic_long_set(&mem_balloon_inflated_free_kb, inflated_kb); + balloon_notify(BALLOON_CHANGED_FREE); +} +EXPORT_SYMBOL(balloon_set_inflated_free); + static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info, struct page *page) { -- 2.31.1