Skip to content
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

Fix page sizes #1184

Merged
merged 7 commits into from
Mar 9, 2025
Merged

Fix page sizes #1184

merged 7 commits into from
Mar 9, 2025

Conversation

archbirdplus
Copy link
Contributor

@archbirdplus archbirdplus commented Mar 9, 2025

Cubyz once switched to its own pageSize, but since then the standard library was upgraded to better represent hardware and software variation. This PR allows for running on ARM Linux and MacOS.

mprotect needs its slices page-aligned. Since the VirtualList range
is contiguous, using a larger page size wouldn't necessarily reduce
memory anyways. And since pageSize() will only get called when
allocating, it is not particularly expensive.
@@ -474,10 +476,10 @@ fn releaseMemory(start: [*]align(pageSize) u8, len: usize) void {
/// A list that reserves a continuous region of virtual memory without actually committing its pages.
/// This allows it to grow without ever invalidating pointers.
pub fn VirtualList(T: type, maxSize: u32) type {
const maxSizeBytes = std.mem.alignForward(usize, @as(usize, maxSize)*@sizeOf(T), pageSize);
std.debug.assert(@sizeOf(T) <= pageSize);
const maxSizeBytes = std.mem.alignForward(usize, @as(usize, maxSize)*@sizeOf(T), pageSize());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this even work? Aren't you calling pageSize in a comptime context here (because the function returns a type)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol. I knew this would come up but I wasn't allowed to put a comptime check into pageSize(). I'll just make maxSizeBytes runtime determined then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, but what does it return if you call it at compile time???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It errors with

compiler/zig/lib/std/atomic.zig:16:20: error: unable to evaluate comptime expression
    return @atomicLoad(T, &self.raw, order);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't you see that while testing then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this is basically the only additional bug that can happen from aarch64-linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I did mess it up so I'll add it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that Zig tries to cross-compile when the target is specified, which of course we can't do without preparing libGL and libX11, and that is very out of scope for this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely not in this PR.
We could compile for aarch64-windows then? That should fail in the same cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an issue for it: #1185

@IntegratedQuantum IntegratedQuantum merged commit 449e9df into PixelGuys:master Mar 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants