@@ -28,7 +28,7 @@ use crate::util::heap::layout::Mmapper;
28
28
use crate :: util:: heap:: layout:: VMMap ;
29
29
use crate :: util:: heap:: space_descriptor:: SpaceDescriptor ;
30
30
use crate :: util:: heap:: HeapMeta ;
31
- use crate :: util:: memory;
31
+ use crate :: util:: memory:: { self , HugePageSupport , MmapProtection , MmapStrategy } ;
32
32
use crate :: vm:: VMBinding ;
33
33
34
34
use std:: marker:: PhantomData ;
@@ -137,13 +137,13 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
137
137
) ;
138
138
let bytes = conversions:: pages_to_bytes ( res. pages ) ;
139
139
140
- let map_sidemetadata = || {
140
+ let mmap = || {
141
141
// Mmap the pages and the side metadata, and handle error. In case of any error,
142
142
// we will either call back to the VM for OOM, or simply panic.
143
143
if let Err ( mmap_error) = self
144
144
. common ( )
145
145
. mmapper
146
- . ensure_mapped ( res. start , res. pages )
146
+ . ensure_mapped ( res. start , res. pages , self . common ( ) . mmap_strategy ( ) )
147
147
. and (
148
148
self . common ( )
149
149
. metadata
@@ -160,7 +160,7 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
160
160
// The scope of the lock is important in terms of performance when we have many allocator threads.
161
161
if SFT_MAP . get_side_metadata ( ) . is_some ( ) {
162
162
// If the SFT map uses side metadata, so we have to initialize side metadata first.
163
- map_sidemetadata ( ) ;
163
+ mmap ( ) ;
164
164
// then grow space, which will use the side metadata we mapped above
165
165
grow_space ( ) ;
166
166
// then we can drop the lock after grow_space()
@@ -170,7 +170,7 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
170
170
grow_space ( ) ;
171
171
drop ( lock) ;
172
172
// and map side metadata without holding the lock
173
- map_sidemetadata ( ) ;
173
+ mmap ( ) ;
174
174
}
175
175
176
176
// TODO: Concurrent zeroing
@@ -421,11 +421,13 @@ pub struct CommonSpace<VM: VMBinding> {
421
421
// the copy semantics for the space.
422
422
pub copy : Option < CopySemantics > ,
423
423
424
- immortal : bool ,
425
- movable : bool ,
424
+ pub immortal : bool ,
425
+ pub movable : bool ,
426
426
pub contiguous : bool ,
427
427
pub zeroed : bool ,
428
428
429
+ pub permission_exec : bool ,
430
+
429
431
pub start : Address ,
430
432
pub extent : usize ,
431
433
@@ -443,6 +445,7 @@ pub struct CommonSpace<VM: VMBinding> {
443
445
444
446
pub gc_trigger : Arc < GCTrigger < VM > > ,
445
447
pub global_state : Arc < GlobalState > ,
448
+ pub options : Arc < Options > ,
446
449
447
450
p : PhantomData < VM > ,
448
451
}
@@ -459,6 +462,7 @@ pub struct PolicyCreateSpaceArgs<'a, VM: VMBinding> {
459
462
pub struct PlanCreateSpaceArgs < ' a , VM : VMBinding > {
460
463
pub name : & ' static str ,
461
464
pub zeroed : bool ,
465
+ pub permission_exec : bool ,
462
466
pub vmrequest : VMRequest ,
463
467
pub global_side_metadata_specs : Vec < SideMetadataSpec > ,
464
468
pub vm_map : & ' static dyn VMMap ,
@@ -467,7 +471,7 @@ pub struct PlanCreateSpaceArgs<'a, VM: VMBinding> {
467
471
pub constraints : & ' a PlanConstraints ,
468
472
pub gc_trigger : Arc < GCTrigger < VM > > ,
469
473
pub scheduler : Arc < GCWorkScheduler < VM > > ,
470
- pub options : & ' a Options ,
474
+ pub options : Arc < Options > ,
471
475
pub global_state : Arc < GlobalState > ,
472
476
}
473
477
@@ -498,6 +502,7 @@ impl<VM: VMBinding> CommonSpace<VM> {
498
502
immortal : args. immortal ,
499
503
movable : args. movable ,
500
504
contiguous : true ,
505
+ permission_exec : args. plan_args . permission_exec ,
501
506
zeroed : args. plan_args . zeroed ,
502
507
start : unsafe { Address :: zero ( ) } ,
503
508
extent : 0 ,
@@ -511,6 +516,7 @@ impl<VM: VMBinding> CommonSpace<VM> {
511
516
} ,
512
517
acquire_lock : Mutex :: new ( ( ) ) ,
513
518
global_state : args. plan_args . global_state ,
519
+ options : args. plan_args . options . clone ( ) ,
514
520
p : PhantomData ,
515
521
} ;
516
522
@@ -619,6 +625,21 @@ impl<VM: VMBinding> CommonSpace<VM> {
619
625
pub fn vm_map ( & self ) -> & ' static dyn VMMap {
620
626
self . vm_map
621
627
}
628
+
629
+ pub fn mmap_strategy ( & self ) -> MmapStrategy {
630
+ MmapStrategy {
631
+ huge_page : if * self . options . transparent_hugepages {
632
+ HugePageSupport :: TransparentHugePages
633
+ } else {
634
+ HugePageSupport :: No
635
+ } ,
636
+ prot : if self . permission_exec || cfg ! ( feature = "exec_permission_on_all_spaces" ) {
637
+ MmapProtection :: ReadWriteExec
638
+ } else {
639
+ MmapProtection :: ReadWrite
640
+ } ,
641
+ }
642
+ }
622
643
}
623
644
624
645
fn get_frac_available ( frac : f32 ) -> usize {
0 commit comments