diff mbox series

[kvmtool,v1,1/2] Factor out getting the host page size

Message ID 20230717102300.3092062-2-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, 10:22 a.m. UTC
Factor out getting the page size of the host into a separate
function. This will be used in the subsequent patch.

No functional change intended.

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

Patch

diff --git a/builtin-run.c b/builtin-run.c
index b1a27fd..2801735 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -360,9 +360,21 @@  static void kernel_usage_with_options(void)
 		KVM_BINARY_NAME);
 }
 
+static long host_page_size(void)
+{
+	long page_size = sysconf(_SC_PAGE_SIZE);
+
+	if (page_size < 0) {
+		pr_warning("sysconf(_SC_PAGE_SIZE) failed");
+		return 0;
+	}
+
+	return page_size;
+}
+
 static u64 host_ram_size(void)
 {
-	long page_size;
+	long page_size = host_page_size();
 	long nr_pages;
 
 	nr_pages	= sysconf(_SC_PHYS_PAGES);
@@ -371,12 +383,6 @@  static u64 host_ram_size(void)
 		return 0;
 	}
 
-	page_size	= sysconf(_SC_PAGE_SIZE);
-	if (page_size < 0) {
-		pr_warning("sysconf(_SC_PAGE_SIZE) failed");
-		return 0;
-	}
-
 	return (u64)nr_pages * page_size;
 }