Skip to content

Commit 74c025c

Browse files
pizhenweimstsirkin
authored andcommitted
virtio_balloon: introduce memory scan/reclaim info
Expose memory scan/reclaim information to the host side via virtio balloon device. Now we have a metric to analyze the memory performance: y: counter increases n: counter does not changes h: the rate of counter change is high l: the rate of counter change is low OOM: VIRTIO_BALLOON_S_OOM_KILL STALL: VIRTIO_BALLOON_S_ALLOC_STALL ASCAN: VIRTIO_BALLOON_S_SCAN_ASYNC DSCAN: VIRTIO_BALLOON_S_SCAN_DIRECT ARCLM: VIRTIO_BALLOON_S_RECLAIM_ASYNC DRCLM: VIRTIO_BALLOON_S_RECLAIM_DIRECT - OOM[y], STALL[*], ASCAN[*], DSCAN[*], ARCLM[*], DRCLM[*]: the guest runs under really critial memory pressure - OOM[n], STALL[h], ASCAN[*], DSCAN[l], ARCLM[*], DRCLM[l]: the memory allocation stalls due to cgroup, not the global memory pressure. - OOM[n], STALL[h], ASCAN[*], DSCAN[h], ARCLM[*], DRCLM[h]: the memory allocation stalls due to global memory pressure. The performance gets hurt a lot. A high ratio between DRCLM/DSCAN shows quite effective memory reclaiming. - OOM[n], STALL[h], ASCAN[*], DSCAN[h], ARCLM[*], DRCLM[l]: the memory allocation stalls due to global memory pressure. the ratio between DRCLM/DSCAN gets low, the guest OS is thrashing heavily, the serious case leads poor performance and difficult trouble shooting. Ex, sshd may block on memory allocation when accepting new connections, a user can't login a VM by ssh command. - OOM[n], STALL[n], ASCAN[h], DSCAN[n], ARCLM[l], DRCLM[n]: the low ratio between ARCLM/ASCAN shows that the guest tries to reclaim more memory, but it can't. Once more memory is required in future, it will struggle to reclaim memory. Acked-by: David Hildenbrand <[email protected]> Signed-off-by: zhenwei pi <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent c5b70a2 commit 74c025c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

drivers/virtio/virtio_balloon.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ static inline unsigned int update_balloon_vm_stats(struct virtio_balloon *vb)
373373

374374
update_stat(vb, idx++, VIRTIO_BALLOON_S_ALLOC_STALL, stall);
375375

376+
update_stat(vb, idx++, VIRTIO_BALLOON_S_ASYNC_SCAN,
377+
pages_to_bytes(events[PGSCAN_KSWAPD]));
378+
update_stat(vb, idx++, VIRTIO_BALLOON_S_DIRECT_SCAN,
379+
pages_to_bytes(events[PGSCAN_DIRECT]));
380+
update_stat(vb, idx++, VIRTIO_BALLOON_S_ASYNC_RECLAIM,
381+
pages_to_bytes(events[PGSTEAL_KSWAPD]));
382+
update_stat(vb, idx++, VIRTIO_BALLOON_S_DIRECT_RECLAIM,
383+
pages_to_bytes(events[PGSTEAL_DIRECT]));
384+
376385
#ifdef CONFIG_HUGETLB_PAGE
377386
update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGALLOC,
378387
events[HTLB_BUDDY_PGALLOC]);

include/uapi/linux/virtio_balloon.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ struct virtio_balloon_config {
7373
#define VIRTIO_BALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */
7474
#define VIRTIO_BALLOON_S_OOM_KILL 10 /* OOM killer invocations */
7575
#define VIRTIO_BALLOON_S_ALLOC_STALL 11 /* Stall count of memory allocatoin */
76-
#define VIRTIO_BALLOON_S_NR 12
76+
#define VIRTIO_BALLOON_S_ASYNC_SCAN 12 /* Amount of memory scanned asynchronously */
77+
#define VIRTIO_BALLOON_S_DIRECT_SCAN 13 /* Amount of memory scanned directly */
78+
#define VIRTIO_BALLOON_S_ASYNC_RECLAIM 14 /* Amount of memory reclaimed asynchronously */
79+
#define VIRTIO_BALLOON_S_DIRECT_RECLAIM 15 /* Amount of memory reclaimed directly */
80+
#define VIRTIO_BALLOON_S_NR 16
7781

7882
#define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \
7983
VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \
@@ -87,7 +91,11 @@ struct virtio_balloon_config {
8791
VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \
8892
VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures", \
8993
VIRTIO_BALLOON_S_NAMES_prefix "oom-kills", \
90-
VIRTIO_BALLOON_S_NAMES_prefix "alloc-stalls" \
94+
VIRTIO_BALLOON_S_NAMES_prefix "alloc-stalls", \
95+
VIRTIO_BALLOON_S_NAMES_prefix "async-scans", \
96+
VIRTIO_BALLOON_S_NAMES_prefix "direct-scans", \
97+
VIRTIO_BALLOON_S_NAMES_prefix "async-reclaims", \
98+
VIRTIO_BALLOON_S_NAMES_prefix "direct-reclaims" \
9199
}
92100

93101
#define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("")

0 commit comments

Comments
 (0)