Skip to content

Commit 5551e7c

Browse files
committed
fix page reclaims
1 parent b2de01e commit 5551e7c

16 files changed

Lines changed: 6 additions & 198 deletions

File tree

perf.data

-11.9 KB
Binary file not shown.

src/free.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ void _free(void *ptr) {
2121
alloc->parent->alloc = alloc->next;
2222

2323
// in case it's the only alloc in a t_mmap, free the mmap
24-
if (!alloc->next && !alloc->prev && alloc->parent->type == LARGE) {
24+
// and only if there is still a t_mmap in g_mmap
25+
if (!alloc->next && !alloc->prev &&
26+
(g_mmap->next || alloc->parent->type == LARGE)) {
2527
t_mmap *map = alloc->parent;
2628
if (map->prev)
2729
map->prev->next = map->next;
2830
if (map->next)
2931
map->next->prev = map->prev;
30-
// FIX: this cause page reclaims to skyrocket
32+
// WARN: this cause minor page faults (page reclaims) to skyrocket
3133
if (map == g_mmap)
3234
g_mmap = map->next;
3335
munmap(map, map->size + sizeof(t_mmap));
3436
}
3537
}
3638

3739
void free(void *ptr) {
38-
(void)ptr;
39-
/* return; */
4040
if (LOGGING) {
4141
ft_dprintf(tmpfd(), "free(%p)\n", ptr);
4242
/* flog("free(): ", (size_t)ptr); */

test.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,11 @@ int main() {
2828
assert(strcmp(dynstr, "Test1234") == 0);
2929
free(dynstr);
3030

31-
// 2. Memory integrity tests
32-
int *numbers = (int *)malloc(10 * sizeof(int));
33-
assert(numbers != NULL);
34-
for (int i = 0; i < 10; i++) {
35-
numbers[i] = i;
36-
}
37-
for (int i = 0; i < 10; i++) {
38-
assert(numbers[i] == i);
39-
}
40-
free(numbers);
41-
42-
char *buf1 = (char *)malloc(100);
43-
char *buf2 = (char *)malloc(100);
44-
for (int i = 0; i < 100; i++) {
45-
buf1[i] = 1;
46-
buf2[i] = 2;
47-
}
48-
for (int i = 0; i < 100; i++) {
49-
assert(buf1[i] == 1);
50-
assert(buf2[i] == 2);
51-
}
52-
free(buf1);
53-
free(buf2);
54-
55-
// 3. Edge cases
5631
void *edge1 = malloc(0);
57-
free(edge1); // This should not crash
32+
free(edge1);
5833

5934
char *edge2 = (char *)malloc(5);
60-
edge2 = realloc(edge2, 0); // This should behave as free
35+
edge2 = realloc(edge2, 0);
6136
assert(edge2 == NULL);
6237

6338
ft_printf("All tests passed!\n");

test0

-15.4 KB
Binary file not shown.

test0.c

Lines changed: 0 additions & 14 deletions
This file was deleted.

test1

-15.7 KB
Binary file not shown.

test1.c

Lines changed: 0 additions & 28 deletions
This file was deleted.

test2

-15.7 KB
Binary file not shown.

test2.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

test2ft

-80.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)