st/nine: Control the memfd virtual limit

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9377>
This commit is contained in:
Axel Davy 2021-02-06 22:24:25 +01:00 committed by Marge Bot
parent a179ea2e6d
commit 24eb1f21d0
3 changed files with 13 additions and 7 deletions

View file

@ -236,7 +236,7 @@ NineDevice9_ctor( struct NineDevice9 *This,
/* Create first, it messes up our state. */
This->hud = hud_create(This->context.cso, NULL, NULL); /* NULL result is fine */
This->allocator = nine_allocator_create(This);
This->allocator = nine_allocator_create(This, 512);
/* Available memory counter. Updated only for allocations with this device
* instance. This is the Win 7 behavior.

View file

@ -774,7 +774,8 @@ nine_allocate(struct nine_allocator *allocator, unsigned size)
/* Restrict to >= page_size to prevent having too much fragmentation, as the size of
* allocations is rounded to the next page_size multiple. */
if (size >= allocator->page_size && nine_memfd_allocator(allocator, new_allocation, size)) {
if (size >= allocator->page_size && allocator->total_virtual_memory_limit >= 0 &&
nine_memfd_allocator(allocator, new_allocation, size)) {
struct nine_memfd_file_region *region = new_allocation->memory.memfd.region;
if (!region->zero_filled) {
void *data = nine_get_pointer(allocator, new_allocation);
@ -1005,7 +1006,7 @@ nine_wrap_external_pointer(struct nine_allocator* allocator, void* data)
}
struct nine_allocator *
nine_allocator_create(struct NineDevice9 *device)
nine_allocator_create(struct NineDevice9 *device, int memfd_virtualsizelimit)
{
struct nine_allocator* allocator = MALLOC(sizeof(struct nine_allocator));
@ -1015,12 +1016,12 @@ nine_allocator_create(struct NineDevice9 *device)
allocator->device = device;
allocator->page_size = sysconf(_SC_PAGESIZE);
assert(allocator->page_size == 4 << 10);
allocator->num_fd_max = MIN2(128, ulimit(__UL_GETOPENMAX));
allocator->num_fd_max = (memfd_virtualsizelimit >= 0) ? MIN2(128, ulimit(__UL_GETOPENMAX)) : 0;
allocator->min_file_size = DIVUP(100 * (1 << 20), allocator->page_size) * allocator->page_size; /* 100MB files */
allocator->total_allocations = 0;
allocator->total_locked_memory = 0;
allocator->total_virtual_memory = 0;
allocator->total_virtual_memory_limit = 512 << 20;
allocator->total_virtual_memory_limit = memfd_virtualsizelimit * (1 << 20);
allocator->num_fd = 0;
DBG("Allocator created (ps: %d; fm: %d)\n", allocator->page_size, allocator->num_fd_max);
@ -1157,10 +1158,11 @@ nine_wrap_external_pointer(struct nine_allocator* allocator, void* data)
}
struct nine_allocator *
nine_allocator_create(struct NineDevice9 *device)
nine_allocator_create(struct NineDevice9 *device, int memfd_virtualsizelimit)
{
struct nine_allocator* allocator = MALLOC(sizeof(struct nine_allocator));
(void)device;
(void)memfd_virtualsizelimit;
if (!allocator)
return NULL;

View file

@ -62,8 +62,12 @@ nine_suballocate(struct nine_allocator* allocator, struct nine_allocation *alloc
struct nine_allocation *
nine_wrap_external_pointer(struct nine_allocator* allocator, void* data);
/* memfd_virtualsizelimit: Limit for the virtual memory usage (in MB)
* above which memfd files are unmapped (to reduce virtual memory usage).
* If negative, disables memfd usage. */
struct nine_allocator *
nine_allocator_create(struct NineDevice9 *device);
nine_allocator_create(struct NineDevice9 *device, int memfd_virtualsizelimit);
void
nine_allocator_destroy(struct nine_allocator *allocator);