psset: Reconceptualize insertion/removal.
Really, this isn't a functional change, just a naming change. We start thinking of pageslabs as being always in the psset. What we used to think of as removal is now thought of as being in the psset, but in the process of being updated (and therefore, unavalable for serving new allocations). This is in preparation of subsequent changes to support deferred purging; allocations will still be in the psset for the purposes of choosing when to purge, but not for purposes of allocation/deallocation.
This commit is contained in:
committed by
David Goldblatt
parent
061cabb712
commit
99fc0717e6
@@ -7,6 +7,8 @@ TEST_BEGIN(test_reserve_alloc) {
|
||||
hpdata_t hpdata;
|
||||
hpdata_init(&hpdata, HPDATA_ADDR, HPDATA_AGE);
|
||||
|
||||
hpdata_updating_set(&hpdata, true);
|
||||
|
||||
/* Allocating a page at a time, we should do first fit. */
|
||||
for (size_t i = 0; i < HUGEPAGE_PAGES; i++) {
|
||||
expect_true(hpdata_consistent(&hpdata), "");
|
||||
@@ -59,6 +61,8 @@ TEST_BEGIN(test_purge_simple) {
|
||||
hpdata_t hpdata;
|
||||
hpdata_init(&hpdata, HPDATA_ADDR, HPDATA_AGE);
|
||||
|
||||
hpdata_updating_set(&hpdata, true);
|
||||
|
||||
void *alloc = hpdata_reserve_alloc(&hpdata, HUGEPAGE_PAGES / 2 * PAGE);
|
||||
expect_ptr_eq(alloc, HPDATA_ADDR, "");
|
||||
|
||||
@@ -107,6 +111,7 @@ TEST_END
|
||||
TEST_BEGIN(test_purge_intervening_dalloc) {
|
||||
hpdata_t hpdata;
|
||||
hpdata_init(&hpdata, HPDATA_ADDR, HPDATA_AGE);
|
||||
hpdata_updating_set(&hpdata, true);
|
||||
|
||||
/* Allocate the first 3/4 of the pages. */
|
||||
void *alloc = hpdata_reserve_alloc(&hpdata, 3 * HUGEPAGE_PAGES / 4 * PAGE);
|
||||
@@ -160,6 +165,7 @@ TEST_END
|
||||
TEST_BEGIN(test_hugify) {
|
||||
hpdata_t hpdata;
|
||||
hpdata_init(&hpdata, HPDATA_ADDR, HPDATA_AGE);
|
||||
hpdata_updating_set(&hpdata, true);
|
||||
|
||||
void *alloc = hpdata_reserve_alloc(&hpdata, HUGEPAGE / 2);
|
||||
expect_ptr_eq(alloc, HPDATA_ADDR, "");
|
||||
|
@@ -19,41 +19,50 @@ static void
|
||||
test_psset_alloc_new(psset_t *psset, hpdata_t *ps, edata_t *r_edata,
|
||||
size_t size) {
|
||||
hpdata_assert_empty(ps);
|
||||
|
||||
/*
|
||||
* As in hpa.c; pretend that the ps is already in the psset and just
|
||||
* being updated, until we implement true insert/removal support.
|
||||
*/
|
||||
if (!hpdata_updating_get(ps)) {
|
||||
hpdata_updating_set(ps, true);
|
||||
}
|
||||
|
||||
void *addr = hpdata_reserve_alloc(ps, size);
|
||||
edata_init(r_edata, edata_arena_ind_get(r_edata), addr, size,
|
||||
/* slab */ false, SC_NSIZES, /* sn */ 0, extent_state_active,
|
||||
/* zeroed */ false, /* committed */ true, EXTENT_PAI_HPA,
|
||||
EXTENT_NOT_HEAD);
|
||||
edata_ps_set(r_edata, ps);
|
||||
psset_insert(psset, ps);
|
||||
psset_update_end(psset, ps);
|
||||
}
|
||||
|
||||
static bool
|
||||
test_psset_alloc_reuse(psset_t *psset, edata_t *r_edata, size_t size) {
|
||||
hpdata_t *ps = psset_fit(psset, size);
|
||||
hpdata_t *ps = psset_pick_alloc(psset, size);
|
||||
if (ps == NULL) {
|
||||
return true;
|
||||
}
|
||||
psset_remove(psset, ps);
|
||||
psset_update_begin(psset, ps);
|
||||
void *addr = hpdata_reserve_alloc(ps, size);
|
||||
edata_init(r_edata, edata_arena_ind_get(r_edata), addr, size,
|
||||
/* slab */ false, SC_NSIZES, /* sn */ 0, extent_state_active,
|
||||
/* zeroed */ false, /* committed */ true, EXTENT_PAI_HPA,
|
||||
EXTENT_NOT_HEAD);
|
||||
edata_ps_set(r_edata, ps);
|
||||
psset_insert(psset, ps);
|
||||
psset_update_end(psset, ps);
|
||||
return false;
|
||||
}
|
||||
|
||||
static hpdata_t *
|
||||
test_psset_dalloc(psset_t *psset, edata_t *edata) {
|
||||
hpdata_t *ps = edata_ps_get(edata);
|
||||
psset_remove(psset, ps);
|
||||
psset_update_begin(psset, ps);
|
||||
hpdata_unreserve(ps, edata_addr_get(edata), edata_size_get(edata));
|
||||
if (hpdata_empty(ps)) {
|
||||
return ps;
|
||||
} else {
|
||||
psset_insert(psset, ps);
|
||||
psset_update_end(psset, ps);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -390,9 +399,9 @@ TEST_BEGIN(test_stats) {
|
||||
|
||||
test_psset_alloc_new(&psset, &pageslab, &alloc[0], PAGE);
|
||||
stats_expect(&psset, 1);
|
||||
psset_remove(&psset, &pageslab);
|
||||
psset_update_begin(&psset, &pageslab);
|
||||
stats_expect(&psset, 0);
|
||||
psset_insert(&psset, &pageslab);
|
||||
psset_update_end(&psset, &pageslab);
|
||||
stats_expect(&psset, 1);
|
||||
}
|
||||
TEST_END
|
||||
@@ -490,7 +499,7 @@ TEST_BEGIN(test_insert_remove) {
|
||||
worse_alloc);
|
||||
|
||||
/* Remove better; should still be able to alloc from worse. */
|
||||
psset_remove(&psset, &pageslab);
|
||||
psset_update_begin(&psset, &pageslab);
|
||||
err = test_psset_alloc_reuse(&psset, &worse_alloc[HUGEPAGE_PAGES - 1],
|
||||
PAGE);
|
||||
expect_false(err, "Removal should still leave an empty page");
|
||||
@@ -504,7 +513,7 @@ TEST_BEGIN(test_insert_remove) {
|
||||
*/
|
||||
ps = test_psset_dalloc(&psset, &worse_alloc[HUGEPAGE_PAGES - 1]);
|
||||
expect_ptr_null(ps, "Incorrect eviction of nonempty pageslab");
|
||||
psset_insert(&psset, &pageslab);
|
||||
psset_update_end(&psset, &pageslab);
|
||||
err = test_psset_alloc_reuse(&psset, &alloc[HUGEPAGE_PAGES - 1], PAGE);
|
||||
expect_false(err, "psset should be nonempty");
|
||||
expect_ptr_eq(&pageslab, edata_ps_get(&alloc[HUGEPAGE_PAGES - 1]),
|
||||
@@ -514,8 +523,8 @@ TEST_BEGIN(test_insert_remove) {
|
||||
*/
|
||||
ps = test_psset_dalloc(&psset, &alloc[HUGEPAGE_PAGES - 1]);
|
||||
expect_ptr_null(ps, "Incorrect eviction");
|
||||
psset_remove(&psset, &pageslab);
|
||||
psset_remove(&psset, &worse_pageslab);
|
||||
psset_update_begin(&psset, &pageslab);
|
||||
psset_update_begin(&psset, &worse_pageslab);
|
||||
err = test_psset_alloc_reuse(&psset, &alloc[HUGEPAGE_PAGES - 1], PAGE);
|
||||
expect_true(err, "psset should be empty, but an alloc succeeded");
|
||||
}
|
||||
|
Reference in New Issue
Block a user