drivers/virtio/virtio_balloon.c
Source file repositories/reference/linux-study-clean/drivers/virtio/virtio_balloon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virtio/virtio_balloon.c- Extension
.c- Size
- 35329 bytes
- Lines
- 1203
- Domain
- Driver Families
- Bucket
- drivers/virtio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/virtio.hlinux/virtio_balloon.hlinux/swap.hlinux/workqueue.hlinux/delay.hlinux/slab.hlinux/module.hlinux/balloon.hlinux/oom.hlinux/wait.hlinux/mm.hlinux/page_reporting.h
Detected Declarations
struct virtio_balloonenum virtio_balloon_vqenum virtio_balloon_config_readfunction page_to_balloon_pfnfunction start_wakeup_eventfunction process_wakeup_eventfunction finish_wakeup_eventfunction balloon_ackfunction tell_hostfunction virtballoon_free_page_reportfunction set_page_pfnsfunction fill_balloonfunction list_for_each_entry_safefunction release_pages_balloonfunction list_for_each_entry_safefunction leak_balloonfunction update_statfunction update_balloon_vm_statsfunction update_balloon_vm_statsfunction update_balloon_statsfunction requestfunction stats_handle_requestfunction towards_targetfunction return_free_pages_to_mmfunction list_for_each_entry_safefunction virtio_balloon_queue_free_page_workfunction start_update_balloon_sizefunction virtballoon_changedfunction update_balloon_sizefunction update_balloon_stats_funcfunction update_balloon_size_funcfunction init_vqsfunction virtio_balloon_cmd_id_receivedfunction send_cmd_id_startfunction send_cmd_id_stopfunction get_free_page_and_sendfunction send_free_pagesfunction virtio_balloon_report_free_pagefunction report_free_page_funcfunction virtio32_to_cpufunction virtballoon_migratepagefunction shrink_free_pagesfunction virtio_balloon_shrinker_scanfunction virtio_balloon_shrinker_countfunction virtio_balloon_oom_notifyfunction virtio_balloon_unregister_shrinkerfunction virtio_balloon_register_shrinkerfunction virtballoon_probe
Annotated Snippet
struct virtio_balloon {
struct virtio_device *vdev;
struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_page_vq;
/* Balloon's own wq for cpu-intensive work items */
struct workqueue_struct *balloon_wq;
/* The free page reporting work item submitted to the balloon wq */
struct work_struct report_free_page_work;
/* The balloon servicing is delegated to a freezable workqueue. */
struct work_struct update_balloon_stats_work;
struct work_struct update_balloon_size_work;
/* Prevent updating balloon when it is being canceled. */
spinlock_t stop_update_lock;
bool stop_update;
/* Bitmap to indicate if reading the related config fields are needed */
unsigned long config_read_bitmap;
/* The list of allocated free pages, waiting to be given back to mm */
struct list_head free_page_list;
spinlock_t free_page_list_lock;
/* The number of free page blocks on the above list */
unsigned long num_free_page_blocks;
/*
* The cmd id received from host.
* Read it via virtio_balloon_cmd_id_received to get the latest value
* sent from host.
*/
u32 cmd_id_received_cache;
/* The cmd id that is actively in use */
__virtio32 cmd_id_active;
/* Buffer to store the stop sign */
__virtio32 cmd_id_stop;
/* Waiting for host to ack the pages we released. */
wait_queue_head_t acked;
/* Number of balloon pages we've told the Host we're not using. */
unsigned int num_pages;
/*
* The pages we've told the Host we're not using are enqueued
* at vb_dev_info->pages list.
* Each page on this list adds VIRTIO_BALLOON_PAGES_PER_PAGE
* to num_pages above.
*/
struct balloon_dev_info vb_dev_info;
/* Synchronize access/update to this struct virtio_balloon elements */
struct mutex balloon_lock;
/* The array of pfns we tell the Host about. */
unsigned int num_pfns;
__virtio32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX];
/* Memory statistics */
struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
/* Shrinker to return free pages - VIRTIO_BALLOON_F_FREE_PAGE_HINT */
struct shrinker *shrinker;
/* OOM notifier to deflate on OOM - VIRTIO_BALLOON_F_DEFLATE_ON_OOM */
struct notifier_block oom_nb;
/* Free page reporting device */
struct virtqueue *reporting_vq;
struct page_reporting_dev_info pr_dev_info;
/* State for keeping the wakeup_source active while adjusting the balloon */
spinlock_t wakeup_lock;
bool processing_wakeup_event;
u32 wakeup_signal_mask;
};
#define VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST (1 << 0)
#define VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS (1 << 1)
static const struct virtio_device_id id_table[] = {
{ VIRTIO_ID_BALLOON, VIRTIO_DEV_ANY_ID },
{ 0 },
};
static u32 page_to_balloon_pfn(struct page *page)
{
unsigned long pfn = page_to_pfn(page);
BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT);
/* Convert pfn from Linux page size to balloon page size. */
return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
}
Annotation
- Immediate include surface: `linux/virtio.h`, `linux/virtio_balloon.h`, `linux/swap.h`, `linux/workqueue.h`, `linux/delay.h`, `linux/slab.h`, `linux/module.h`, `linux/balloon.h`.
- Detected declarations: `struct virtio_balloon`, `enum virtio_balloon_vq`, `enum virtio_balloon_config_read`, `function page_to_balloon_pfn`, `function start_wakeup_event`, `function process_wakeup_event`, `function finish_wakeup_event`, `function balloon_ack`, `function tell_host`, `function virtballoon_free_page_report`.
- Atlas domain: Driver Families / drivers/virtio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.