Skip to content

Commit aba28e3

Browse files
author
jason
committed
remove directory nesting; better logical order in page_aligned_alloc
1 parent 07d8a82 commit aba28e3

4 files changed

+12
-12
lines changed
File renamed without changes.

page_allocator/page_allocator_linux.odin renamed to page_allocator_linux.odin

+12-12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ _page_aligned_alloc :: proc(size, alignment, granularity: int,
5555
return nil, .Invalid_Argument
5656
}
5757

58+
alignment := alignment
59+
alignment = max(alignment, GRANULARITY_MIN)
60+
if granularity == GRANULARITY_MIN && alignment == GRANULARITY_MIN {
61+
size_full := mem.align_forward_int(size, GRANULARITY_MIN)
62+
memory, err = virtual.reserve_and_commit(uint(size_full))
63+
if err != nil {
64+
memory = memory[:size]
65+
}
66+
return
67+
}
68+
5869
if .Allow_Large_Pages in flags && granularity >= mem.Gigabyte && size >= mem.Gigabyte {
5970
raw_map_flags := i32(MAP_HUGE_1GB)
6071
map_flags := transmute(linux.Map_Flags)(raw_map_flags)
@@ -67,18 +78,7 @@ _page_aligned_alloc :: proc(size, alignment, granularity: int,
6778
}
6879
}
6980

70-
alignment := alignment
71-
alignment = max(alignment, GRANULARITY_MIN)
72-
if granularity == GRANULARITY_MIN && alignment == GRANULARITY_MIN {
73-
size_full := mem.align_forward_int(size, GRANULARITY_MIN)
74-
memory, err = virtual.reserve_and_commit(uint(size_full))
75-
if err != nil {
76-
memory = memory[:size]
77-
}
78-
return
79-
}
80-
81-
huge_if: if .Allow_Large_Pages in flags && granularity > 2 * mem.Megabyte && size > 2 * mem.Megabyte {
81+
if .Allow_Large_Pages in flags && granularity > 2 * mem.Megabyte && size > 2 * mem.Megabyte {
8282
raw_map_flags := i32(MAP_HUGE_2MB)
8383
map_flags := transmute(linux.Map_Flags)(raw_map_flags)
8484
map_flags += {.ANONYMOUS, .PRIVATE, .HUGETLB}
File renamed without changes.

0 commit comments

Comments
 (0)