-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[libpas] Refactor PGM to align with libpas allocation norms and split pas_get_random #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libpas] Refactor PGM to align with libpas allocation norms and split pas_get_random #597
Conversation
ea819b7
to
b19765c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, some comments :)
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove these three more empty lines.
@@ -63,7 +63,7 @@ void pas_baseline_allocator_table_initialize_if_necessary(void) | |||
|
|||
unsigned pas_baseline_allocator_table_get_random_index(void) | |||
{ | |||
return pas_get_random(pas_fast_random, PAS_MIN(PAS_NUM_BASELINE_ALLOCATORS, | |||
return pas_get_fast_random(PAS_MIN(PAS_NUM_BASELINE_ALLOCATORS, | |||
pas_baseline_allocator_table_bound)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation looks weird, so let's just remove this indent.
return pas_get_fast_random(PAS_MIN(PAS_NUM_BASELINE_ALLOCATORS, pas_baseline_allocator_table_bound));
|
||
// allocate memory | ||
pas_allocation_result result = pas_large_heap_try_allocate_and_forget(&heap->large_heap, mem_to_alloc, page_size, | ||
result = pas_large_heap_try_allocate_and_forget(large_heap, mem_to_alloc, page_size, | ||
heap_config, transaction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix, or remove this indentation.
@@ -315,4 +222,34 @@ size_t pas_probabilistic_guard_malloc_get_free_wasted_memory() { | |||
return free_wasted_mem; | |||
} | |||
|
|||
static PAS_ALWAYS_INLINE void pas_probabilistic_guard_malloc_debug_info(const void *key, const pgm_storage *value, const char *operation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put newline before {
of the function (WebKit's coding style).
Looks like functions in this file has this issue, so it is good timing to fix them :)
/* We want a fast way to determine if we can call PGM or not. | ||
* It would be really wasteful to recompute this answer each time we try to allocate, | ||
* so just update this variable each time we allocate or deallocate. */ | ||
extern PAS_API bool pgm_can_use; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is exposed as PAS_API, let's put prefix pas_
, so pas_can_use_pgm
.
void* pas_probabilistic_guard_malloc_allocate(size_t size, pas_heap* heap, pas_heap_config* heap_config, pas_physical_memory_transaction* transaction); | ||
// max amount of virtual memory that can be used by PGM (1GB) | ||
// including guard pages and wasted memory | ||
#define PGM_MAX_VIRTUAL_MEMORY (1024 * 1024 * 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put prefix PAS_
#define PGM_MAX_VIRTUAL_MEMORY (1024 * 1024 * 1024) | ||
|
||
// Probability that we should call PGM in percentage (0-100) | ||
#define PGM_PROBABILITY (1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put prefix PAS_
bool pas_probabilistic_guard_malloc_can_use(void); | ||
bool pas_probabilistic_guard_malloc_should_use(void); | ||
// max amount of free memory that can be wasted (1MB) | ||
#define PGM_MAX_WASTED_MEMORY (1024 * 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put prefix PAS_
@@ -75,7 +75,8 @@ PAS_BEGIN_EXTERN_C; | |||
.medium_bitfit_min_align_shift = PAS_MIN_MEDIUM_ALIGN_SHIFT, \ | |||
.use_marge_bitfit = true, \ | |||
.marge_bitfit_min_align_shift = PAS_MIN_MARGE_ALIGN_SHIFT, \ | |||
.marge_bitfit_page_size = PAS_MARGE_PAGE_DEFAULT_SIZE) | |||
.marge_bitfit_page_size = PAS_MARGE_PAGE_DEFAULT_SIZE, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one space after SIZE,
.
size_t allocation_size_requested; | ||
size_t size_of_data_pages; | ||
size_t mem_to_waste; | ||
size_t mem_to_alloc; | ||
uintptr_t start_of_data_pages; | ||
uintptr_t upper_guard_page; | ||
uintptr_t lower_guard_page; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only necessary thing in this storage will be allocation_size_requested
. The other values are only for debugging purpose or values that can be calculated from pointer
& allocation_size_requested
.
Because utility heap is precious resource in bmalloc (it is using limited compact heap), in the production version of PGM in libpas, we should not allocate it for each allocation. So, please keep in mind that we need to make this struct just the following in the release build.
struct pas_pgm_storage {
size_t allocation_size_requested;
};
And then, we do not need to have storage allocation via utility heap since pas_ptr_hash_map can store 64bit value as a value.
b19765c
to
19b4698
Compare
19b4698
to
6af9ccf
Compare
6af9ccf
to
e3532db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with nits.
|
||
void pas_probabilistic_guard_malloc_trigger(void) { | ||
// ??? | ||
// free memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is obvious, I think this comment is not necessary.
} | ||
|
||
return key; | ||
result.begin = (uintptr_t) key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space between (uintptr_t)
and key
.
|
||
PAS_BEGIN_EXTERN_C; | ||
|
||
/* Initial Function Definitions */ | ||
// structure for holding metadata of pgm allocations | ||
// TODO : Reduce size of structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename TODO
with FIXME
.
e8cb8c4
to
e220474
Compare
e220474
to
b821836
Compare
b821836
to
ff11be4
Compare
Committed r294866 (250997@main): https://commits.webkit.org/250997@main Reviewed commits have been landed. Closing PR #597 and removing active labels. |
ff11be4