CLARIFICATION: WASM page size implemented on the IC

This question is primarily directed towards @roman-kashitsyn

I’ve recently been going through the more technical blog posts on the Dfinity Medium channel. In there, I read 2 articles by @roman-kashitsyn around memory management on the IC and in both places he mentions that memory page sizes on the IC are 4KiB in size. I’m referring to these:

However, other authoritative sources say that WASM pages are 64KiB in size.
https://www.google.com/search?q=wasm+page+size&oq=wasm+page+size&aqs=chrome.0.69i59j0i22i30j0i390l5j69i61.1809j0j7&sourceid=chrome&ie=UTF-8

I wanted to clarify what the sizes are and if there’s a hole in my understanding. This is required because I am borrowing serialization/deserialization logic from OpenChat’s implementation here and this is a constant that needs to be specified while using the lower level API defined here in the ic_cdk.

Thank you for clarifying. :slight_smile:

1 Like

Hi @saikatdas0790,
The short answer is that Wasm pages are 64 KiB and the constant used in the OpenChat source is correct.

The blog posts from @roman-kashitsyn and @ulan are talking about how the memory is stored in the replica, but the page size used there is an internal detail which isn’t directly exposed to canisters. In the stable API docs it’s specified that stable64_size and stable_size refer to the number of Wasm pages which are 64 KiB each.

5 Likes

If you’re curious about why these page sizes are different: We use 4 KiB internally because that’s the default size on Linux so the OS can efficiently handle pages at that level. Wasm, on the other hand, is meant to be portable and not all CPUs/OSes support 4 KiB pages so they wanted to pick a page size that would be large enough to be supported on all major systems (source).

5 Likes