@@ -40,6 +40,15 @@ The device can be configured with the following options:
4040 the virtio balloon statistics and otherwise represents the interval of time in
4141 seconds at which the balloon statistics are updated.
4242
43+ The device has two optional features which can be enabled with the following
44+ options:
45+
46+ - ` free_page_reporting ` : A mechanism for the guest to continually report ranges
47+ of memory which the guest is not using and can be reclaimed. Read more here
48+ - ` free_page_hinting ` : A dev-preview feature which is a different mechanism to
49+ reclaim memory from the guest, this is instead triggered from the host. Read
50+ more here.
51+
4352## Security disclaimer
4453
4554** The balloon device is a paravirtualized virtio device that requires
@@ -162,7 +171,7 @@ curl --unix-socket $socket_location -i \
162171On success, this request returns a JSON object of the same structure as the one
163172used to configure the device (via a PUT request on "/balloon").
164173
165- ## Operating the balloon device
174+ ## Operating the traditional balloon device
166175
167176After it has been installed, the balloon device can only be operated via the API
168177through the following command:
@@ -238,9 +247,9 @@ device has support for the following statistics:
238247- ` VIRTIO_BALLOON_S_HTLB_PGFAIL ` : The number of failed hugetlb page allocations
239248 in the guest.
240249
241- The driver is querried for updated statistics every time the amount of time
250+ The driver is queried for updated statistics every time the amount of time
242251specified in that field passes. The driver may not provide all the statistics
243- when querried , in which case the old values of the missing statistics are
252+ when queried , in which case the old values of the missing statistics are
244253preserved.
245254
246255To change the statistics polling interval, users can sent a PATCH request on
@@ -264,19 +273,60 @@ Furthermore, if the balloon was configured with statistics pre-boot through a
264273non-zero ` stats_polling_interval_s ` value, the statistics cannot be disabled
265274through a ` polling_interval ` value of zero post-boot.
266275
276+ ## Virtio balloon free page reporting
277+
278+ Free page reporting is a virtio balloon feature which allows the guest OS to
279+ report ranges of memory which are not being used. In Firecracker, the balloon
280+ device will ` madvise ` the range with the ` MADV_DONTNEED ` flag, reducing the RSS
281+ of the guest. Reporting can only be enabled pre-boot and will run continually
282+ with no option to stop it running. The feature also requires the guest to have
283+ the ` PAGE_REPORTING ` feature enabled.
284+
285+ To enable free page reporting when creating the balloon device, the
286+ ` free_page_reporting ` attribute should be set in the JSON object.
287+
288+ An example of how to configure the device to enable free page reporting:
289+
290+ ``` console
291+ socket_location=...
292+ amount_mib=...
293+ deflate_on_oom=...
294+ polling_interval=...
295+
296+ curl --unix-socket $socket_location -i \
297+ -X PUT 'http://localhost/balloon' \
298+ -H 'Accept: application/json' \
299+ -H 'Content-Type: application/json' \
300+ -d "{
301+ \"amount_mib\": $amount_mib, \
302+ \"deflate_on_oom\": $deflate_on_oom, \
303+ \"stats_polling_interval_s\": $polling_interval, \
304+ \"free_page_reporting\": true \
305+ }"
306+ ```
307+
308+ The Linux driver uses a hook in the free page path to trigger the reporting
309+ process, which will begin after a short delay (~ 2 seconds) and report the
310+ ranges. The runtime impact of this feature is heavily workload dependent. The
311+ driver gets ranges from the buddy allocator with a minimum page order. This page
312+ order dictates the minimum size of ranges reported and can be configured with
313+ the ` page_reporting_order ` module parameter in the guest kernel. The page order
314+ comes with trade-offs between performance and memory reclaimed; a good target is
315+ to have the reported ranges match the backing page size.
316+
267317## Balloon Caveats
268318
269319- Firecracker has no control over the speed of inflation or deflation; this is
270320 dictated by the guest kernel driver.
271321
272- - The balloon will continually attempt to reach its target size, which can be a
273- CPU-intensive process. It is therefore recommended to set realistic targets
274- or, after a period of stagnation in the inflation, update the target size to
275- be close to the inflated size.
322+ - The traditional balloon will continually attempt to reach its target size,
323+ which can be a CPU-intensive process. It is therefore recommended to set
324+ realistic targets or, after a period of stagnation in the inflation, update
325+ the target size to be close to the inflated size.
276326
277327- The ` deflate_on_oom ` flag is a mechanism to prevent the guest from crashing or
278328 terminating processes; it is not meant to be used continually to free memory.
279- Doing this will be a CPU-intensive process, as the balloon driver is designed
280- to deflate and release memory slowly. This is also compounded if the balloon
281- has yet to reach its target size, as it will attempt to inflate while also
282- deflating.
329+ Doing this will be a CPU-intensive process, as the traditional balloon driver
330+ is designed to deflate and release memory slowly. This is also compounded if
331+ the balloon has yet to reach its target size, as it will attempt to inflate
332+ while also deflating.
0 commit comments