Skip to content

Commit

Permalink
tweak + refresh dist/
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonin Reitz committed Jul 21, 2024
1 parent 5fbdcf8 commit 1c3c3f9
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 38 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ FILES = \
dist/Slots.c \
dist/Bitmap5.c \
dist/Utils2.c \
dist/Constants.c \
dist/SizeClass.c \
dist/SizeClassSelection.c \
dist/PtrdiffWrapper.c \
Expand Down
4 changes: 1 addition & 3 deletions dist/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ bool Config_enable_quarantine_trap = true;

bool Config_enable_quarantine_strict_trap = false;

size_t Config_quarantine_queue_length = (size_t)1024U;

size_t Config_quarantine_queue_threshold = (size_t)256U;
size_t Config_quarantine_queue_length = (size_t)4096U;

bool Config_enable_zeroing_malloc = true;

Expand Down
2 changes: 0 additions & 2 deletions dist/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ extern bool Config_enable_quarantine_strict_trap;

extern size_t Config_quarantine_queue_length;

extern size_t Config_quarantine_queue_threshold;

extern bool Config_enable_zeroing_malloc;

extern bool Config_enable_zeroing_free;
Expand Down
5 changes: 5 additions & 0 deletions dist/Constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@

uint32_t Constants_page_size = 4096U;

uint32_t Constants_nb_slots(uint32_t size_class)
{
return 4096U / size_class;
}

2 changes: 2 additions & 0 deletions dist/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

extern uint32_t Constants_page_size;

uint32_t Constants_nb_slots(uint32_t size_class);


#define __Constants_H_DEFINED
#endif
6 changes: 3 additions & 3 deletions dist/Slabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ update_quarantine2(
size_t idx7
)
{
if (idx7 < (size_t)1024U)
if (idx7 < (size_t)4096U)
return ((tuple4){ .x = idx1, .y = idx5, .z = idx6, .w = idx7 });
else
{
Expand All @@ -78,7 +78,7 @@ static void update_quarantine3_aux(uint8_t *slab_region, tuple4 idxs)

static void update_quarantine3(uint8_t *slab_region, size_t idx7, tuple4 idxs)
{
if (!(idx7 < (size_t)1024U))
if (!(idx7 < (size_t)4096U))
update_quarantine3_aux(slab_region, idxs);
}

Expand Down Expand Up @@ -382,7 +382,7 @@ uint8_t
}
else
{
bool b = idx7_ >= (size_t)256U;
bool b = idx7_ >= (size_t)Constants_nb_slots(size_class) * (size_t)4U;
if (b)
{
bounded_tuple_
Expand Down
2 changes: 1 addition & 1 deletion dist/Slots.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static uint8_t *get_slot_as_returned_value(uint32_t size_class, uint8_t *arr, ui

static uint32_t get_free_slot(uint32_t size_class, uint64_t *bitmap, uint64_t *bitmap_q)
{
uint32_t nb_slots_v = Utils2_nb_slots(size_class);
uint32_t nb_slots_v = Constants_nb_slots(size_class);
uint32_t bound = nb_slots_v / 64U;
uint32_t nb_slots_v_rem = nb_slots_v % 64U;
uint32_t bound2;
Expand Down
15 changes: 5 additions & 10 deletions dist/Utils2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

#include "Utils2.h"

uint32_t Utils2_nb_slots(uint32_t size_class)
{
return 4096U / size_class;
}

size_t Utils2_rounding(uint32_t size_class)
{
return (size_t)(Utils2_nb_slots(size_class) * size_class);
return (size_t)(Constants_nb_slots(size_class) * size_class);
}

uint64_t Utils2_full_n_aux(uint32_t bound)
Expand All @@ -32,7 +27,7 @@ uint64_t Utils2_full_n(uint32_t bound)

bool Utils2_is_empty_s(uint32_t size_class, uint64_t *md)
{
uint32_t bound = Utils2_nb_slots(size_class) / 64U;
uint32_t bound = Constants_nb_slots(size_class) / 64U;
uint64_t v0 = md[0U];
uint64_t v1 = md[1U];
uint64_t v2 = md[2U];
Expand All @@ -47,7 +42,7 @@ bool Utils2_is_empty_s(uint32_t size_class, uint64_t *md)

bool Utils2_is_empty_s2(uint32_t size_class, uint64_t *md, uint64_t *md_q)
{
uint32_t bound = Utils2_nb_slots(size_class) / 64U;
uint32_t bound = Constants_nb_slots(size_class) / 64U;
uint64_t v0 = md[0U];
uint64_t v1 = md[1U];
uint64_t v2 = md[2U];
Expand All @@ -66,7 +61,7 @@ bool Utils2_is_empty_s2(uint32_t size_class, uint64_t *md, uint64_t *md_q)

bool Utils2_has_free_slot_s(uint32_t size_class, uint64_t *md)
{
uint32_t nb_slots_v = Utils2_nb_slots(size_class);
uint32_t nb_slots_v = Constants_nb_slots(size_class);
uint32_t bound = nb_slots_v / 64U;
uint32_t nb_slots_v_rem = nb_slots_v % 64U;
uint32_t bound2;
Expand All @@ -88,7 +83,7 @@ bool Utils2_has_free_slot_s(uint32_t size_class, uint64_t *md)

bool Utils2_has_free_slot_s2(uint32_t size_class, uint64_t *md, uint64_t *md_q)
{
uint32_t nb_slots_v = Utils2_nb_slots(size_class);
uint32_t nb_slots_v = Constants_nb_slots(size_class);
uint32_t bound = nb_slots_v / 64U;
uint32_t nb_slots_v_rem = nb_slots_v % 64U;
uint32_t bound2;
Expand Down
2 changes: 1 addition & 1 deletion dist/Utils2.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "krmllib.h"

uint32_t Utils2_nb_slots(uint32_t size_class);
#include "Constants.h"

size_t Utils2_rounding(uint32_t size_class);

Expand Down
1 change: 1 addition & 0 deletions dist/internal/Slabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "internal/ArrayList.h"
#include "Utils2.h"
#include "MemoryTrap.h"
#include "Constants.h"
#include "ArrayList.h"

bool
Expand Down
1 change: 1 addition & 0 deletions dist/internal/Slots.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "Utils2.h"
#include "ExternUtils.h"
#include "Constants.h"
#include "Bitmap5.h"

uint8_t
Expand Down
5 changes: 3 additions & 2 deletions src/Config.fst
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ let enable_quarantine = true
let enable_quarantine_slot = true
let enable_quarantine_trap = true
let enable_quarantine_strict_trap = false
let quarantine_queue_length = 1024sz
let quarantine_queue_threshold = 256sz
let quarantine_queue_length = 4096sz

let quarantine_queue_threshold sc = US.mul (US.uint32_to_sizet (nb_slots sc)) 4sz
let enable_quarantine_lemma _ = ()

// zeroing
Expand Down
6 changes: 4 additions & 2 deletions src/Config.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ inline_for_extraction
val enable_quarantine_strict_trap: bool
inline_for_extraction
val quarantine_queue_length: v:US.t{0 < US.v v /\ US.v v <= US.v metadata_max}
inline_for_extraction
val quarantine_queue_threshold: v:US.t{0 < US.v v /\ US.v v < US.v quarantine_queue_length}
//: v:US.t{0 < US.v v /\ US.v v < US.v quarantine_queue_length}
noextract inline_for_extraction
val quarantine_queue_threshold (size_class: sc) : (v:US.t{0 < US.v v})

// required
val enable_quarantine_lemma (_:unit)
: Lemma
Expand Down
13 changes: 13 additions & 0 deletions src/Constants.fst
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ let sc = x:U32.t{
// allowing use of SSE instructions
(U32.v x % 16 == 0)
}

#push-options "--z3rlimit 30"
let nb_slots (size_class: sc)
: Pure U32.t
(requires True)
(ensures fun r ->
U32.v r >= 1 /\
U32.v r <= 256
)
=
//TODO: stabilize
U32.div page_size size_class
#pop-options
4 changes: 3 additions & 1 deletion src/SlabsAlloc.fst
Original file line number Diff line number Diff line change
Expand Up @@ -3357,8 +3357,10 @@ let allocate_slab'
(if (A.is_null r) then emp else A.varray r);
return r
) else (
let b = US.gte idx7 quarantine_queue_threshold in
let b = US.gte idx7 (quarantine_queue_threshold size_class) in
//let b = US.gte idx7 (US.mul (US.uint32_to_sizet (nb_slots size_class)) 4sz) in
if enable_quarantine && b then (
assume (idx7 <> 0sz);
let idxs = allocate_slab_aux_4 size_class
slab_region md_bm_region md_bm_region_q md_region md_count r_idxs
md_count_v md_region_lv
Expand Down
13 changes: 0 additions & 13 deletions src/Utils2.fst
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ unfold let slab_metadata = r:array U64.t{A.length r = 4}
let array_u8_alignment = ArrayAlignment.array_u8_alignment
let array_u8_alignment_lemma = ArrayAlignment.array_u8_alignment_lemma

#push-options "--z3rlimit 30"
let nb_slots (size_class: sc)
: Pure U32.t
(requires True)
(ensures fun r ->
U32.v r >= 1 /\
U32.v r <= 256
)
=
//TODO: stabilize
U32.div page_size size_class
#pop-options

open FStar.Mul

open Prelude
Expand Down

0 comments on commit 1c3c3f9

Please sign in to comment.