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

Turn off EPC paging #94

Closed
az-hasan opened this issue May 30, 2019 · 6 comments
Closed

Turn off EPC paging #94

az-hasan opened this issue May 30, 2019 · 6 comments

Comments

@az-hasan
Copy link

Hello,

I am running a program assigning a buffer inside the enclave using malloc, at runtime. I then perform some read/write operations on the buffer. I can see performance slow down and then drop once the EPC limit is reached, with a large buffer. I understand that the EPC size is set to 128MB maximum.

  1. Is there a way to turn off EPC paging in SGX, to ensure the active pages are not swapped out?

  2. I was told there was no way to turn off the swap feature without changing the driver code. I am looking at sgx_page_cache.c, at a function called "sgx_swap_pages" - what must I change to turn off the swap feature?

  3. If I stick to sizes small enough that I know will not trigger paging, will I be able to load the enclave, if I turn off swap?

Thank you

@sergeay
Copy link
Contributor

sergeay commented Jun 2, 2019

The EPC area contains both your data (the buffer but also others such as stack, global variables your binary code...). When the size of your "working set" passes the 96MB limit (and not 128MB since 32MB are reserved), then the sub system (the driver) is starting to swap. This is not a "nice to have" feature but a necessary feature in order to have your running environment up and running. If swapping was disabled, either the allocation or your buffer access would fail and your program would crash / exit much before.

@az-hasan
Copy link
Author

az-hasan commented Jun 2, 2019

Got it. I did notice the drop between 90-100MB - the 32 MB reserved explains it.
So the pages of the EPC are managed by the Linux memory management subsystem, and if I want to ensure that for the entire run of the program, the EPC pages are not swapped out, I need to turn off the Linux swap feature (with the risk of program crashing + not being able to load an Enclave bigger than the EPC). I don't have to worry about any SGX settings.

Thank you for the clear explanation.

@az-hasan az-hasan closed this as completed Jun 2, 2019
@sergeay
Copy link
Contributor

sergeay commented Jun 2, 2019

This is almost true:

So the pages of the EPC are managed by the Linux memory management subsystem
Not exactly but managed by the SGX driver.
...I need to turn off the Linux swap feature...
No, this will not help and I did not know that such an option exists. You could cripple the driver code. As you said you would expose yourself to crashes

@az-hasan
Copy link
Author

az-hasan commented Jun 2, 2019

Ok, so the EPC pages are managed by the SGX driver, not the Linux memory management subsystem. And modifying the driver code is not trivial, and there are no settings I can change anywhere to prevent paging out of the EPC pages?

@sergeay
Copy link
Contributor

sergeay commented Jun 2, 2019

At your own risk...
You probably can comment out the kernel swapper thread creation.
Easy to find, the main method is: ksgxswapd.
Your system will probably become unstable.

@rriley
Copy link

rriley commented Jun 25, 2019

Hi, I'm working with the original question asker. In our case, we're doing some performance testing and want to make sure that our tests are not triggering swapping without us realizing it. The thought with turning it off was that we'd rather have the enclave crash due to running out of memory. (Because then we know we screwed up and should lower our memory usage.)

Thanks for your feedback and help!

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

No branches or pull requests

3 participants