diff mbox series

[kvmtool,v2,2/3] Factor out getting the number of physical memory host pages

Message ID 20230717121232.3559948-3-tabba@google.com (mailing list archive)
State New, archived
Headers show
Series Align value generated by get_ram_size() to the host's page size | expand

Commit Message

Fuad Tabba July 17, 2023, 12:12 p.m. UTC
Factor out getting the number of physical pages available for the
host into a separate function. This will be used in a subsequent
patch.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
---
 builtin-run.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/builtin-run.c b/builtin-run.c
index 2801735..44ea690 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -372,17 +372,23 @@  static long host_page_size(void)
 	return page_size;
 }
 
-static u64 host_ram_size(void)
+static long host_ram_nrpages(void)
 {
-	long page_size = host_page_size();
-	long nr_pages;
+	long nr_pages = sysconf(_SC_PHYS_PAGES);
 
-	nr_pages	= sysconf(_SC_PHYS_PAGES);
 	if (nr_pages < 0) {
 		pr_warning("sysconf(_SC_PHYS_PAGES) failed");
 		return 0;
 	}
 
+	return nr_pages;
+}
+
+static u64 host_ram_size(void)
+{
+	long page_size = host_page_size();
+	long nr_pages = host_ram_nrpages();
+
 	return (u64)nr_pages * page_size;
 }