Skip to content

Commit 0ca2701

Browse files
committed
protomatter: allocator: Never supervisor-alloc while gc available
This may have been contributing to fragmentation of the supervisor heap
1 parent 23bced2 commit 0ca2701

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

shared-module/_protomatter/allocator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
#define MICROPY_INCLUDED_SHARED_MODULE_PROTOMATTER_ALLOCATOR_H
33

44
#include <stdbool.h>
5+
#include "py/gc.h"
56
#include "py/misc.h"
67
#include "supervisor/memory.h"
78

89
#define _PM_ALLOCATOR _PM_allocator_impl
910
#define _PM_FREE(x) (_PM_free_impl((x)), (x)=NULL, (void)0)
1011

1112
static inline void *_PM_allocator_impl(size_t sz) {
12-
supervisor_allocation *allocation = allocate_memory(align32_size(sz), true);
13-
if (allocation) {
14-
return allocation->ptr;
15-
} else {
13+
if (gc_alloc_possible()) {
1614
return m_malloc(sz + sizeof(void*), true);
15+
} else {
16+
supervisor_allocation *allocation = allocate_memory(align32_size(sz), true);
17+
return allocation ? allocation->ptr : NULL;
1718
}
1819
}
1920

0 commit comments

Comments
 (0)