<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Mar 18, 2017 at 2:24 AM, Gustaw Smolarczyk <span dir="ltr"><<a href="mailto:wielkiegie@gmail.com" target="_blank">wielkiegie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div class="h5"><div><div class="gmail_extra"><div class="gmail_quote">18 mar 2017 05:24 "Jason Ekstrand" <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> napisał(a):<br type="attribution"><blockquote class="m_3503187747582817732quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Instead of just advertising the aperture size, we do something more<br>
intelligent. On systems with a full 48-bit PPGTT, we can address 100%<br>
of the available system RAM from the GPU. In order to keep clients from<br>
burning 100% of your available RAM for graphics resources, we have a<br>
nice little heuristic (which has received exactly zero tuning) to keep<br>
things under a reasonable level of control.<br>
<br>
Cc: Alex Smith <<a href="mailto:asmith@feralinteractive.com" target="_blank">asmith@feralinteractive.com</a>><br>
---<br>
src/intel/vulkan/anv_device.<wbr>c | 61 ++++++++++++++++++++++++++++++<wbr>+++---------<br>
src/intel/vulkan/anv_gem.c | 16 +++++++++++<br>
src/intel/vulkan/anv_private.<wbr>h | 13 ++++++++-<br>
3 files changed, 76 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index 8994e70..fd71a23 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -25,6 +25,7 @@<br>
#include <stdbool.h><br>
#include <string.h><br>
#include <sys/mman.h><br>
+#include <sys/sysinfo.h><br>
#include <unistd.h><br>
#include <fcntl.h><br>
#include <xf86drm.h><br>
@@ -53,6 +54,48 @@ compiler_perf_log(void *data, const char *fmt, ...)<br>
va_end(args);<br>
}<br>
<br>
+static VkResult<br>
+anv_compute_heap_size(int fd, uint64_t *heap_size)<br>
+{<br>
+ uint64_t gtt_size;<br>
+ if (anv_gem_get_context_param(fd, 0, I915_CONTEXT_PARAM_GTT_SIZE,<br>
+ >t_size) == -1) {<br>
+ /* If, for whatever reason, we can't actually get the GTT size from the<br>
+ * kernel (too old?) fall back to the aperture size.<br>
+ */<br>
+ anv_perf_warn("Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");<br>
+<br>
+ if (anv_gem_get_aperture(fd, >t_size) == -1) {<br>
+ return vk_errorf(VK_ERROR_INITIALIZAT<wbr>ION_FAILED,<br>
+ "failed to get aperture size: %m");<br>
+ }<br>
+ }<br>
+<br>
+ /* Query the total ram from the system */<br>
+ struct sysinfo info;<br>
+ sysinfo(&info);<br>
+<br>
+ uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;<br>
+<br>
+ /* We don't want to burn too much ram with the GPU. If the user has 4GiB<br>
+ * or less, we use at most half. If they have more than 4GiB, we use 3/4.<br>
+ */<br>
+ uint64_t available_ram;<br>
+ if (total_ram < 4ull * 1024ull * 1024ull * 1024ull)<br>
+ available_ram = total_ram / 2;<br>
+ else<br>
+ available_ram = total_ram * 3 / 4;<br></blockquote></div></div></div><div dir="auto"><br></div></div></div><div dir="auto">This will result in 3/4 in case of exactly 4GB of RAM present. Did you mean to use <= instead of <?</div></div></blockquote><div><br></div><div>You're right, I did. Thanks for catching that! Fixed loclly.<br><br></div><div>That said, my laptop actually reports slightly less than 8 GiB of ram so I'd expect a 4 GiB system to report slightly less and it would still work. Never hurts to be correct though. <br></div></div><br></div></div>