122
123
int Chroot(const char* Target);
124
125
-void ConfigureMemoryReduction(int PageReportingOrder, LX_MINI_INIT_MEMORY_RECLAIM_MODE Mode);
125
+void ConfigureMemoryReduction(LX_MINI_INIT_MEMORY_RECLAIM_MODE Mode);
126
127
void CreateSwap(unsigned int Lun);
128
265
return 0;
266
}
267
268
-void ConfigureMemoryReduction(int PageReportingOrder, LX_MINI_INIT_MEMORY_RECLAIM_MODE Mode)
268
+void ConfigureMemoryReduction(LX_MINI_INIT_MEMORY_RECLAIM_MODE Mode)
269
270
/*++
271
272
Routine Description:
273
274
- This routine sets the page reporting order.
274
+ This routine configures memory reduction behavior including memory reclaim and compaction.
275
276
Arguments:
277
278
- PageReportingOrder - Supplies the page reporting order. This value determines the size of cold discard hints
279
- by using the equation: 2^PageReportingOrder * PAGE_SIZE
280
- Example: 2^9 * 4096 = 2MB
281
-
278
Mode - Supplies the memory reclaim mode.
279
280
Return Value:
286
try
287
{
288
//
293
- // Ensure the value falls within a reasonable range (single page to 2MB).
294
- //
295
-
296
- if (PageReportingOrder < 0 || PageReportingOrder > 9)
297
- {
298
- LOG_WARNING("Invalid page_reporting_order {}", PageReportingOrder);
299
- PageReportingOrder = 0;
300
- }
301
- else
302
- {
303
- WriteToFile("/sys/module/page_reporting/parameters/page_reporting_order", std::to_string(PageReportingOrder).c_str());
304
- }
305
-
306
- //
307
- // Create a worker thread to periodically check if the VM is idle and performs memory compaction.
308
- // This ensures that the maximum number of pages can be discarded to the host.
289
+ // Create a worker thread to periodically check if the VM is idle and performs memory compaction
290
+ // and memory reclaim. This ensures that the maximum number of pages can be discarded to the host.
291
//
310
- // N.B. Compaction is not needed if page reporting order is set to single page mode.
311
- //
312
-
313
- if (PageReportingOrder == 0 && Mode == LxMiniInitMemoryReclaimModeDisabled)
314
- {
315
- return;
316
- }
292
318
- std::thread([PageReportingOrder = PageReportingOrder, Mode = Mode]() mutable {
293
+ std::thread([Mode]() mutable {
294
try
295
{
296
//
397
398
//
399
// Perform memory compaction if the VM is idle.
425
- //
426
- // N.B. Memory compaction is not needed if the page reporting order is set to single page (0).
400
+ // This coalesces free pages into larger blocks for more efficient page reporting.
401
//
402
429
- if (PageReportingOrder != 0 && (Start - Stop) > IdleThreshold)
403
+ if ((Start - Stop) > IdleThreshold)
404
{
405
std::this_thread::sleep_for(std::chrono::seconds(1));
406
Stop = GetUserCpuTime();
3268
}
3269
3270
//
3297
- // Configure page reporting and memory reclamation.
3271
+ // Configure memory reclamation.
3272
//
3273
3300
- ConfigureMemoryReduction(EarlyConfig->PageReportingOrder, EarlyConfig->MemoryReclaimMode);
3274
+ ConfigureMemoryReduction(EarlyConfig->MemoryReclaimMode);
3275
3276
//
3277
// Initialize system distro if supported.