mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-08 12:18:42 +00:00
Stored pages release routine
This commit is contained in:
parent
4ba991f19c
commit
821344c781
@ -135,3 +135,32 @@ free_sys_page(void *ptr)
|
|||||||
#endif
|
#endif
|
||||||
free(ptr);
|
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
|
||||||
|
}
|
||||||
|
@ -2193,6 +2193,7 @@ static int short_loops = 0;
|
|||||||
#define WORK_EVENTS_MAX 10
|
#define WORK_EVENTS_MAX 10
|
||||||
|
|
||||||
void pipe_drain(int fd);
|
void pipe_drain(int fd);
|
||||||
|
void check_stored_pages(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
io_loop(void)
|
io_loop(void)
|
||||||
@ -2215,6 +2216,9 @@ io_loop(void)
|
|||||||
timers_fire(&main_birdloop.time, 1);
|
timers_fire(&main_birdloop.time, 1);
|
||||||
io_close_event();
|
io_close_event();
|
||||||
|
|
||||||
|
/* Try to release some memory if possible */
|
||||||
|
check_stored_pages();
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
poll_tout = (events ? 0 : 3000); /* Time in milliseconds */
|
poll_tout = (events ? 0 : 3000); /* Time in milliseconds */
|
||||||
if (t = timers_first(&main_birdloop.time))
|
if (t = timers_first(&main_birdloop.time))
|
||||||
|
Loading…
Reference in New Issue
Block a user