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

Support large initial memory allocation #305

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Conversation

zherczeg
Copy link
Collaborator

No description provided.

@zherczeg
Copy link
Collaborator Author

I don't understand the windows error. It installs tmate, then a lot of warnings, then
Error: The action 'Run mxschmitt/action-tmate@v3' has timed out after 15 minutes.

Does something changed in the build system?

@zherczeg
Copy link
Collaborator Author

Oh, it showed the wrong error. So win32 cannot allocate 2GB memory. Maybe I need to lower it.

@@ -43,7 +43,7 @@ Memory::Memory(uint64_t initialSizeInByte, uint64_t maximumSizeInByte, bool isSh
, m_targetBuffers(nullptr)
, m_isShared(isShared)
{
ASSERT(initialSizeInByte <= std::numeric_limits<size_t>::max());
RELEASE_ASSERT(initialSizeInByte <= std::numeric_limits<size_t>::max());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have changed this because of 32 bit systems.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you change this?
ASSERT enabled only in debug mode is not enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The mmap (and calloc) uses size_t length, and that is 32 bit on 32 bit systems. When max size is 4GByte or more (uint64_t value), it allocates an incorrect amount of memory.

Btw, would it be better to throw error on alloc fails?

Copy link
Collaborator

@clover2123 clover2123 Nov 19, 2024

Choose a reason for hiding this comment

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

It would be better to inform the unvalid size before actually allocated.
BTW is memory limit differently defined for 32bit and 64bit each?
(I cannot find this in spec)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is not defined differently, that is the problem. You can allocate more than 4GByte memory for WebAssembly, and 32 bit system can access maximum of 4GByte only. So I think anything requires more than 4GByte maximum memory should fail with allocation failure. This should affect memory.grow as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see,
then what about using 64bit length instead of size_t to unify both architectures?
We may need to allocate much more memory for complex wasm apps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh this is because of mmap and calloc, I see.
For now there is no other choice..
let's think about it more

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

WebAssembly has 32 bit pointers and 32 bit offsets by default, so they can only access 8GByte memory. However, with 64 bit offsets (an extension), it can asses more memory.

@@ -43,7 +43,7 @@ Memory::Memory(uint64_t initialSizeInByte, uint64_t maximumSizeInByte, bool isSh
, m_targetBuffers(nullptr)
, m_isShared(isShared)
{
ASSERT(initialSizeInByte <= std::numeric_limits<size_t>::max());
RELEASE_ASSERT(initialSizeInByte <= std::numeric_limits<size_t>::max());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you change this?
ASSERT enabled only in debug mode is not enough?

@@ -58,7 +58,7 @@ Memory::Memory(uint64_t initialSizeInByte, uint64_t maximumSizeInByte, bool isSh
#else
WALRUS_64_MEMORY_INITIAL_MMAP_RESERVED_ADDRESS_SIZE;
#endif
m_reservedSizeInByte = std::min(initialReservedSize, m_maximumSizeInByte);
m_reservedSizeInByte = std::min(std::max(initialReservedSize, initialSizeInByte), m_maximumSizeInByte);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice catch!

@clover2123 clover2123 merged commit bce14b0 into Samsung:main Nov 19, 2024
15 checks passed
@zherczeg zherczeg deleted the large_mem branch November 19, 2024 09:14
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