mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-12 09:17:53 +00:00
- Emulator can now test the αcτµαlly pδrταblε εxεcµταblε bootloader - Whipped up a webserver named redbean. It services 150k requests per second on a single core. Bundling assets inside zip enables extremely fast serving for two reasons. The first is that zip central directory lookups go faster than stat() system calls. The second is that both zip and gzip content-encoding use DEFLATE, therefore, compressed responses can be served via the sendfile() system call which does an in-kernel copy directly from the zip executable structure. Also note that red bean zip executables can be deployed easily to all platforms, since these native executables work on Linux, Mac, BSD, and Windows. - Address sanitizer now works very well
31 lines
1.2 KiB
C
31 lines
1.2 KiB
C
#include "libc/mem/mem.h"
|
|
#include "third_party/dlmalloc/dlmalloc.h"
|
|
|
|
/**
|
|
* If possible, gives memory back to the system (via negative arguments
|
|
* to sbrk) if there is unused memory at the `high' end of the malloc
|
|
* pool or in unused MMAP segments. You can call this after freeing
|
|
* large blocks of memory to potentially reduce the system-level memory
|
|
* requirements of a program. However, it cannot guarantee to reduce
|
|
* memory. Under some allocation patterns, some large free blocks of
|
|
* memory will be locked between two used chunks, so they cannot be
|
|
* given back to the system.
|
|
*
|
|
* The `pad' argument to malloc_trim represents the amount of free
|
|
* trailing space to leave untrimmed. If this argument is zero, only the
|
|
* minimum amount of memory to maintain internal data structures will be
|
|
* left. Non-zero arguments can be supplied to maintain enough trailing
|
|
* space to service future expected allocations without having to
|
|
* re-obtain memory from the system.
|
|
*
|
|
* @return 1 if it actually released any memory, else 0
|
|
*/
|
|
int malloc_trim(size_t pad) {
|
|
int result = 0;
|
|
ensure_initialization();
|
|
if (!PREACTION(g_dlmalloc)) {
|
|
result = dlmalloc_sys_trim(g_dlmalloc, pad);
|
|
POSTACTION(g_dlmalloc);
|
|
}
|
|
return result;
|
|
}
|