From patchwork Thu Sep 21 12:55:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= X-Patchwork-Id: 9963889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8506A600C5 for ; Thu, 21 Sep 2017 12:55:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77C2D294D0 for ; Thu, 21 Sep 2017 12:55:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C96B294D3; Thu, 21 Sep 2017 12:55:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10165294D0 for ; Thu, 21 Sep 2017 12:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751724AbdIUMzt (ORCPT ); Thu, 21 Sep 2017 08:55:49 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:52805 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751387AbdIUMzr (ORCPT ); Thu, 21 Sep 2017 08:55:47 -0400 Received: by mail-wr0-f180.google.com with SMTP id c23so4486771wrg.9 for ; Thu, 21 Sep 2017 05:55:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QQqrEZhzMM/+LPQeNrEAB3OmSWcWViwH5vxzDcJ1SMQ=; b=WVrOhPNwvbDOqYEISLRvBIj5GZzML+bpspqKHFFrI0X++UJoi4mrthZ+BWArVPLbd7 +22tAic/XBG1Pm2Fi4UGXUzsYqzAc4Lg7oweemzyNvLxmSXbmNlbGBY62qdSI8mZft7D SB5kMjaPP4n1bpbxtIMa/AcKt/1bkpr0mKJWIcw51QgGXtxlOGMyh+2uiwR/q2pQ4KhS cIuqoRxrYBO9yr5UwrmhS/e7huWRd8tGcAxpO57YIFdCxpo1Z2CESObzJQsZIpSThNIh U24U/WFQoX98VMQrzhfR8NFvM49fWf+/2PHqLVrjsUkep3nDeI486/BSGwYCscPMTY6Y Y3sQ== X-Gm-Message-State: AHPjjUjQ+k8hUW5qw3+zfdQJl7V9MSfWK7eT9LBXQkI/2vO+1RS9E/PE l4L/tIMWmKzuwPdlPnYzhvIZFQ== X-Google-Smtp-Source: AOwi7QDZbgQWdW/t/4R/pgDGFJ4rMVWCpC5nu6dvTB9eRoNG0jzD5YiG9r0TrFm/1txlhNOWJ75I1w== X-Received: by 10.223.146.129 with SMTP id 1mr1968703wrn.1.1505998546442; Thu, 21 Sep 2017 05:55:46 -0700 (PDT) Received: from fiorina.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id e77sm3382129wmf.27.2017.09.21.05.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 05:55:45 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, qemu-devel@nongnu.org, kvm@vger.kernel.org, virtio-dev@lists.oasis-open.org Cc: Wei Wang , Shaohua Li , Huang Ying , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Subject: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics Date: Thu, 21 Sep 2017 14:55:41 +0200 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo. To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules. Signed-off-by: Tomáš Golembiovský --- drivers/virtio/virtio_balloon.c | 11 +++++++++++ include/uapi/linux/virtio_balloon.h | 4 +++- mm/swap_state.c | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index f0b3a0b9d42f..c2558ec47a62 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb) struct sysinfo i; unsigned int idx = 0; long available; + long cached; all_vm_events(events); si_meminfo(&i); available = si_mem_available(); + cached = global_node_page_state(NR_FILE_PAGES) - + total_swapcache_pages() - i.bufferram; + if (cached < 0) + cached = 0; + + #ifdef CONFIG_VM_EVENT_COUNTERS update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, pages_to_bytes(events[PSWPIN])); @@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb) pages_to_bytes(i.totalram)); update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL, pages_to_bytes(available)); + update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS, + pages_to_bytes(i.bufferram)); + update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED, + pages_to_bytes(cached)); return idx; } diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virtio_balloon.h index 343d7ddefe04..d5dc8a56a497 100644 --- a/include/uapi/linux/virtio_balloon.h +++ b/include/uapi/linux/virtio_balloon.h @@ -52,7 +52,9 @@ struct virtio_balloon_config { #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ #define VIRTIO_BALLOON_S_AVAIL 6 /* Available memory as in /proc */ -#define VIRTIO_BALLOON_S_NR 7 +#define VIRTIO_BALLOON_S_BUFFERS 7 /* Buffers memory as in /proc */ +#define VIRTIO_BALLOON_S_CACHED 8 /* Cached memory as in /proc */ +#define VIRTIO_BALLOON_S_NR 9 /* * Memory statistics structure. diff --git a/mm/swap_state.c b/mm/swap_state.c index 71ce2d1ccbf7..f3a4ff7d6c52 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void) rcu_read_unlock(); return ret; } +EXPORT_SYMBOL_GPL(total_swapcache_pages); static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);