Skip to contentSkip to conversation

virtio-mem: don't warn about THP sizes on a kernel without THP support

PATCH In review David Hildenbrand 3 participants 4 messages Sep 10, 2024 – Sep 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-mem: don't warn about THP sizes on a kernel without THP support

If the config directory in sysfs does not exist at all, we are dealing with a system that does not support THPs. Simply use 1 MiB block size then, instead of warning "Could not detect THP size, falling back to ..." and falling back to the default THP size.

Cc "Michael S. Tsirkin" <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Juraj Marcin <[email protected]>
---
 hw/virtio/virtio-mem.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/virtio/virtio-mem.c +7 -0
index ef64bf1b4a..4075f3d4ce 100644
@@ -88,6 +88,7 @@ static uint32_t virtio_mem_default_thp_size(void)
 static uint32_t thp_size;
 
 #define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"
+#define HPAGE_PATH "/sys/kernel/mm/transparent_hugepage/"
 static uint32_t virtio_mem_thp_size(void)
 {
     gchar *content = NULL;
@@ -98,6 +99,12 @@ static uint32_t virtio_mem_thp_size(void)
         return thp_size;
     }
 
+    /* No THP -> no restrictions. */
+    if (!g_file_test(HPAGE_PATH, G_FILE_TEST_EXISTS)) {
+        thp_size = VIRTIO_MEM_MIN_BLOCK_SIZE;
+        return thp_size;
+    }
+
     /*
      * Try to probe the actual THP size, fallback to (sane but eventually
      * incorrect) default sizes.
Signature · 1 line
2.46.0
#1 lore raw
Quoted 9 lines · David Hildenbrand

If the config directory in sysfs does not exist at all, we are dealing with a system that does not support THPs. Simply use 1 MiB block size then, instead of warning "Could not detect THP size, falling back to ..." and falling back to the default THP size.

Cc "Michael S. Tsirkin" <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Juraj Marcin <[email protected]>

Okay, I picked it up. But I have a question

hw/virtio/virtio-mem.c static uint32_t virtio_mem_default_thp_size(void) · line 91

Quoted 13 lines
---
 hw/virtio/virtio-mem.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/virtio/virtio-mem.c +1 -0
index ef64bf1b4a..4075f3d4ce 100644
@@ -88,6 +88,7 @@ static uint32_t virtio_mem_default_thp_size(void)
 static uint32_t thp_size;
 
 #define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"
+#define HPAGE_PATH "/sys/kernel/mm/transparent_hugepage/"

If this code runs e.g. on windows, it will poke at cwd root with unpredictable results.
It doesn't look like this is linux specific, did I miss anything?

Quoted 18 lines
hw/virtio/virtio-mem.c +6 -0
 static uint32_t virtio_mem_thp_size(void)
 {
     gchar *content = NULL;
@@ -98,6 +99,12 @@ static uint32_t virtio_mem_thp_size(void)
         return thp_size;
     }
 
+    /* No THP -> no restrictions. */
+    if (!g_file_test(HPAGE_PATH, G_FILE_TEST_EXISTS)) {
+        thp_size = VIRTIO_MEM_MIN_BLOCK_SIZE;
+        return thp_size;
+    }
+
     /*
      * Try to probe the actual THP size, fallback to (sane but eventually
      * incorrect) default sizes.
Signature · 1 line
2.46.0
#2 lore raw
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · David Hildenbrand

If the config directory in sysfs does not exist at all, we are dealing with a system that does not support THPs. Simply use 1 MiB block size then, instead of warning "Could not detect THP size, falling back to ..." and falling back to the default THP size.

Quoted 6 lines
Quoted 4 lines
Cc "Michael S. Tsirkin" <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Juraj Marcin <[email protected]>

Okay, I picked it up. But I have a question

Thanks, I can also route it via my memory device tree, whatever you prefer.

Quoted 12 lines
Quoted 12 lines
---
  hw/virtio/virtio-mem.c | 7 +++++++
  1 file changed, 7 insertions(+)
hw/virtio/virtio-mem.c +0 -0
index ef64bf1b4a..4075f3d4ce 100644
@@ -88,6 +88,7 @@ static uint32_t virtio_mem_default_thp_size(void)
  static uint32_t thp_size;
 
Quoted 7 lines

hw/virtio/virtio-mem.c static uint32_t virtio_mem_default_thp_size(void) · line 91

Quoted 2 lines
hw/virtio/virtio-mem.c +1 -0
  #define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"
+#define HPAGE_PATH "/sys/kernel/mm/transparent_hugepage/"

If this code runs e.g. on windows, it will poke at cwd root with unpredictable results.
It doesn't look like this is linux specific, did I miss anything?

VIRTIO_MEM has

"depends on LINUX"

so that code will never run on Windows.

Thanks!

Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v1 1/1
#3 lore raw
In reply to David Hildenbrand
Quoted 5 lines · David Hildenbrand

If the config directory in sysfs does not exist at all, we are dealing with a system that does not support THPs. Simply use 1 MiB block size then, instead of warning "Could not detect THP size, falling back to ..." and falling back to the default THP size.

Quoted 8 lines
Cc "Michael S. Tsirkin" <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Juraj Marcin <[email protected]>
---
  hw/virtio/virtio-mem.c | 7 +++++++
  1 file changed, 7 insertions(+)