From nobody Mon Nov 3 14:13:44 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 1505922726368322.5527669162095; Wed, 20 Sep 2017 08:52:06 -0700 (PDT) Received: from localhost ([::1]:49092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duhID-0000Rk-GJ for importer@patchew.org; Wed, 20 Sep 2017 11:52:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duhF0-0006fM-Sr for qemu-devel@nongnu.org; Wed, 20 Sep 2017 11:48:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duhEv-00031x-NZ for qemu-devel@nongnu.org; Wed, 20 Sep 2017 11:48:46 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:52754) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1duhEv-0002xn-GB for qemu-devel@nongnu.org; Wed, 20 Sep 2017 11:48:41 -0400 Received: by mail-wr0-f176.google.com with SMTP id c23so2522243wrg.9 for ; Wed, 20 Sep 2017 08:48:39 -0700 (PDT) Received: from fiorina.redhat.com (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id f10sm2057444wrg.20.2017.09.20.08.48.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 08:48:37 -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:mime-version :content-transfer-encoding; bh=gKAizjl91g47sZ0BeAIJdgBb3Aucowd+HtPJRUJREMc=; b=Dihhha+VQyxlzf1ZnaOqAcfs8sFJ44SPfxHWeVqOiCqcm0ocPFY2VAuxJxXabY1kyR J87kzR2fJw39W+PJgkNLz+/0n7BBlsjKgRVf0CIRsST0jFKv9twPOhiNompqmQ/plWcr KjeJ0WBfhlS/AcevbldtjacVCQ0Um8C6dOuHxkspxmYoUTGqrGrQHk0O0hQcwA+cONKg 7HSgY+OvqFQYDZd4xEXkM2TxbpkBObGj4xz1BePrcXGoyBR4gP5MO346Vi+K/32qbIjZ Wn7r0F20sTbKh4tXu0GdLqZNptDU7hZbrLMKF8bw57NTABixWyfU0Ci3KEGYJN5bbWXa v+hg== X-Gm-Message-State: AHPjjUi8B53esXMjt2WRYhM8fGHCSHYf5e/Y49OWYJLXKyQtkVga8x+q nVHcEOTir1ANtc17wzo3r0EbyA== X-Google-Smtp-Source: AOwi7QCGYktEZqa/kHrBin9rdtxiXkzH07u2vyM/MMQklFMk/oLj/ifTchNI9VolFFOa3Xx9jz4Kiw== X-Received: by 10.223.168.110 with SMTP id l101mr2472215wrc.215.1505922518627; Wed, 20 Sep 2017 08:48:38 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Date: Wed, 20 Sep 2017 17:48:36 +0200 Message-Id: <0bc0c49663fafdf3b03844fe048cac3216d88c5b.1505922364.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.14.1 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.176 Subject: [Qemu-devel] [PATCH] virtio_balloon: include buffers and chached 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..119224c34389 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 /* Bufferes 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