Mesa (staging/20.1): anv: use os_get_available_system_memory()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Sep 2 13:58:49 UTC 2020


Module: Mesa
Branch: staging/20.1
Commit: 8a1a97db312f3c1b3d4f5a9ec8e7e0dbf4e28198
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8a1a97db312f3c1b3d4f5a9ec8e7e0dbf4e28198

Author: Jonathan Gray <jsg at jsg.id.au>
Date:   Fri Dec  6 01:07:56 2019 +1100

anv: use os_get_available_system_memory()

Replace local get_available_system_memory() function with
os_get_available_system_memory().

Fixes: b80930a6fea ("anv: add support for VK_EXT_memory_budget")
Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6517>
(cherry picked from commit 5b1ed09ff023ff98fed0c78a5ea609821cb92a8c)

---

 .pick_status.json             |  2 +-
 src/intel/vulkan/anv_device.c | 32 ++++++--------------------------
 2 files changed, 7 insertions(+), 27 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index a6818204607..d13bb4872a7 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -112,7 +112,7 @@
         "description": "anv: use os_get_available_system_memory()",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "b80930a6fea075d2ef283ceac5a2a64e65fd7bc4"
     },
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 5785c790b43..8965c168aa0 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -304,29 +304,6 @@ anv_physical_device_free_disk_cache(struct anv_physical_device *device)
 #endif
 }
 
-static uint64_t
-get_available_system_memory()
-{
-   char *meminfo = os_read_file("/proc/meminfo", NULL);
-   if (!meminfo)
-      return 0;
-
-   char *str = strstr(meminfo, "MemAvailable:");
-   if (!str) {
-      free(meminfo);
-      return 0;
-   }
-
-   uint64_t kb_mem_available;
-   if (sscanf(str, "MemAvailable: %" PRIx64, &kb_mem_available) == 1) {
-      free(meminfo);
-      return kb_mem_available << 10;
-   }
-
-   free(meminfo);
-   return 0;
-}
-
 static VkResult
 anv_physical_device_try_create(struct anv_instance *instance,
                                drmDevicePtr drm_device,
@@ -471,7 +448,8 @@ anv_physical_device_try_create(struct anv_instance *instance,
 
    device->has_implicit_ccs = device->info.has_aux_map;
 
-   device->has_mem_available = get_available_system_memory() != 0;
+   uint64_t avail_mem;
+   device->has_mem_available = os_get_available_system_memory(&avail_mem);
 
    device->always_flush_cache =
       driQueryOptionb(&instance->dri_options, "always_flush_cache");
@@ -2126,8 +2104,10 @@ anv_get_memory_budget(VkPhysicalDevice physicalDevice,
                       VkPhysicalDeviceMemoryBudgetPropertiesEXT *memoryBudget)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   uint64_t sys_available = get_available_system_memory();
-   assert(sys_available > 0);
+   uint64_t sys_available;
+   ASSERTED bool has_available_memory =
+      os_get_available_system_memory(&sys_available);
+   assert(has_available_memory);
 
    VkDeviceSize total_heaps_size = 0;
    for (size_t i = 0; i < device->memory.heap_count; i++)



More information about the mesa-commit mailing list