Skip to content

Commit 947520b

Browse files
committed
Enable transparent huge pages
This enables transparent huge pages in jemalloc for clusterd, if enable_transparent_hugepages is enabled at the time we create the cluster replica. Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 2c490ef commit 947520b

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

misc/python/materialize/mzcompose/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def get_minimal_system_parameters(
113113
"enable_sql_server_source": "true",
114114
"enable_statement_lifecycle_logging": "true",
115115
"enable_compute_temporal_bucketing": "true",
116+
"enabel_transparent_hugepages": "true",
116117
"enable_variadic_left_join_lowering": "true",
117118
"enable_worker_core_affinity": "true",
118119
"grpc_client_http2_keep_alive_timeout": "5s",
@@ -564,6 +565,7 @@ def get_default_system_parameters(
564565
"enable_ctp_cluster_protocols",
565566
"enable_paused_cluster_readhold_downgrade",
566567
"force_swap_for_cc_sizes",
568+
"enable_transparent_hugepages",
567569
]
568570

569571

misc/python/materialize/parallel_workload/action.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ def __init__(
13221322
"enable_mz_join_core_v2",
13231323
"force_swap_for_cc_sizes",
13241324
"enable_with_ordinality_legacy_fallback",
1325+
"enable_transparent_hugepages",
13251326
]
13261327

13271328
def run(self, exe: Executor) -> bool:

src/controller-types/src/dyncfgs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ pub const ENABLE_PAUSED_CLUSTER_READHOLD_DOWNGRADE: Config<bool> = Config::new(
8080
"Aggressively downgrade input read holds for indexes on zero-replica clusters.",
8181
);
8282

83+
pub const ENABLE_TRANSPARENT_HUGEPAGES: Config<bool> = Config::new(
84+
"enable_transparent_hugepages",
85+
false,
86+
"Enable transparent hugepages in clusterd with jemalloc.",
87+
);
88+
8389
/// Adds the full set of all controller `Config`s.
8490
pub fn all_dyncfgs(configs: ConfigSet) -> ConfigSet {
8591
configs
@@ -90,6 +96,7 @@ pub fn all_dyncfgs(configs: ConfigSet) -> ConfigSet {
9096
.add(&WALLCLOCK_LAG_HISTOGRAM_PERIOD_INTERVAL)
9197
.add(&ENABLE_TIMELY_ZERO_COPY)
9298
.add(&ENABLE_TIMELY_ZERO_COPY_LGALLOC)
99+
.add(&ENABLE_TRANSPARENT_HUGEPAGES)
93100
.add(&TIMELY_ZERO_COPY_LIMIT)
94101
.add(&ARRANGEMENT_EXERT_PROPORTIONALITY)
95102
.add(&ENABLE_CTP_CLUSTER_PROTOCOLS)

src/controller/src/clusters.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use mz_compute_types::config::{ComputeReplicaConfig, ComputeReplicaLogging};
2828
use mz_controller_types::dyncfgs::{
2929
ARRANGEMENT_EXERT_PROPORTIONALITY, CONTROLLER_PAST_GENERATION_REPLICA_CLEANUP_RETRY_INTERVAL,
3030
ENABLE_CTP_CLUSTER_PROTOCOLS, ENABLE_TIMELY_ZERO_COPY, ENABLE_TIMELY_ZERO_COPY_LGALLOC,
31-
TIMELY_ZERO_COPY_LIMIT,
31+
ENABLE_TRANSPARENT_HUGEPAGES, TIMELY_ZERO_COPY_LIMIT,
3232
};
3333
use mz_controller_types::{ClusterId, ReplicaId};
3434
use mz_orchestrator::NamespacedOrchestrator;
@@ -819,6 +819,7 @@ where
819819
}],
820820
disk_limit,
821821
node_selector: location.allocation.selectors,
822+
enable_transparent_hugepages: ENABLE_TRANSPARENT_HUGEPAGES.get(&self.dyncfg),
822823
},
823824
)?;
824825

src/orchestrator-kubernetes/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ impl NamespacedOrchestrator for NamespacedKubernetesOrchestrator {
568568
replicas_selector,
569569
disk_limit,
570570
node_selector,
571+
enable_transparent_hugepages,
571572
}: ServiceConfig,
572573
) -> Result<Box<dyn Service>, anyhow::Error> {
573574
// This is extremely cheap to clone, so just look into the lock once.
@@ -971,7 +972,7 @@ impl NamespacedOrchestrator for NamespacedKubernetesOrchestrator {
971972
}]
972973
});
973974

974-
let env = if self.config.coverage {
975+
let mut env = if self.config.coverage {
975976
Some(vec![EnvVar {
976977
name: "LLVM_PROFILE_FILE".to_string(),
977978
value: Some(format!("/coverage/{}-%p-%9m%c.profraw", self.namespace)),
@@ -981,6 +982,20 @@ impl NamespacedOrchestrator for NamespacedKubernetesOrchestrator {
981982
None
982983
};
983984

985+
// Configure jemalloc to use transparent hugepages.
986+
if enable_transparent_hugepages {
987+
let var = EnvVar {
988+
name: "MALLOC_CONF".to_string(),
989+
value: Some("thp:always".to_string()),
990+
..Default::default()
991+
};
992+
if let Some(env) = &mut env {
993+
env.push(var);
994+
} else {
995+
env = Some(vec![var]);
996+
}
997+
}
998+
984999
let mut volume_mounts = vec![];
9851000

9861001
if self.config.coverage {

src/orchestrator-process/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl NamespacedOrchestrator for NamespacedProcessOrchestrator {
345345
cpu_limit: config.cpu_limit,
346346
scale: config.scale,
347347
labels: config.labels,
348+
enable_transparent_hugepages: config.enable_transparent_hugepages,
348349
disk,
349350
};
350351

@@ -461,6 +462,8 @@ struct EnsureServiceConfig {
461462
pub labels: BTreeMap<String, String>,
462463
/// Whether scratch disk space should be allocated for the service.
463464
pub disk: bool,
465+
/// Whether to enable transparent hugepages.
466+
pub enable_transparent_hugepages: bool,
464467
}
465468

466469
/// A task executing blocking work for a [`NamespacedProcessOrchestrator`] in the background.
@@ -572,6 +575,7 @@ impl OrchestratorWorker {
572575
scale,
573576
labels,
574577
disk,
578+
enable_transparent_hugepages,
575579
}: EnsureServiceConfig,
576580
) -> Result<(), anyhow::Error> {
577581
let full_id = self.config.full_id(&id);
@@ -686,6 +690,7 @@ impl OrchestratorWorker {
686690
memory_limit,
687691
cpu_limit,
688692
launch_spec: self.config.launch_spec,
693+
enable_transparent_hugepages,
689694
}),
690695
);
691696

@@ -791,6 +796,7 @@ impl OrchestratorWorker {
791796
memory_limit,
792797
cpu_limit,
793798
launch_spec,
799+
enable_transparent_hugepages,
794800
}: ServiceProcessConfig,
795801
) -> impl Future<Output = ()> + use<> {
796802
let suppress_output = self.config.suppress_output;
@@ -838,6 +844,9 @@ impl OrchestratorWorker {
838844
memory_limit.as_ref(),
839845
cpu_limit.as_ref(),
840846
);
847+
if enable_transparent_hugepages {
848+
cmd.env("MALLOC_CONF", "thp:always");
849+
}
841850
info!(
842851
"launching {full_id}-{i} via {} {}...",
843852
cmd.as_std().get_program().to_string_lossy(),
@@ -933,6 +942,7 @@ struct ServiceProcessConfig {
933942
memory_limit: Option<MemoryLimit>,
934943
cpu_limit: Option<CpuLimit>,
935944
launch_spec: LaunchSpec,
945+
enable_transparent_hugepages: bool,
936946
}
937947

938948
struct ServiceProcessPort {

src/orchestrator/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ pub struct ServiceConfig {
243243
pub disk_limit: Option<DiskLimit>,
244244
/// Node selector for this service.
245245
pub node_selector: BTreeMap<String, String>,
246+
/// Whether to enable transparent hugepages.
247+
pub enable_transparent_hugepages: bool,
246248
}
247249

248250
/// A named port associated with a service.

0 commit comments

Comments
 (0)