summaryrefslogtreecommitdiff
path: root/sysdep/unix/alloc.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@jmq.cz>2021-11-23 11:13:11 +0000
committerMaria Matejka <mq@jmq.cz>2021-11-23 11:13:11 +0000
commit821344c781a99a4f559949a7497617b64c061c82 (patch)
tree878df97d83216fb9f85f25b7e1d0ffdb8198e1ea /sysdep/unix/alloc.c
parent4ba991f19c2f8aa893a723f29775c50e1370ed07 (diff)
Stored pages release routine
Diffstat (limited to 'sysdep/unix/alloc.c')
-rw-r--r--sysdep/unix/alloc.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c
index 4ae1a9db..61360e73 100644
--- a/sysdep/unix/alloc.c
+++ b/sysdep/unix/alloc.c
@@ -135,3 +135,32 @@ free_sys_page(void *ptr)
#endif
free(ptr);
}
+
+void
+check_stored_pages(void)
+{
+#ifdef ENOMEM
+ if (atomic_load_explicit(&global_page_list_not_empty, memory_order_relaxed) == 0)
+ return;
+
+ for (uint limit = 0; limit < 256; limit++)
+ {
+ GLOBAL_PAGE_SPIN_LOCK;
+ void *ptr = HEAD(global_page_list);
+ if (!NODE_VALID(ptr))
+ {
+ atomic_store_explicit(&global_page_list_not_empty, 0, memory_order_relaxed);
+ GLOBAL_PAGE_SPIN_UNLOCK;
+ return;
+ }
+
+ rem_node(ptr);
+ if (munmap(ptr, page_size) < 0)
+ if (errno == ENOMEM)
+ add_tail(&global_page_list, ptr);
+ else
+ bug("munmap(%p) failed: %m", ptr);
+ GLOBAL_PAGE_SPIN_UNLOCK;
+ }
+#endif
+}