Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1145)

Issue 7068021: Dynamic loading: Fill pages with halts only when they are needed (Closed)

Created:
9 years, 7 months ago by Mark Seaborn
Modified:
9 years, 5 months ago
Reviewers:
bsy, Roland McGrath
CC:
native-client-reviews_googlegroups.com
Visibility:
Public.

Description

Dynamic loading: Fill pages with halts only when they are needed This will save memory and improve startup time. Pages from the dyncode shared memory segment are mapped as unreadable/non-executable to start with. When a page is needed, we fill it with halt instructions and then make it accessible (readable and executable) by untrusted code. We maintain a bitmap of pages that have been allocated in this way. We track allocations at 64k granularity, even though we could use 4k on Unix, so that the observable behaviour on Linux/Mac is the same as on Windows. Also it makes the bitmap a bit smaller (512 bytes for a 256MB dynamic code area). Although we could use a list of ranges, using a bitmap is simpler. Specific changes: * nacl_desc_imc_shm.c: Move the check for PROT_NONE into the Windows-specific code (win/nacl_shm.cc). We need PROT_NONE on Unix, and it works fine there. * sel_ldr_standard.c: Re-order the setup so that NaClAppLoadFile()'s NaCl_mprotect() call does not undo the PROT_NONE/PAGE_NOACCESS permissions we carefully set up in nacl_text.c. Similarly, remove the NaCl_mprotect() call in sel_addrspace.c that was undoing the damage that NaClAppLoadFile() did. * Add a test that checks that unallocated dynamic code pages are inaccessible. Note that on Windows, this change only saves RAM, not swap space. Since we do not yet pass SEC_RESERVE to CreateFileMapping() in nacl_shm.cc, we are still reserving swap space for the whole dynamic code area. This can be fixed but it involves some trickier code on Windows. BUG=http://code.google.com/p/nativeclient/issues/detail?id=503 TEST=run_dynamic_load_test Committed: http://src.chromium.org/viewvc/native_client?view=rev&revision=5481

Patch Set 1 #

Total comments: 2

Patch Set 2 : Fix log messages #

Messages

Total messages: 8 (0 generated)
Mark Seaborn
9 years, 7 months ago (2011-05-25 20:11:32 UTC) #1
Roland McGrath
Is there a real benefit to maintaining a bitmap? It could just be a maximum ...
9 years, 7 months ago (2011-05-25 20:44:31 UTC) #2
Mark Seaborn
On 25 May 2011 21:44, <mcgrathr@chromium.org> wrote: > Is there a real benefit to maintaining ...
9 years, 7 months ago (2011-05-25 20:58:15 UTC) #3
bsy
i generally like the suggestion to use posix_fallocate to ensure sparse shm files on linux, ...
9 years, 7 months ago (2011-05-25 21:56:35 UTC) #4
bsy
small nits. plz fix. o/w lgtm. http://codereview.chromium.org/7068021/diff/1/src/native_client/src/trusted/service_runtime/nacl_text.c File src/native_client/src/trusted/service_runtime/nacl_text.c (right): http://codereview.chromium.org/7068021/diff/1/src/native_client/src/trusted/service_runtime/nacl_text.c#newcode240 src/native_client/src/trusted/service_runtime/nacl_text.c:240: NaClLog(LOG_FATAL, "VirtualProtect() failed\n"); ...
9 years, 7 months ago (2011-05-25 21:56:48 UTC) #5
Mark Seaborn
On 25 May 2011 21:44, <mcgrathr@chromium.org> wrote: > Is there a real benefit to maintaining ...
9 years, 7 months ago (2011-05-25 22:37:56 UTC) #6
Mark Seaborn
On 25 May 2011 22:56, <bsy@google.com> wrote: > small nits. plz fix. o/w lgtm. > ...
9 years, 7 months ago (2011-05-25 22:58:25 UTC) #7
Roland McGrath
9 years, 7 months ago (2011-05-25 22:58:37 UTC) #8
Indeed, a non-sparse file is fairly pessimal for resource use.
The posix_fallocate trick only works because it can de-sparse part of a file
discontiguously.

The only way to win on Mac (i.e. with non-sparse files) is not to use a 1:1
mapping of the backing file to the address space.  That would require a lot more
bookkeeping, to allocate pages from the backing file linearly from the beginning
to be mapped with subsequent mmap calls to whatever portion of the dynamic text
region is actually filled.

Powered by Google App Engine
This is Rietveld 408576698