mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-07 22:21:40 +00:00
kvm tools: Make host_ram_size() more robust
This patch fixes cryptic "out of memory" errors on hosts where sysconf() fails by defaulting to MIN_RAM_SIZE_MB. Reported-by: <born2befrag@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
committed by
Will Deacon
parent
4352ffa41c
commit
d63c5ce6c5
@@ -267,8 +267,16 @@ static u64 host_ram_size(void)
|
||||
long nr_pages;
|
||||
|
||||
nr_pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (nr_pages < 0) {
|
||||
warning("sysconf(_SC_PHYS_PAGES) failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
page_size = sysconf(_SC_PAGE_SIZE);
|
||||
if (page_size < 0) {
|
||||
warning("sysconf(_SC_PAGE_SIZE) failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (nr_pages * page_size) >> MB_SHIFT;
|
||||
}
|
||||
@@ -287,6 +295,8 @@ static u64 get_ram_size(int nr_cpus)
|
||||
ram_size = 64 * (nr_cpus + 3);
|
||||
|
||||
available = host_ram_size() * RAM_SIZE_RATIO;
|
||||
if (!available)
|
||||
available = MIN_RAM_SIZE_MB;
|
||||
|
||||
if (ram_size > available)
|
||||
ram_size = available;
|
||||
|
||||
Reference in New Issue
Block a user