-
-
Notifications
You must be signed in to change notification settings - Fork 606
Closed
Description
OSv uses malloc_large for huge memory request, and it stores alloced size (page alloced) in header (page_range).
Lines 844 to 850 in 69ea100
| if (ret_header) { | |
| on_alloc(size); | |
| void* obj = ret_header; | |
| obj += offset; | |
| trace_memory_malloc_large(obj, requested_size, size, alignment); | |
| return obj; | |
| } |
However, in large_object_size it only returns size in header.
Lines 1070 to 1075 in 69ea100
| static unsigned large_object_size(void *obj) | |
| { | |
| obj = align_down(obj - 1, page_size); | |
| auto header = static_cast<page_range*>(obj); | |
| return header->size; | |
| } |
I think malloc_usable_size should subtract offset or header size.
Example code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
void* ptr = malloc(0x4010);
int size = malloc_usable_size(ptr);
printf("ptr: %p size: %lx\n", ptr, size);
return 0;
}
Output:
Cmdline: /hello
ptr: 0xffff800001b64040 size: 5000
I think the size should be 0x4FC0.
Metadata
Metadata
Assignees
Labels
No labels