From nobody Tue Nov 4 05:26:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505998665049577.3753273569179; Thu, 21 Sep 2017 05:57:45 -0700 (PDT) Received: from localhost ([::1]:53553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv132-0006UJ-9G for importer@patchew.org; Thu, 21 Sep 2017 08:57:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv11E-0005Pf-O0 for qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:55:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dv119-00076J-TV for qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:55:52 -0400 Received: from mail-wr0-f175.google.com ([209.85.128.175]:54109) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dv119-00075h-LX for qemu-devel@nongnu.org; Thu, 21 Sep 2017 08:55:47 -0400 Received: by mail-wr0-f175.google.com with SMTP id l22so4542083wrc.10 for ; Thu, 21 Sep 2017 05:55:47 -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) 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=AHiBc7pTOontQVTknfWPtuhuUTkHebs3Lz2efALQCXN59d53G+ZOMqUhM+6Ik4x4rP CI9cFQBLZZH6oCcXddgj5PNG0hreqWDSq2iCCZJjaIxDsEA3TLMXqdy55/HybTpSLcmX tKsoJQFjsPIC/HCXkX/4LIpvVSV7jlV93JQADVnoMhlLj917anVHRTtWnE5qgEFJvx++ J73AmP6C1oiElgNhLhirFwb5B/TJ26PqneReTZw5j1mFnkToXwpHb8fZJtsCeIcIu6F1 doSQ9pR7iczUKpj5vccodHrlVIFqftbXDBRwrAD/7H71FqvHyKO6Wvrp5B5Gg75SCaN+ os+A== X-Gm-Message-State: AHPjjUjUdDQbBVKw4CCIz0qDxPRn6nD/uyxOn3On+HF4XHujQaabn/cN X2Yd6OoANkNCwhUMPYRfxYqGEQ== 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) 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 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.175 Subject: [Qemu-devel] [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , Wei Wang , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Shaohua Li , Huang Ying Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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=C3=A1=C5=A1 Golembiovsk=C3=BD --- 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_balloo= n.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 virti= o_balloon *vb) struct sysinfo i; unsigned int idx =3D 0; long available; + long cached; =20 all_vm_events(events); si_meminfo(&i); =20 available =3D si_mem_available(); =20 + cached =3D global_node_page_state(NR_FILE_PAGES) - + total_swapcache_pages() - i.bufferram; + if (cached < 0) + cached =3D 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)); =20 return idx; } diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virti= o_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 =20 /* * 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); =20 static atomic_t swapin_readahead_hits =3D ATOMIC_INIT(4); =20 --=20 2.14.1