25
25
//! functions, then try to compile with the `not_glibc_interface` module.
26
26
27
27
#[ cfg( all(
28
+ any( feature = "sysmalloc" , not( feature = "jemalloc" ) ) ,
28
29
target_os = "linux" ,
29
- not( target_env = "musl" ) ,
30
- not( feature = "jemalloc" )
30
+ not( target_env = "musl" )
31
31
) ) ]
32
32
pub mod glibc;
33
33
34
- #[ cfg( feature = "jemalloc" ) ]
34
+ #[ cfg( all ( unix , not ( feature = "sysmalloc" ) , feature = " jemalloc") ) ]
35
35
pub mod jemalloc;
36
36
37
37
pub use interface:: * ;
38
38
39
+ // Glibc malloc is the default on non-musl Linux if the sysmalloc feature is enabled, or jemalloc
40
+ // is disabled.
39
41
#[ cfg( all(
42
+ any( feature = "sysmalloc" , not( feature = "jemalloc" ) ) ,
40
43
target_os = "linux" ,
41
- not( target_env = "musl" ) ,
42
- not( feature = "jemalloc" )
44
+ not( target_env = "musl" )
43
45
) ) ]
44
46
mod interface {
45
47
pub use crate :: glibc:: configure_glibc_malloc as configure_memory_allocator;
46
48
pub use crate :: glibc:: scrape_mallinfo_metrics as scrape_allocator_metrics;
49
+
50
+ pub fn allocator_name ( ) -> String {
51
+ "glibc" . to_string ( )
52
+ }
47
53
}
48
54
49
- #[ cfg( feature = "jemalloc" ) ]
55
+ // Jemalloc is the default on UNIX (including musl) unless the sysmalloc feature is enabled.
56
+ #[ cfg( all( unix, not( feature = "sysmalloc" ) , feature = "jemalloc" ) ) ]
50
57
mod interface {
51
58
#[ allow( dead_code) ]
52
59
pub fn configure_memory_allocator ( ) -> Result < ( ) , String > {
53
60
Ok ( ( ) )
54
61
}
55
62
56
63
pub use crate :: jemalloc:: scrape_jemalloc_metrics as scrape_allocator_metrics;
64
+
65
+ pub fn allocator_name ( ) -> String {
66
+ match crate :: jemalloc:: page_size ( ) {
67
+ Ok ( page_size) => format ! ( "jemalloc ({}K)" , page_size / 1024 ) ,
68
+ Err ( e) => format ! ( "jemalloc (error: {e:?})" ) ,
69
+ }
70
+ }
57
71
}
58
72
59
- #[ cfg( all(
60
- any( not( target_os = "linux" ) , target_env = "musl" ) ,
61
- not( feature = "jemalloc" )
73
+ #[ cfg( any(
74
+ not( unix) ,
75
+ all(
76
+ any( feature = "sysmalloc" , not( feature = "jemalloc" ) ) ,
77
+ any( not( target_os = "linux" ) , target_env = "musl" )
78
+ )
62
79
) ) ]
63
80
mod interface {
64
81
#[ allow( dead_code, clippy:: unnecessary_wraps) ]
@@ -68,4 +85,8 @@ mod interface {
68
85
69
86
#[ allow( dead_code) ]
70
87
pub fn scrape_allocator_metrics ( ) { }
88
+
89
+ pub fn allocator_name ( ) -> String {
90
+ "system" . to_string ( )
91
+ }
71
92
}
0 commit comments