Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1669605rwb; Wed, 5 Oct 2022 03:03:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YssZHxlb+fAny4qcB4qPidmob3vdzGnQDheHMxTKhCTvelBmhiKpthpI6Lq171XrPEVsI X-Received: by 2002:a17:907:7dab:b0:782:fe13:6102 with SMTP id oz43-20020a1709077dab00b00782fe136102mr22437878ejc.617.1664964219502; Wed, 05 Oct 2022 03:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664964219; cv=none; d=google.com; s=arc-20160816; b=WkCApAbBoU49fCk+8N29+sx848M7Zu1DkMimE3MiHaH3QxxzH1tYp+WSs5ahx/k595 V1ZdEt7v/hegQP3n2Wu6uyH9W7rzo94psJzUx1XiEhDsuCvRahzQ7QyocdgZ0vVQpENl Km3zQDW3n9piVyH1xNhboi5JiNU4uJUqGIMzldJA6r9BlBydDfhaRjT1PPhvPZ3mWZZg +U2aNtkpdtBIE5HsD3vfTbY5gGk/AkKPcBO151emi6fNUs5voeffGWhfI2Tngi1OPsdr gSdKEHVsj1P7V1orbgmIqq9Vrr5H+rkQpDIFuvES/grZAkW381r4Yzz6R2bBA9AmMelJ FA1Q== 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=UZ+rupz0I0JmelXDykp/sAwF2YGfDdjWZPVBSl8/mrRZ3DnNdD64ghZ2YmXcP03QLc vRrWgcM2sOQWY+NiFQMdx2J+qOtLMmZATYvs+MXSE/VuLx4dISDCkrxuHGSGo8iy1MuA h5ctatiC4re6a9V0JB1OczcOtnwghUNdNwxXrLOeQIDNjl6bdSu8m3ZGqHVtJlAR3X0V Z+vXQQM2ljFAhQRDsfNqZV1Hl0gRon9BcFdp+IJYIMQRJlcZZJeRtJzl2RJwfzY431jb 8MCCP/wrF5uH+P4WK4hcGyZU7ebGN+lO8yoJ8kzBUEmvqTHyGBI1eVd96dbxzXxq9I0W BleA== 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 sd16-20020a1709076e1000b00781dbee4273si13421886ejc.514.2022.10.05.03.03.10; Wed, 05 Oct 2022 03:03:39 -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 S230179AbiJEJED (ORCPT + 99 others); Wed, 5 Oct 2022 05:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiJEJDz (ORCPT ); Wed, 5 Oct 2022 05:03:55 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA2E1760EC for ; Wed, 5 Oct 2022 02:03:52 -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 1og0GL-007ckN-6V; Wed, 05 Oct 2022 11:02:45 +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 v4 2/7] Enable balloon drivers to report inflated memory Date: Wed, 5 Oct 2022 12:01:52 +0300 Message-Id: <20221005090158.2801592-3-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221005090158.2801592-1-alexander.atanasov@virtuozzo.com> References: <20221005090158.2801592-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 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