Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

virtio_balloon: separate vm events into a function

All the VM events related statistics have dependence on
'CONFIG_VM_EVENT_COUNTERS', separate these events into a function to
make code clean. Then we can remove 'CONFIG_VM_EVENT_COUNTERS' from
'update_balloon_stats'.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20240423034109.1552866-2-pizhenwei@bytedance.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>

authored by

zhenwei pi and committed by
Michael S. Tsirkin
fdba68d2 8b6c724c

+29 -14
+29 -14
drivers/virtio/virtio_balloon.c
··· 349 349 350 350 #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT) 351 351 352 - static unsigned int update_balloon_stats(struct virtio_balloon *vb) 352 + #ifdef CONFIG_VM_EVENT_COUNTERS 353 + /* Return the number of entries filled by vm events */ 354 + static inline unsigned int update_balloon_vm_stats(struct virtio_balloon *vb) 353 355 { 354 356 unsigned long events[NR_VM_EVENT_ITEMS]; 355 - struct sysinfo i; 356 357 unsigned int idx = 0; 357 - long available; 358 - unsigned long caches; 359 358 360 359 all_vm_events(events); 361 - si_meminfo(&i); 362 - 363 - available = si_mem_available(); 364 - caches = global_node_page_state(NR_FILE_PAGES); 365 - 366 - #ifdef CONFIG_VM_EVENT_COUNTERS 367 360 update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, 368 - pages_to_bytes(events[PSWPIN])); 361 + pages_to_bytes(events[PSWPIN])); 369 362 update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT, 370 - pages_to_bytes(events[PSWPOUT])); 363 + pages_to_bytes(events[PSWPOUT])); 371 364 update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]); 372 365 update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]); 366 + 373 367 #ifdef CONFIG_HUGETLB_PAGE 374 368 update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGALLOC, 375 369 events[HTLB_BUDDY_PGALLOC]); 376 370 update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGFAIL, 377 371 events[HTLB_BUDDY_PGALLOC_FAIL]); 378 - #endif 379 - #endif 372 + #endif /* CONFIG_HUGETLB_PAGE */ 373 + 374 + return idx; 375 + } 376 + #else /* CONFIG_VM_EVENT_COUNTERS */ 377 + static inline unsigned int update_balloon_vm_stats(struct virtio_balloon *vb) 378 + { 379 + return 0; 380 + } 381 + #endif /* CONFIG_VM_EVENT_COUNTERS */ 382 + 383 + static unsigned int update_balloon_stats(struct virtio_balloon *vb) 384 + { 385 + struct sysinfo i; 386 + unsigned int idx; 387 + long available; 388 + unsigned long caches; 389 + 390 + idx = update_balloon_vm_stats(vb); 391 + 392 + si_meminfo(&i); 393 + available = si_mem_available(); 394 + caches = global_node_page_state(NR_FILE_PAGES); 380 395 update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE, 381 396 pages_to_bytes(i.freeram)); 382 397 update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,