Skip to content

Commit 07321df

Browse files
authored
Merge pull request #81 from BlackDex/fix-ci
Fix CI and update extended.rs
2 parents d5bfccf + 3a84502 commit 07321df

File tree

4 files changed

+101
-59
lines changed

4 files changed

+101
-59
lines changed

.github/workflows/ci.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
steps:
2626
- name: Checkout repository
27-
uses: actions/checkout@v1
27+
uses: actions/checkout@v3
2828
with:
2929
submodules: recursive
3030

@@ -44,7 +44,12 @@ jobs:
4444
uses: actions-rs/cargo@v1
4545
with:
4646
command: test
47-
args: --no-default-features
47+
48+
- name: Test libmimalloc-sys crate bindings (secure)
49+
uses: actions-rs/cargo@v1
50+
with:
51+
command: run
52+
args: -p libmimalloc-sys-test
4853

4954
- name: Build (no secure)
5055
uses: actions-rs/cargo@v1
@@ -58,18 +63,18 @@ jobs:
5863
command: test
5964
args: --no-default-features
6065

61-
- name: Test libmimalloc-sys crate bindings.
66+
- name: Test libmimalloc-sys crate bindings (no secure)
6267
uses: actions-rs/cargo@v1
6368
with:
6469
command: run
65-
args: -p libmimalloc-sys-test
70+
args: --no-default-features -p libmimalloc-sys-test
6671

6772
lint:
6873
name: Rustfmt / Clippy
6974
runs-on: ubuntu-latest
7075

7176
steps:
72-
- uses: actions/checkout@v1
77+
- uses: actions/checkout@v3
7378
with:
7479
submodules: recursive
7580

@@ -97,7 +102,7 @@ jobs:
97102
runs-on: ubuntu-latest
98103
steps:
99104

100-
- uses: actions/checkout@v2
105+
- uses: actions/checkout@v3
101106
with:
102107
submodules: recursive
103108

libmimalloc-sys/src/extended.rs

+88-51
Original file line numberDiff line numberDiff line change
@@ -469,25 +469,27 @@ pub type mi_option_t = c_int;
469469
// show_errors reversed as of 1.6.3, however what I have here is correct:
470470
// https://github.com/microsoft/mimalloc/issues/266#issuecomment-653822341
471471

472-
/// Option allowing printing error messages to stderr.
472+
/// Print error messages to `stderr`.
473473
pub const mi_option_show_errors: mi_option_t = 0;
474474

475-
/// Option allowing printing statistics to stderr when the program is done.
475+
/// Print statistics to `stderr` when the program is done.
476476
pub const mi_option_show_stats: mi_option_t = 1;
477477

478-
/// Option allowing printing verbose messages to stderr.
478+
/// Print verbose messages to `stderr`.
479479
pub const mi_option_verbose: mi_option_t = 2;
480480

481-
/// Option (experimental) specifying eagerly commit segments (4MiB) (enabled by default).
482-
pub const mi_option_eager_commit: mi_option_t = 3;
481+
/// ### The following options are experimental
482+
/// ### Deprecated options are kept for binary backward compatibility with v1.x versions
483483
484-
/// Option (experimental) specifying eagerly commit large (256MiB) memory regions (enabled by default, except on Windows).
485-
pub const mi_option_eager_region_commit: mi_option_t = 4;
484+
/// Option (experimental) Eagerly commit segments (4MiB) (enabled by default).
485+
pub const mi_option_eager_commit: mi_option_t = 3;
486486

487-
/// Experimental
488-
pub const mi_option_reset_decommits: mi_option_t = 5;
487+
/// Option Deprecated
488+
pub const mi_option_deprecated_eager_region_commit: mi_option_t = 4;
489+
/// Option Deprecated
490+
pub const mi_option_deprecated_reset_decommits: mi_option_t = 5;
489491

490-
/// Option (experimental) to use large OS pages (2MiB in size) if possible.
492+
/// Option (experimental) Use large OS pages (2MiB in size) if possible.
491493
///
492494
/// Use large OS pages (2MiB) when available; for some workloads this can
493495
/// significantly improve performance. Use mi_option_verbose to check if
@@ -499,7 +501,7 @@ pub const mi_option_reset_decommits: mi_option_t = 5;
499501
/// instead whenever possible).
500502
pub const mi_option_large_os_pages: mi_option_t = 6;
501503

502-
/// Option (experimental) specifying number of huge OS pages (1GiB in size) to reserve at the start of the program.
504+
/// Option (experimental) The number of huge OS pages (1GiB in size) to reserve at the start of the program.
503505
///
504506
/// This reserves the huge pages at startup and sometimes this can give a large (latency) performance
505507
/// improvement on big workloads. Usually it is better to not use MIMALLOC_LARGE_OS_PAGES in
@@ -512,13 +514,20 @@ pub const mi_option_large_os_pages: mi_option_t = 6;
512514
/// allocate just a little to take up space in the huge OS page area (which cannot be reset).
513515
pub const mi_option_reserve_huge_os_pages: mi_option_t = 7;
514516

515-
/// TODO: update later
516-
pub const mi_option_reserve_os_memory: mi_option_t = 8;
517+
/// Option (experimental) Reserve huge OS pages at node N.
518+
///
519+
/// The huge pages are usually allocated evenly among NUMA nodes.
520+
/// You can use mi_option_reserve_huge_os_pages_at=N where `N` is the numa node (starting at 0) to allocate all
521+
/// the huge pages at a specific numa node instead.
522+
pub const mi_option_reserve_huge_os_pages_at: mi_option_t = 8;
517523

518-
/// Option (experimental) specifying number of segments per thread to keep cached.
519-
pub const mi_option_segment_cache: mi_option_t = 9;
524+
/// Option (experimental) Reserve specified amount of OS memory at startup, e.g. "1g" or "512m".
525+
pub const mi_option_reserve_os_memory: mi_option_t = 9;
520526

521-
/// Option (experimental) to reset page memory after mi_option_reset_delay milliseconds when it becomes free.
527+
/// Option Deprecated
528+
pub const mi_option_deprecated_segment_cache: mi_option_t = 10;
529+
530+
/// Option (experimental) Reset page memory after a mi_option_reset_delay milliseconds when it becomes free.
522531
///
523532
/// By default, mimalloc will reset (or purge) OS pages that are not in use, to signal to the OS
524533
/// that the underlying physical memory can be reused. This can reduce memory fragmentation in
@@ -528,40 +537,49 @@ pub const mi_option_segment_cache: mi_option_t = 9;
528537
/// off completely.
529538
///
530539
/// Default: 1 (true)
531-
pub const mi_option_page_reset: mi_option_t = 10;
540+
pub const mi_option_page_reset: mi_option_t = 11;
532541

533-
/// Experimental
534-
pub const mi_option_abandoned_page_reset: mi_option_t = 11;
542+
/// Option (experimental)
543+
pub const mi_option_abandoned_page_decommit: mi_option_t = 12;
535544

536-
/// Experimental
537-
pub const mi_option_segment_reset: mi_option_t = 12;
545+
// Option (experimental)
546+
pub const mi_option_deprecated_segment_reset: mi_option_t = 13;
538547

539-
/// Experimental
540-
pub const mi_option_eager_commit_delay: mi_option_t = 13;
548+
/// Option (experimental) the first N segments per thread are not eagerly committed (=1).
549+
pub const mi_option_eager_commit_delay: mi_option_t = 14;
541550

542-
/// Option (experimental) specifying delay in milli-seconds before resetting a page (100ms by default).
543-
pub const mi_option_reset_delay: mi_option_t = 14;
551+
/// Option (experimental) Decommit page memory after N milli-seconds delay (25ms).
552+
pub const mi_option_decommit_delay: mi_option_t = 15;
544553

545-
/// Option (experimental) to pretend there are at most N NUMA nodes.
546-
///
547-
/// If not set, the actual NUMA nodes are detected at runtime. Setting N to 1 may avoid
548-
/// problems in some virtual environments. Also, setting it to a lower number than the
549-
/// actual NUMA nodes is fine and will only cause threads to potentially allocate more
550-
/// memory across actual NUMA nodes (but this can happen in any case as NUMA local
551-
/// allocation is always a best effort but not guaranteed).
552-
pub const mi_option_use_numa_nodes: mi_option_t = 15;
554+
/// Option (experimental) Pretend there are at most N NUMA nodes; Use 0 to use the actual detected NUMA nodes at runtime.
555+
pub const mi_option_use_numa_nodes: mi_option_t = 16;
556+
557+
/// Option (experimental) If set to 1, do not use OS memory for allocation (but only pre-reserved arenas)
558+
pub const mi_option_limit_os_alloc: mi_option_t = 17;
559+
560+
/// Option (experimental) OS tag to assign to mimalloc'd memory
561+
pub const mi_option_os_tag: mi_option_t = 18;
562+
563+
/// Option (experimental)
564+
pub const mi_option_max_errors: mi_option_t = 19;
565+
566+
/// Option (experimental)
567+
pub const mi_option_max_warnings: mi_option_t = 20;
553568

554-
/// TODO: update later
555-
pub const mi_option_limit_os_alloc: mi_option_t = 16;
569+
/// Option (experimental)
570+
pub const mi_option_max_segment_reclaim: mi_option_t = 21;
556571

557-
/// Option (experimental) specifying OS tag to assign to mimalloc'd memory.
558-
pub const mi_option_os_tag: mi_option_t = 17;
572+
/// Option (experimental) Enable decommitting memory (=on)
573+
pub const mi_option_allow_decommit: mi_option_t = 22;
559574

560-
/// Experimental
561-
pub const mi_option_max_errors: mi_option_t = 18;
575+
/// Option (experimental) Decommit large segment memory after N milli-seconds delay (500ms).
576+
pub const mi_option_segment_decommit_delay: mi_option_t = 23;
562577

563-
/// Experimental
564-
pub const mi_option_max_warnings: mi_option_t = 19;
578+
/// Option (experimental)
579+
pub const mi_option_decommit_extend_delay: mi_option_t = 24;
580+
581+
/// Last option.
582+
pub const _mi_option_last: mi_option_t = 25;
565583

566584
extern "C" {
567585
// Note: mi_option_{enable,disable} aren't exposed because they're redundant
@@ -670,6 +688,8 @@ pub struct mi_heap_area_t {
670688
pub used: usize,
671689
/// Size in bytes of one block.
672690
pub block_size: usize,
691+
/// Size in bytes of a full block including padding and metadata.
692+
pub full_block_size: usize,
673693
}
674694

675695
/// Visitor function passed to [`mi_heap_visit_blocks`]
@@ -970,17 +990,34 @@ mod tests {
970990
use super::*;
971991

972992
#[test]
973-
fn runtime_option_page_reset() {
993+
fn runtime_option_decommit() {
994+
unsafe {
995+
// decommit slices when no longer used (after decommit_delay milli-seconds) (default 1)
996+
assert_eq!(mi_option_get(mi_option_allow_decommit), 1);
997+
mi_option_set(mi_option_allow_decommit, 0);
998+
assert_eq!(mi_option_get(mi_option_allow_decommit), 0);
999+
1000+
// page decommit delay in milli-seconds (default 25)
1001+
assert_eq!(mi_option_get(mi_option_decommit_delay), 25);
1002+
mi_option_set(mi_option_decommit_delay, 100);
1003+
assert_eq!(mi_option_get(mi_option_decommit_delay), 100);
1004+
}
1005+
}
1006+
1007+
#[test]
1008+
fn runtime_stable_option() {
9741009
unsafe {
975-
// page reset
976-
assert_eq!(mi_option_get(mi_option_page_reset), 1);
977-
mi_option_set(mi_option_page_reset, 2);
978-
assert_eq!(mi_option_get(mi_option_page_reset), 2);
979-
980-
// page reset delay
981-
assert_eq!(mi_option_get(mi_option_reset_delay), 100);
982-
mi_option_set(mi_option_reset_delay, 10_000);
983-
assert_eq!(mi_option_get(mi_option_reset_delay), 10_000);
1010+
assert_eq!(mi_option_get(mi_option_show_errors), 0);
1011+
mi_option_set(mi_option_show_errors, 1);
1012+
assert_eq!(mi_option_get(mi_option_show_errors), 1);
1013+
1014+
assert_eq!(mi_option_get(mi_option_show_stats), 0);
1015+
mi_option_set(mi_option_show_stats, 1);
1016+
assert_eq!(mi_option_get(mi_option_show_stats), 1);
1017+
1018+
assert_eq!(mi_option_get(mi_option_verbose), 0);
1019+
mi_option_set(mi_option_verbose, 1);
1020+
assert_eq!(mi_option_get(mi_option_verbose), 1);
9841021
}
9851022
}
9861023
}

libmimalloc-sys/sys-test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ libmimalloc-sys = { path = "..", features = ["extended"] }
1212
libc = "0.2"
1313

1414
[build-dependencies]
15-
ctest = "0.2"
15+
ctest2 = "0.4"

libmimalloc-sys/sys-test/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
let mut cfg = ctest::TestGenerator::new();
2+
let mut cfg = ctest2::TestGenerator::new();
33
cfg.header("mimalloc.h")
44
.include(concat!(
55
env!("CARGO_MANIFEST_DIR"),

0 commit comments

Comments
 (0)