mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-31 02:35:39 +00:00
Request maximum map counts
This commit is contained in:
@@ -683,7 +683,15 @@ public:
|
||||
total_physical >> 20, MinimumTotalPhysical >> 20);
|
||||
return 0;
|
||||
}
|
||||
const u64 max_map_count = Common::GetMaxMapCount();
|
||||
constexpr u64 ReservedMaps = 24576;
|
||||
if (max_map_count == 0 || max_map_count <= ReservedMaps) {
|
||||
LOG_WARNING(HW_Memory,
|
||||
"Skipping hardware buffer backing, vm.max_map_count is unknown or too low");
|
||||
return 0;
|
||||
}
|
||||
u64 budget = total_physical / 6;
|
||||
budget = (std::min)(budget, (max_map_count - ReservedMaps) * PageAlignment);
|
||||
const u64 available = Common::GetAvailablePhysicalMemory();
|
||||
if (available != 0) {
|
||||
constexpr u64 Headroom = 2ULL << 30;
|
||||
@@ -695,8 +703,8 @@ public:
|
||||
if (budget < MinimumBudget) {
|
||||
LOG_INFO(HW_Memory,
|
||||
"Skipping hardware buffer backing, only {} MiB could be committed on a {} MiB "
|
||||
"system with {} MiB available",
|
||||
budget >> 20, total_physical >> 20, available >> 20);
|
||||
"system with {} MiB available and vm.max_map_count {}",
|
||||
budget >> 20, total_physical >> 20, available >> 20, max_map_count);
|
||||
return 0;
|
||||
}
|
||||
return static_cast<size_t>(budget);
|
||||
|
||||
@@ -107,4 +107,21 @@ u64 GetAvailablePhysicalMemory() {
|
||||
#endif
|
||||
}
|
||||
|
||||
u64 GetMaxMapCount() {
|
||||
#ifdef __linux__
|
||||
if (std::FILE* const file = std::fopen("/proc/sys/vm/max_map_count", "re")) {
|
||||
char line[32];
|
||||
u64 count = 0;
|
||||
if (std::fgets(line, sizeof(line), file) != nullptr) {
|
||||
count = std::strtoull(line, nullptr, 10);
|
||||
}
|
||||
std::fclose(file);
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
||||
@@ -20,4 +20,6 @@ struct MemoryInfo {
|
||||
|
||||
[[nodiscard]] u64 GetAvailablePhysicalMemory();
|
||||
|
||||
[[nodiscard]] u64 GetMaxMapCount();
|
||||
|
||||
} // namespace Common
|
||||
|
||||
Reference in New Issue
Block a user