Re: [PATCH v3] virtio_balloon: include disk/file caches memory statistics

2017-11-20 Thread Tomáš Golembiovský
On Sun, 12 Nov 2017 13:05:38 +0100
Tomáš Golembiovský <tgole...@redhat.com> wrote:

> Add a new field VIRTIO_BALLOON_S_CACHES to virtio_balloon memory
> statistics protocol. The value represents all disk/file caches.
> 
> In this case it corresponds to the sum of values
> Buffers+Cached+SwapCached from /proc/meminfo.
> 
> Signed-off-by: Tomáš Golembiovský <tgole...@redhat.com>
> ---
>  drivers/virtio/virtio_balloon.c | 4 
>  include/uapi/linux/virtio_balloon.h | 3 ++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
 
ping


-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

[PATCH v3] virtio_balloon: include disk/file caches memory statistics

2017-11-12 Thread Tomáš Golembiovský
Add a new field VIRTIO_BALLOON_S_CACHES to virtio_balloon memory
statistics protocol. The value represents all disk/file caches.

In this case it corresponds to the sum of values
Buffers+Cached+SwapCached from /proc/meminfo.

Signed-off-by: Tomáš Golembiovský <tgole...@redhat.com>
---
 drivers/virtio/virtio_balloon.c | 4 
 include/uapi/linux/virtio_balloon.h | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index f0b3a0b9d42f..d2bd13bbaf9f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -244,11 +244,13 @@ static unsigned int update_balloon_stats(struct 
virtio_balloon *vb)
struct sysinfo i;
unsigned int idx = 0;
long available;
+   unsigned long caches;
 
all_vm_events(events);
si_meminfo();
 
available = si_mem_available();
+   caches = global_node_page_state(NR_FILE_PAGES);
 
 #ifdef CONFIG_VM_EVENT_COUNTERS
update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
@@ -264,6 +266,8 @@ 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_CACHES,
+   pages_to_bytes(caches));
 
return idx;
 }
diff --git a/include/uapi/linux/virtio_balloon.h 
b/include/uapi/linux/virtio_balloon.h
index 343d7ddefe04..4e8b8304b793 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -52,7 +52,8 @@ 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_AVAIL6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR   7
+#define VIRTIO_BALLOON_S_CACHES   7   /* Disk caches */
+#define VIRTIO_BALLOON_S_NR   8
 
 /*
  * Memory statistics structure.
-- 
2.15.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

2017-11-03 Thread Tomáš Golembiovský
On Tue, 31 Oct 2017 18:15:48 +0200
"Michael S. Tsirkin" <m...@redhat.com> wrote:

> On Tue, Oct 31, 2017 at 01:20:19PM +0100, Tomáš Golembiovský wrote:
> > ping
> > 
> > +Gil, +Amnon... could you maybe aid in reviewing the patch, please?
> > 
> > 
> > Tomas
> > 
> > On Sun, 22 Oct 2017 20:05:57 +0200
> > Tomáš Golembiovský <tgole...@redhat.com> wrote:
> > 
> > > On Thu, 19 Oct 2017 16:12:20 +0300
> > > "Michael S. Tsirkin" <m...@redhat.com> wrote:
> > > 
> > > > On Thu, Sep 21, 2017 at 02:55:41PM +0200, Tomáš Golembiovský wrote:  
> > > > > 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ý <tgole...@redhat.com>  
> > > > 
> > > > Does 'Buffers' actually make sense? It's a temporary storage -
> > > > wouldn't it be significantly out of date by the time
> > > > host receives it?  
> > > 
> > > That would be best answered by somebody from kernel. But my personal
> > > opinion is that it would not be out of date. The amount of memory
> > > dedicated to Buffers does not seem to fluctuate too much.
> > > 
> > > Tomas
> > > 
> 
> I would be inclined to say, just report
> global_node_page_state(NR_FILE_PAGES).
> Maybe subtract buffer ram.
> 
> It's not clear host cares about the distinction,
> it's all memory that can shrink in response to
> memory pressure such as inflating the balloon.

So in procfs terms we'd be sending sum Cached+SwapCahced.
Martin, would that be good enough?

I wonder whether it would still make sense to send Buffers as a separate
value though. Maybe we should forget about having some granularity here
and just report all the disk caches as one value.

Tomas

> 
> This statistic is portable as well I think, most guests have
> storage cache.
> 
> 
> > > > > ---
> > > > >  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();
> > > > >  
> > > > >   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_b

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

2017-10-31 Thread Tomáš Golembiovský
ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?


Tomas

On Sun, 22 Oct 2017 20:05:57 +0200
Tomáš Golembiovský <tgole...@redhat.com> wrote:

> On Thu, 19 Oct 2017 16:12:20 +0300
> "Michael S. Tsirkin" <m...@redhat.com> wrote:
> 
> > On Thu, Sep 21, 2017 at 02:55:41PM +0200, Tomáš Golembiovský wrote:  
> > > 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ý <tgole...@redhat.com>  
> > 
> > Does 'Buffers' actually make sense? It's a temporary storage -
> > wouldn't it be significantly out of date by the time
> > host receives it?  
> 
> That would be best answered by somebody from kernel. But my personal
> opinion is that it would not be out of date. The amount of memory
> dedicated to Buffers does not seem to fluctuate too much.
> 
> Tomas
> 
> 
> > > ---
> > >  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();
> > >  
> > >   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_AVAIL6   /* 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);  
> > 
> > Need an ack from MM crowd on that.
> >   
> > > -- 
> > > 2.14.1  
> 
> 
> -- 
> Tomáš Golembiovský <tgole...@redhat.com>


-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

2017-10-26 Thread Tomáš Golembiovský
On Thu, 19 Oct 2017 16:12:20 +0300
"Michael S. Tsirkin" <m...@redhat.com> wrote:

> On Thu, Sep 21, 2017 at 02:55:41PM +0200, Tomáš Golembiovský wrote:
> > 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ý <tgole...@redhat.com>
> 
> Does 'Buffers' actually make sense? It's a temporary storage -
> wouldn't it be significantly out of date by the time
> host receives it?

That would be best answered by somebody from kernel. But my personal
opinion is that it would not be out of date. The amount of memory
dedicated to Buffers does not seem to fluctuate too much.

Tomas


> > ---
> >  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();
> >  
> > 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_AVAIL6   /* 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);
> 
> Need an ack from MM crowd on that.
> 
> > -- 
> > 2.14.1


-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v2 0/1] linux: Buffers/caches in VirtIO Balloon driver stats

2017-10-26 Thread Tomáš Golembiovský
On Thu, 5 Oct 2017 15:51:18 +0200
Tomáš Golembiovský <tgole...@redhat.com> wrote:

> On Thu, 21 Sep 2017 14:55:40 +0200
> Tomáš Golembiovský <tgole...@redhat.com> wrote:
> 
> > Linux driver part
> > 
> > v2:
> > - fixed typos
> > 
> > Tomáš Golembiovský (1):
> >   virtio_balloon: include buffers and cached memory statistics
> > 
> >  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(-)
> > 
> > -- 
> > 2.14.1
> > 
> 
> ping

ping

-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v2 0/1] linux: Buffers/caches in VirtIO Balloon driver stats

2017-10-26 Thread Tomáš Golembiovský
On Thu, 21 Sep 2017 14:55:40 +0200
Tomáš Golembiovský <tgole...@redhat.com> wrote:

> Linux driver part
> 
> v2:
> - fixed typos
> 
> Tomáš Golembiovský (1):
>   virtio_balloon: include buffers and cached memory statistics
> 
>  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(-)
> 
> -- 
> 2.14.1
> 

ping

-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

[PATCH v2 0/1] linux: Buffers/caches in VirtIO Balloon driver stats

2017-10-26 Thread Tomáš Golembiovský
Linux driver part

v2:
- fixed typos

Tomáš Golembiovský (1):
  virtio_balloon: include buffers and cached memory statistics

 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(-)

-- 
2.14.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] virtio_balloon: include buffers and chached memory statistics

2017-10-26 Thread Tomáš Golembiovský
On Wed, 20 Sep 2017 17:48:36 +0200
Tomáš Golembiovský <tgole...@redhat.com> wrote:

> 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ý <tgole...@redhat.com>
> ---
>  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();
>  
>   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..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_AVAIL6   /* Available memory as in /proc */
> -#define VIRTIO_BALLOON_S_NR   7
> +#define VIRTIO_BALLOON_S_BUFFERS  7   /* Bufferes memory as in /proc */

I've just noticed I have a typo in the comment: 'Bufferes' should be
'Buffers'.

> +#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);
>  
> -- 
> 2.14.1
> 


-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

[PATCH] virtio_balloon: include buffers and chached memory statistics

2017-10-26 Thread Tomáš Golembiovský
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ý <tgole...@redhat.com>
---
 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();
 
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..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_AVAIL6   /* 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
 
 /*
  * 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);
 
-- 
2.14.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [Qemu-devel] [RFC] Buffers/caches in VirtIO Balloon driver stats

2017-10-26 Thread Tomáš Golembiovský
On Tue, 29 Aug 2017 20:01:53 +0800
Wei Wang <wei.w.w...@intel.com> wrote:

> On 08/29/2017 05:57 PM, Stefan Hajnoczi wrote:
> > On Sun, Aug 27, 2017 at 11:30:33PM +0200, Tomáš Golembiovský wrote:  
> >> Hi,  
> > I have CCed the relevant mailing lists and people most recently involved
> > in virtio-balloon discussions.  Hopefully this will help get the right
> > people to see your questions.
> >  
> >> We'd like to include information about reclaimable memory into the
> >> statistics in VirtiO Balloon driver. Namely, we'd like to include
> >> counters for bufferes and caches of Linux kernel. The patch itself is
> >> pretty trivial -- no problem there. But before we do that I'd like to
> >> get some input from the QEMU community.
> >>
> >> 1) Is there any reason not to have the stats there?  
> 
> Could you please share the usages of reclaimable memory via the stats?

I'll go ahead then and start sending patches. What would be the proper
course of action here? Send patch for the driver first, or send patch
for QEMU first or send both patches right away?


> >>
> >> 2) Considering the balloon device is multiplatform (Linux, BSD,
> >> Windows), is there a problem with including buffers/caches? These seem
> >> to be specific to the Linux virtual memory subsystem. Of course, other
> >> OSes could just report zeros. Are there some internal stats on those
> >> OSes that could be filled in? I don't now if such or similar statistic
> >> are available on BSD. On Windows only SystemCache stat looks like
> >> something relevant. Anyone familiar with those OSes has any suggestions?
> >>
> >>   
> 
> One of the solutions that I'm thinking about is to make virtio 
> platform-ware.

This is not necessary. IIUC the driver does not need to send all the
stats. We can simply treat those stats as specific to Linux driver and
other drivers will not send them. Then QEMU will treat them as if zero
was reported.

> 
> That is, the device by default supports
> VIRTIO_F_LINUX,
> VIRTIO_F_WINDOWS,
> VIRTIO_F_BSD.
> 
> For the Linux driver, only VIRTIO_F_LINUX is supported, then we can
> have Linux specific driver implementations under that feature.


Since there were no suggestions for similar stats on other OSes I'd say
we treat the stats for buffers and caches as Linux specific. If there is
any need to send similar stats for other OSes we will add new stat fields
(specific for that particular OS).


Thanks,

Tomas

-- 
Tomáš Golembiovský <tgole...@redhat.com>
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization