Welcome to Part 3 of the Confidential Computing Chronicles.
In Part 2, we fought the SDK and won. We have a running Enclave. But if you’re trying to move beyond "Hello World" to something real—like running an image processing algorithm or a small database—you’re about to hit a literal, hardware-encoded brick wall.
It’s called the Memory Wall, and it exists because Intel is paranoid (for good reason).
The 128MB Problem (The EPC)
In a traditional app, you treat RAM like a vast, flat ocean. You malloc a gigabyte? The OS says "Sure, whatever."
In SGX, the CPU reserved a special, isolated region of RAM for Enclaves. This is the Enclave Page Cache (EPC). On older machines (pre-Ice Lake), this pool was strictly capped at 128MB.
But wait, it gets worse! After some administrative overhead, you only have about 90MB of usable space for your code, stack, and heap.
"90MB? My Node.js app consumes that just waking up!" Precisely. This is why SGX is for Confidential Computing, not for Lazy Computing.
The Performance Cliff: What happens when you leak?
If you exceed that 128MB limit, the hardware doesn't just crash. It starts Paging.
The CPU moves encrypted pages of your Enclave out to normal RAM. When you need them again, it pulls them back, decrypts them, verifies the integrity hash, and swaps them in.
This "Swapping" in SGX is roughly 10x to 100x slower than standard OS paging because of the constant encryption/decryption overhead. If your app frequently crosses that 128MB threshold, you will see a performance cliff that looks like a vertical drop into hell.
Pro-Tips for Tuning your Enclave
So, how do we survive inside a 90MB box? Here are the battle-hardened rules I follow:
1. Reuse, Don't Reallocate
Inside an Enclave, malloc and free are not just expensive—they are dangerous for memory fragmentation. If you have a 1MB buffer for processing data, allocate it once at startup and reuse it forever.
2. Stream, Don't Load
Don't read a 500MB database file into the Enclave memory. Keep it outside (Untrusted RAM), and pull it in chunks of 64KB, process it, and send the result back out via OCALL. Keep the Enclave as a "Processing Factory," not a "Storage Warehouse."
3. Check your Enclave Configuration
Every Enclave has a configuration file (Enclave.config.xml). If you don't adjust this, you're using default values that might be crippling you.
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<HeapMaxSize>0x4000000</HeapMaxSize> <StackMaxSize>0x40000</StackMaxSize> <ReservedMemSize>0x1000000</ReservedMemSize> </EnclaveConfiguration>
Max's Golden Rule: Set your Heap to just under your machine's EPC hardware limit to avoid the paging trap.
Testing for the Cliff
If you want to feel the pain, try this exercise:
Write a loop that allocates 1MB blocks inside the Enclave and times each allocation. Watch the time stay steady until you reach ~90MB, and then watch the latency skyrocket.
Why this makes you a better engineer
Learning to code for SGX is like learning to code for a 1980s game console with 64KB of RAM. It forces you to think about data locality, buffer management, and overhead.
In a world where developers throw RAM at problems like it's free, being the person who can fit a secure machine learning model into 90MB makes you a unicorn in the security industry.
What's Next?
We've mastered memory. Now we need to prove to the world that our Enclave is actually running on real hardware and hasn't been tampered with.
Next up is the most mysterious and crucial part of SGX: Remote Attestation. This is how you prove your identity over the internet without trusting the guy holding the other end of the wire.
Part 4: Remote Attestation - The Digital Handshake of Trust
Leave a Comment 👇
What's the smallest memory footprint you've ever managed to squeeze your code into?
Are you getting SGX_ERROR_OUT_OF_MEMORY? Post your stack size configuration below and let's find that memory leak together!


Top comments (1)
I calculated that the time lost due to SGX paging overhead is roughly equal to the time I need to brew a fresh coffee. ☕
So technically... Intel is just trying to keep us caffeinated and happy, right? Right...?