1414 * https://fortanix.atlassian.net/browse/RTE-36 (under the heading
1515 * "Instructions on how to run the test:" )
1616 */
17+ /*
18+ The performance results produced by this test were quite random to get a clear picture of
19+ improvements between dlmalloc and snmalloc allocator. In order to reduce the randomness
20+ of the tests, use feature flag "reduce_randomness" - RTE-85
21+ */
1722
1823use rand:: Rng ;
1924use std:: alloc:: { alloc, dealloc, Layout } ;
@@ -157,14 +162,30 @@ fn wakeup_all_child_threads(pair_clone: Arc<(Mutex<bool>, Condvar)>) {
157162}
158163
159164fn traverse_buffer ( buf : * mut u8 , size : usize , _scan_interval : usize ) {
160- let num_indices_checks = get_random_num ( 1 , MAX_INDEX_CHECKS_PER_BUFFER ) ;
165+ let num_indices_checks: usize ;
166+ #[ cfg( feature = "reduce_randomness" ) ]
167+ {
168+ num_indices_checks = 10 ;
169+ }
170+ #[ cfg( not( feature = "reduce_randomness" ) ) ]
171+ {
172+ num_indices_checks= get_random_num ( 1 , MAX_INDEX_CHECKS_PER_BUFFER ) ;
173+ }
161174 for _i in 1 ..=num_indices_checks {
162175 /* Check for random indices and number of such indices is num_indices_checks
163176 * Please note that depending on the number random number generator, we
164177 * can check for the same index multiple times. We could have checked
165178 * for all the indices but that would be too time consuming
166179 */
167- let index = get_random_num ( 0 , size - 1 ) ;
180+ let index: usize ;
181+ #[ cfg( feature = "reduce_randomness" ) ]
182+ {
183+ index = _i * 10 % size;
184+ }
185+ #[ cfg( not( feature = "reduce_randomness" ) ) ]
186+ {
187+ index = get_random_num ( 0 , size - 1 ) ;
188+ }
168189 unsafe {
169190 ptr:: write ( buf. offset ( index as isize ) , 1 ) ;
170191 }
@@ -189,7 +210,7 @@ fn worker_thread(
189210 */
190211 loop {
191212 /* Create a random size depending on the memory type */
192- let ( scan_interval, size, limit) = match memsize {
213+ let ( scan_interval, mut size, limit) = match memsize {
193214 MemSize :: Large => {
194215 (
195216 SCAN_INTERVAL_LARGE_THREAD ,
@@ -218,7 +239,21 @@ fn worker_thread(
218239 /* Create an array of x GB where x is a random number between 1 to 4 */
219240
220241 // Create a layout based on the size and alignment
221- let align = get_random_num ( 2 , PAGE_SIZE ) . next_power_of_two ( ) ;
242+ let align: usize ;
243+ #[ cfg( feature = "reduce_randomness" ) ]
244+ {
245+ align = PAGE_SIZE ;
246+ size = match memsize {
247+ MemSize :: Large => crate :: TO_GB * 1 ,
248+ MemSize :: Medium => crate :: TO_MB * 1 ,
249+ MemSize :: Small => crate :: TO_KB * 1
250+ }
251+ }
252+ #[ cfg( not( feature = "reduce_randomness" ) ) ]
253+ {
254+ align = get_random_num ( 2 , PAGE_SIZE ) . next_power_of_two ( ) ;
255+
256+ }
222257 let layout = Layout :: from_size_align ( size, align) . unwrap ( ) ;
223258
224259 // Allocate memory using the global allocator
0 commit comments