Skip to content

Commit

Permalink
Rename extent_discard (from hard_evict_extent) (vmware#526)
Browse files Browse the repository at this point in the history
* rename cache_claim to cache_try_claim

* format fixall

* rename extent_discard from hard_evict_extent

Co-authored-by: Jon Howell <[email protected]>
  • Loading branch information
jonhnet and Jon Howell authored Jan 6, 2023
1 parent 864c31a commit 2b4ecf0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ typedef uint64 (*cache_generic_uint64_fn)(cache *cc);
typedef void (*page_generic_fn)(cache *cc, page_handle *page);

typedef page_handle *(*page_alloc_fn)(cache *cc, uint64 addr, page_type type);
typedef void (*extent_hard_evict_fn)(cache *cc, uint64 addr, page_type type);
typedef void (*extent_discard_fn)(cache *cc, uint64 addr, page_type type);
typedef page_handle *(*page_get_fn)(cache *cc,
uint64 addr,
bool blocking,
Expand Down Expand Up @@ -174,7 +174,7 @@ typedef void (*cache_print_fn)(platform_log_handle *log_handle, cache *cc);
*/
typedef struct cache_ops {
page_alloc_fn page_alloc;
extent_hard_evict_fn extent_hard_evict;
extent_discard_fn extent_discard;
page_get_fn page_get;
page_get_async_fn page_get_async;
page_async_done_fn page_async_done;
Expand Down Expand Up @@ -242,7 +242,7 @@ cache_alloc(cache *cc, uint64 addr, page_type type)

/*
*----------------------------------------------------------------------
* cache_hard_evict_extent
* cache_extent_discard
*
* Evicts all the pages in the extent. Dirty pages are discarded.
* This call may block on I/O (to complete writebacks initiated before
Expand All @@ -257,9 +257,9 @@ cache_alloc(cache *cc, uint64 addr, page_type type)
*----------------------------------------------------------------------
*/
static inline void
cache_hard_evict_extent(cache *cc, uint64 addr, page_type type)
cache_extent_discard(cache *cc, uint64 addr, page_type type)
{
cc->ops->extent_hard_evict(cc, addr, type);
cc->ops->extent_discard(cc, addr, type);
}

/*
Expand Down
22 changes: 11 additions & 11 deletions src/clockcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ page_handle *
clockcache_alloc(clockcache *cc, uint64 addr, page_type type);

void
clockcache_hard_evict_extent(clockcache *cc, uint64 addr, page_type type);
clockcache_extent_discard(clockcache *cc, uint64 addr, page_type type);

uint8
clockcache_get_allocator_ref(clockcache *cc, uint64 addr);
Expand Down Expand Up @@ -282,10 +282,10 @@ clockcache_alloc_virtual(cache *c, uint64 addr, page_type type)
}

void
clockcache_hard_evict_extent_virtual(cache *c, uint64 addr, page_type type)
clockcache_extent_discard_virtual(cache *c, uint64 addr, page_type type)
{
clockcache *cc = (clockcache *)c;
return clockcache_hard_evict_extent(cc, addr, type);
return clockcache_extent_discard(cc, addr, type);
}

page_handle *
Expand Down Expand Up @@ -506,7 +506,7 @@ clockcache_get_config_virtual(const cache *c)

static cache_ops clockcache_ops = {
.page_alloc = clockcache_alloc_virtual,
.extent_hard_evict = clockcache_hard_evict_extent_virtual,
.extent_discard = clockcache_extent_discard_virtual,
.page_get = clockcache_get_virtual,
.page_get_async = clockcache_get_async_virtual,
.page_async_done = clockcache_async_done_virtual,
Expand Down Expand Up @@ -1923,21 +1923,21 @@ clockcache_alloc(clockcache *cc, uint64 addr, page_type type)

/*
*----------------------------------------------------------------------
* clockcache_try_hard_evict --
* clockcache_try_page_discard --
*
* Evicts the page with address addr if it is in cache.
*----------------------------------------------------------------------
*/
void
clockcache_try_hard_evict(clockcache *cc, uint64 addr)
clockcache_try_page_discard(clockcache *cc, uint64 addr)
{
const threadid tid = platform_get_tid();
while (TRUE) {
uint32 entry_number = clockcache_lookup(cc, addr);
if (entry_number == CC_UNMAPPED_ENTRY) {
clockcache_log(addr,
entry_number,
"try_hard_evict (uncached): entry %u addr %lu\n",
"try_discard_page (uncached): entry %u addr %lu\n",
entry_number,
addr);
return;
Expand Down Expand Up @@ -1986,7 +1986,7 @@ clockcache_try_hard_evict(clockcache *cc, uint64 addr)
/* log only after steps that can fail */
clockcache_log(addr,
entry_number,
"try_hard_evict (cached): entry %u addr %lu\n",
"try_discard_page (cached): entry %u addr %lu\n",
entry_number,
addr);

Expand All @@ -2013,22 +2013,22 @@ clockcache_try_hard_evict(clockcache *cc, uint64 addr)

/*
*----------------------------------------------------------------------
* clockcache_hard_evict_extent --
* clockcache_extent_discard --
*
* Attempts to evict all the pages in the extent. Will wait for writeback,
* but will evict and discard dirty pages.
*----------------------------------------------------------------------
*/
void
clockcache_hard_evict_extent(clockcache *cc, uint64 addr, page_type type)
clockcache_extent_discard(clockcache *cc, uint64 addr, page_type type)
{
debug_assert(addr % clockcache_extent_size(cc) == 0);
debug_assert(allocator_get_refcount(cc->al, addr) == 1);

clockcache_log(addr, 0, "hard evict extent: addr %lu\n", addr);
for (uint64 i = 0; i < cc->cfg->pages_per_extent; i++) {
uint64 page_addr = addr + clockcache_multiply_by_page_size(cc, i);
clockcache_try_hard_evict(cc, page_addr);
clockcache_try_page_discard(cc, page_addr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/memtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ memtable_context_destroy(platform_heap_id hid, memtable_context *ctxt)
uint8 ref =
allocator_dec_ref(al, ctxt->insert_lock_addr, PAGE_TYPE_LOCK_NO_DATA);
platform_assert(ref == AL_NO_REFS);
cache_hard_evict_extent(cc, ctxt->insert_lock_addr, PAGE_TYPE_LOCK_NO_DATA);
cache_extent_discard(cc, ctxt->insert_lock_addr, PAGE_TYPE_LOCK_NO_DATA);
ref = allocator_dec_ref(al, ctxt->insert_lock_addr, PAGE_TYPE_LOCK_NO_DATA);
platform_assert(ref == AL_FREE);

Expand Down
6 changes: 3 additions & 3 deletions src/mini_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ mini_deinit(cache *cc, uint64 meta_head, page_type type, bool pinned)
uint64 last_meta_base_addr = base_addr(cc, last_meta_addr);
uint8 ref = allocator_dec_ref(al, last_meta_base_addr, type);
platform_assert(ref == AL_NO_REFS);
cache_hard_evict_extent(cc, last_meta_base_addr, type);
cache_extent_discard(cc, last_meta_base_addr, type);
ref = allocator_dec_ref(al, last_meta_base_addr, type);
platform_assert(ref == AL_FREE);
}
Expand Down Expand Up @@ -1013,7 +1013,7 @@ mini_dealloc_extent(cache *cc, page_type type, uint64 base_addr, void *out)
allocator *al = cache_get_allocator(cc);
uint8 ref = allocator_dec_ref(al, base_addr, type);
platform_assert(ref == AL_NO_REFS);
cache_hard_evict_extent(cc, base_addr, type);
cache_extent_discard(cc, base_addr, type);
ref = allocator_dec_ref(al, base_addr, type);
platform_assert(ref == AL_FREE);
return TRUE;
Expand Down Expand Up @@ -1112,7 +1112,7 @@ mini_keyed_dec_ref_extent(cache *cc,
allocator *al = cache_get_allocator(cc);
uint8 ref = allocator_dec_ref(al, base_addr, type);
if (ref == AL_NO_REFS) {
cache_hard_evict_extent(cc, base_addr, type);
cache_extent_discard(cc, base_addr, type);
ref = allocator_dec_ref(al, base_addr, type);
platform_assert(ref == AL_FREE);
return TRUE;
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/cache_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ test_cache_basic(cache *cc, clockcache_config *cfg, platform_heap_id hid)
allocator *al = cache_get_allocator(cc);
uint8 ref = allocator_dec_ref(al, addr, PAGE_TYPE_MISC);
platform_assert(ref == AL_NO_REFS);
cache_hard_evict_extent(cc, addr, PAGE_TYPE_MISC);
cache_extent_discard(cc, addr, PAGE_TYPE_MISC);
ref = allocator_dec_ref(al, addr, PAGE_TYPE_MISC);
platform_assert(ref == AL_FREE);
}
Expand Down Expand Up @@ -548,7 +548,7 @@ test_cache_flush(cache *cc,
allocator *al = cache_get_allocator(cc);
uint8 ref = allocator_dec_ref(al, addr, PAGE_TYPE_MISC);
platform_assert(ref == AL_NO_REFS);
cache_hard_evict_extent(cc, addr, PAGE_TYPE_MISC);
cache_extent_discard(cc, addr, PAGE_TYPE_MISC);
ref = allocator_dec_ref(al, addr, PAGE_TYPE_MISC);
platform_assert(ref == AL_FREE);
}
Expand Down Expand Up @@ -934,7 +934,7 @@ test_cache_async(cache *cc,
allocator *al = cache_get_allocator(cc);
uint8 ref = allocator_dec_ref(al, addr, PAGE_TYPE_MISC);
platform_assert(ref == AL_NO_REFS);
cache_hard_evict_extent(cc, addr, PAGE_TYPE_MISC);
cache_extent_discard(cc, addr, PAGE_TYPE_MISC);
ref = allocator_dec_ref(al, addr, PAGE_TYPE_MISC);
platform_assert(ref == AL_FREE);
}
Expand Down

0 comments on commit 2b4ecf0

Please sign in to comment.