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

mem: Improve memory issue when page size is not 4KiB #2843

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KhoraLee
Copy link
Contributor

@KhoraLee KhoraLee commented Aug 7, 2023

On devices that have larger page size than 4KiB(such as aarch64 macOS), sometimes page is overlapped when allocating at specific page(alloc_at) and caused memory issue because overlapped page's memory is zero-fiiled. So if region contains already allocated page then it will only allocate remain parts and update allocation table's info to largest one.

If there is better way then I'll close this PR.

@Macdu
Copy link
Contributor

Macdu commented Aug 9, 2023

I think it would be better to make the whole allocator use blocks which are the host page size instead of trying to use workaround like that.

@KhoraLee
Copy link
Contributor Author

I think it would be better to make the whole allocator use blocks which are the host page size instead of trying to use workaround like that.

I don't understand what you mean. Would you describe it a bit more?

@KhoraLee KhoraLee mentioned this pull request Aug 10, 2023
7 tasks
@Macdu
Copy link
Contributor

Macdu commented Aug 12, 2023

I think it would be better to make the whole allocator use blocks which are the host page size instead of trying to use workaround like that.

I don't understand what you mean. Would you describe it a bit more?

Ah, I kind of see, so the issue is that some games are trying to allocate two contiguous memory segment with the second one not being 8KB-aligned, right?

@KhoraLee
Copy link
Contributor Author

KhoraLee commented Aug 13, 2023

Ah, I kind of see, so the issue is that some games are trying to allocate two contiguous memory segment with the second one not being 8KB-aligned, right?

For example, on Uncharted

[16:32:25.181] |D| [load_self]: Loading SELF at app0:eboot.bin... (ELF type: 0xfe00, self_filesize: 0x325b, self_offset: 0x4, module_info_offset: 0x4a4)
[16:32:25.181] |D| [load_self]:     [LOAD] (p_type: 0x1): p_offset: 0x1000, p_vaddr: 0x81000000, p_paddr: 0x0, p_filesz: 0x838, p_memsz: 0x838, p_flags: 0x5, p_align: 0x1000
[16:32:25.181] |D| [load_self]:     [LOAD] (p_type: 0x1): p_offset: 0x2000, p_vaddr: 0x81001000, p_paddr: 0x0, p_filesz: 0xbc, p_memsz: 0xc0, p_flags: 0x6, p_align: 0x1000
[16:32:25.181] |C| [alloc_inner]: Failed to allocate at specific page
4KiB Page
┌──────────────────────┬──────────────────────┐
│    Seg0    │ Padding │    Seg1    │ Padding │
└──────────────────────┴──────────────────────┘
├──── Page 528,384 ────┼──── Page 528,385 ────┤

16KiB Page
┌───────────────────────────────────────────────...──┐
│    Seg0    │ Padding │    Seg1    │ Padding │ ...
└───────────────────────────────────────────────...──┘
├────────────────── Page #132,096 ──────────────...──┤

On 4KiB page size, seg0 and seg1 are allocated in different page.
On 16KiB, Seg0 and Seg1 is in same page and it is calling alloc_inner with forcing same page, Page 132,096(containing Seg0 region) is zero-filled when allocating Seg1 and caused memory issue.

@Macdu
Copy link
Contributor

Macdu commented Aug 16, 2023

Yes, I see. This issue is kind of annoying to tackle. Your approach looks kind of fine but there are some issues:

  • we can alloc_at at the same position multiple time (fine for the time being because alloc_at is only use for elf non-relocatable segments)
  • this only works when alloc_at-ing from left to right
  • free does not work with your approach (fine for the time being because we never free elf segments)

@KhoraLee
Copy link
Contributor Author

@Macdu How about current(93e9e5b) implementation?

@Macdu
Copy link
Contributor

Macdu commented Sep 16, 2023

Given that your fix only affects aarch64 mac, which for the time being does not work because of the underlying problem, I am fine with it.

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.

None yet

2 participants