From dc886e5608d553ff2b8f2538cb8d6595bc90e9ac Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Sun, 6 Dec 2020 13:16:51 -0800 Subject: [PATCH] hpdata: Return the number of pages to be purged. We'll use this in the next commit. --- include/jemalloc/internal/hpdata.h | 5 ++++- src/hpdata.c | 7 +++++-- test/unit/hpdata.c | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/jemalloc/internal/hpdata.h b/include/jemalloc/internal/hpdata.h index feca5f5e..30dd6721 100644 --- a/include/jemalloc/internal/hpdata.h +++ b/include/jemalloc/internal/hpdata.h @@ -363,8 +363,11 @@ struct hpdata_purge_state_s { * Once you begin purging, you have to follow through and call hpdata_purge_next * until you're done, and then end. Allocating out of an hpdata undergoing * purging is not allowed. + * + * Returns the number of pages that will be purged. */ -void hpdata_purge_begin(hpdata_t *hpdata, hpdata_purge_state_t *purge_state); +size_t hpdata_purge_begin(hpdata_t *hpdata, hpdata_purge_state_t *purge_state); + /* * If there are more extents to purge, sets *r_purge_addr and *r_purge_size to * true, and returns true. Otherwise, returns false to indicate that we're diff --git a/src/hpdata.c b/src/hpdata.c index bb4808aa..e11ba8d9 100644 --- a/src/hpdata.c +++ b/src/hpdata.c @@ -158,7 +158,7 @@ hpdata_unreserve(hpdata_t *hpdata, void *addr, size_t sz) { hpdata_assert_consistent(hpdata); } -void +size_t hpdata_purge_begin(hpdata_t *hpdata, hpdata_purge_state_t *purge_state) { hpdata_assert_consistent(hpdata); /* See the comment in reserve. */ @@ -181,10 +181,13 @@ hpdata_purge_begin(hpdata_t *hpdata, hpdata_purge_state_t *purge_state) { hpdata->touched_pages, HUGEPAGE_PAGES); /* We purge everything we can. */ - assert(hpdata->h_ntouched - hpdata->h_nactive == fb_scount( + size_t to_purge = hpdata->h_ntouched - hpdata->h_nactive; + assert(to_purge == fb_scount( purge_state->to_purge, HUGEPAGE_PAGES, 0, HUGEPAGE_PAGES)); hpdata_assert_consistent(hpdata); + + return to_purge; } bool diff --git a/test/unit/hpdata.c b/test/unit/hpdata.c index 2a702338..11bccc58 100644 --- a/test/unit/hpdata.c +++ b/test/unit/hpdata.c @@ -68,7 +68,8 @@ TEST_BEGIN(test_purge_simple) { expect_zu_eq(hpdata_ntouched_get(&hpdata), HUGEPAGE_PAGES / 2, ""); hpdata_purge_state_t purge_state; - hpdata_purge_begin(&hpdata, &purge_state); + size_t to_purge = hpdata_purge_begin(&hpdata, &purge_state); + expect_zu_eq(HUGEPAGE_PAGES / 4, to_purge, ""); void *purge_addr; size_t purge_size; @@ -112,7 +113,8 @@ TEST_BEGIN(test_purge_intervening_dalloc) { expect_zu_eq(hpdata_ntouched_get(&hpdata), 3 * HUGEPAGE_PAGES / 4, ""); hpdata_purge_state_t purge_state; - hpdata_purge_begin(&hpdata, &purge_state); + size_t to_purge = hpdata_purge_begin(&hpdata, &purge_state); + expect_zu_eq(HUGEPAGE_PAGES / 2, to_purge, ""); void *purge_addr; size_t purge_size;