hpdata: Rename "dirty" to "touched".

This matches the usage in the rest of the codebase.
This commit is contained in:
David Goldblatt 2020-12-03 18:58:58 -08:00 committed by David Goldblatt
parent be0d7a53f3
commit 68a1666e91
4 changed files with 34 additions and 29 deletions

View File

@ -67,14 +67,14 @@ struct hpdata_s {
fb_group_t active_pages[FB_NGROUPS(HUGEPAGE_PAGES)];
/*
* Number of dirty pages, and a bitmap tracking them. This really means
* "dirty" from the OS's point of view; it includes both active and
* inactive pages that have been touched by the user.
* Number of dirty or active pages, and a bitmap tracking them. One
* way to think of this is as which pages are dirty from the OS's
* perspective.
*/
size_t h_ndirty;
size_t h_ntouched;
/* The dirty pages (using the same definition as above). */
fb_group_t dirty_pages[FB_NGROUPS(HUGEPAGE_PAGES)];
fb_group_t touched_pages[FB_NGROUPS(HUGEPAGE_PAGES)];
};
TYPED_LIST(hpdata_list, hpdata_t, ql_link)
@ -148,9 +148,14 @@ hpdata_nactive_get(hpdata_t *hpdata) {
return hpdata->h_nactive;
}
static inline size_t
hpdata_ntouched_get(hpdata_t *hpdata) {
return hpdata->h_ntouched;
}
static inline size_t
hpdata_ndirty_get(hpdata_t *hpdata) {
return hpdata->h_ndirty;
return hpdata->h_ntouched - hpdata->h_nactive;
}
static inline void
@ -174,14 +179,14 @@ hpdata_consistent(hpdata_t *hpdata) {
!= hpdata->h_nactive) {
return false;
}
if (fb_scount(hpdata->dirty_pages, HUGEPAGE_PAGES, 0, HUGEPAGE_PAGES)
!= hpdata->h_ndirty) {
if (fb_scount(hpdata->touched_pages, HUGEPAGE_PAGES, 0, HUGEPAGE_PAGES)
!= hpdata->h_ntouched) {
return false;
}
if (hpdata->h_ndirty < hpdata->h_nactive) {
if (hpdata->h_ntouched < hpdata->h_nactive) {
return false;
}
if (hpdata->h_huge && hpdata->h_ndirty != HUGEPAGE_PAGES) {
if (hpdata->h_huge && hpdata->h_ntouched != HUGEPAGE_PAGES) {
return false;
}
return true;

View File

@ -161,7 +161,7 @@ hpa_should_purge(hpa_shard_t *shard, hpdata_t *ps) {
if (hpdata_changing_state_get(ps)) {
return false;
}
size_t purgeable = hpdata_ndirty_get(ps) - hpdata_nactive_get(ps);
size_t purgeable = hpdata_ndirty_get(ps);
return purgeable > HUGEPAGE_PAGES * 25 / 100
|| (purgeable > 0 && hpdata_empty(ps));
}

View File

@ -28,8 +28,8 @@ hpdata_init(hpdata_t *hpdata, void *addr, uint64_t age) {
hpdata_longest_free_range_set(hpdata, HUGEPAGE_PAGES);
hpdata->h_nactive = 0;
fb_init(hpdata->active_pages, HUGEPAGE_PAGES);
hpdata->h_ndirty = 0;
fb_init(hpdata->dirty_pages, HUGEPAGE_PAGES);
hpdata->h_ntouched = 0;
fb_init(hpdata->touched_pages, HUGEPAGE_PAGES);
hpdata_assert_consistent(hpdata);
}
@ -84,10 +84,10 @@ hpdata_reserve_alloc(hpdata_t *hpdata, size_t sz) {
* We might be about to dirty some memory for the first time; update our
* count if so.
*/
size_t new_dirty = fb_ucount(hpdata->dirty_pages, HUGEPAGE_PAGES,
size_t new_dirty = fb_ucount(hpdata->touched_pages, HUGEPAGE_PAGES,
result, npages);
fb_set_range(hpdata->dirty_pages, HUGEPAGE_PAGES, result, npages);
hpdata->h_ndirty += new_dirty;
fb_set_range(hpdata->touched_pages, HUGEPAGE_PAGES, result, npages);
hpdata->h_ntouched += new_dirty;
/*
* We might have shrunk the longest free range. We have to keep
@ -167,10 +167,10 @@ hpdata_purge_begin(hpdata_t *hpdata, hpdata_purge_state_t *purge_state) {
*/
fb_bit_not(purge_state->to_purge, hpdata->active_pages, HUGEPAGE_PAGES);
fb_bit_and(purge_state->to_purge, purge_state->to_purge,
hpdata->dirty_pages, HUGEPAGE_PAGES);
hpdata->touched_pages, HUGEPAGE_PAGES);
/* We purge everything we can. */
assert(hpdata->h_ndirty - hpdata->h_nactive == fb_scount(
assert(hpdata->h_ntouched - hpdata->h_nactive == fb_scount(
purge_state->to_purge, HUGEPAGE_PAGES, 0, HUGEPAGE_PAGES));
hpdata_assert_consistent(hpdata);
@ -225,10 +225,10 @@ hpdata_purge_end(hpdata_t *hpdata, hpdata_purge_state_t *purge_state) {
fb_bit_not(purge_state->to_purge, purge_state->to_purge,
HUGEPAGE_PAGES);
fb_bit_and(hpdata->dirty_pages, hpdata->dirty_pages,
fb_bit_and(hpdata->touched_pages, hpdata->touched_pages,
purge_state->to_purge, HUGEPAGE_PAGES);
assert(hpdata->h_ndirty >= purge_state->npurged);
hpdata->h_ndirty -= purge_state->npurged;
assert(hpdata->h_ntouched >= purge_state->npurged);
hpdata->h_ntouched -= purge_state->npurged;
hpdata_assert_consistent(hpdata);
}
@ -241,8 +241,8 @@ hpdata_hugify_begin(hpdata_t *hpdata) {
assert(!hpdata->h_mid_hugify);
hpdata->h_mid_hugify = true;
hpdata->h_huge = true;
fb_set_range(hpdata->dirty_pages, HUGEPAGE_PAGES, 0, HUGEPAGE_PAGES);
hpdata->h_ndirty = HUGEPAGE_PAGES;
fb_set_range(hpdata->touched_pages, HUGEPAGE_PAGES, 0, HUGEPAGE_PAGES);
hpdata->h_ntouched = HUGEPAGE_PAGES;
hpdata_assert_consistent(hpdata);
}

View File

@ -65,7 +65,7 @@ TEST_BEGIN(test_purge_simple) {
/* Create HUGEPAGE_PAGES / 4 dirty inactive pages at the beginning. */
hpdata_unreserve(&hpdata, alloc, HUGEPAGE_PAGES / 4 * PAGE);
expect_zu_eq(hpdata_ndirty_get(&hpdata), HUGEPAGE_PAGES / 2, "");
expect_zu_eq(hpdata_ntouched_get(&hpdata), HUGEPAGE_PAGES / 2, "");
expect_false(hpdata_changing_state_get(&hpdata), "");
@ -93,7 +93,7 @@ TEST_BEGIN(test_purge_simple) {
hpdata_purge_end(&hpdata, &purge_state);
expect_false(hpdata_changing_state_get(&hpdata), "");
expect_zu_eq(hpdata_ndirty_get(&hpdata), HUGEPAGE_PAGES / 4, "");
expect_zu_eq(hpdata_ntouched_get(&hpdata), HUGEPAGE_PAGES / 4, "");
}
TEST_END
@ -118,7 +118,7 @@ TEST_BEGIN(test_purge_intervening_dalloc) {
(void *)((uintptr_t)alloc + 2 * HUGEPAGE_PAGES / 4 * PAGE),
HUGEPAGE_PAGES / 4 * PAGE);
expect_zu_eq(hpdata_ndirty_get(&hpdata), 3 * HUGEPAGE_PAGES / 4, "");
expect_zu_eq(hpdata_ntouched_get(&hpdata), 3 * HUGEPAGE_PAGES / 4, "");
hpdata_purge_state_t purge_state;
hpdata_purge_begin(&hpdata, &purge_state);
@ -153,7 +153,7 @@ TEST_BEGIN(test_purge_intervening_dalloc) {
hpdata_purge_end(&hpdata, &purge_state);
expect_zu_eq(hpdata_ndirty_get(&hpdata), HUGEPAGE_PAGES / 4, "");
expect_zu_eq(hpdata_ntouched_get(&hpdata), HUGEPAGE_PAGES / 4, "");
}
TEST_END
@ -164,7 +164,7 @@ TEST_BEGIN(test_hugify) {
void *alloc = hpdata_reserve_alloc(&hpdata, HUGEPAGE / 2);
expect_ptr_eq(alloc, HPDATA_ADDR, "");
expect_zu_eq(HUGEPAGE_PAGES / 2, hpdata_ndirty_get(&hpdata), "");
expect_zu_eq(HUGEPAGE_PAGES / 2, hpdata_ntouched_get(&hpdata), "");
expect_false(hpdata_changing_state_get(&hpdata), "");
hpdata_hugify_begin(&hpdata);
@ -174,7 +174,7 @@ TEST_BEGIN(test_hugify) {
expect_false(hpdata_changing_state_get(&hpdata), "");
/* Hugeifying should have increased the dirty page count. */
expect_zu_eq(HUGEPAGE_PAGES, hpdata_ndirty_get(&hpdata), "");
expect_zu_eq(HUGEPAGE_PAGES, hpdata_ntouched_get(&hpdata), "");
}
TEST_END