Пример #1
0
//test lru_front and lru_remove
static void test_lru(struct lruhash *table)
{
    testkey *k1 = newkey(12);
    testkey *k2 = newkey(14);
    lock_basic_lock(&table->lock);

    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);
    lru_remove(table, &k1->entry);
    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);

    //add one
    lru_front(table, &k1->entry);
    unit_assert( table->lru_head == &k1->entry && table->lru_tail == &k1->entry);

    //remove
    lru_remove(table, &k1->entry);
    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);

    //add two
    lru_front(table, &k1->entry);
    unit_assert(table->lru_head == &k1->entry &&
                table->lru_tail == &k1->entry);
    lru_front(table, &k2->entry);
    unit_assert(table->lru_head == &k2->entry &&
                table->lru_tail == &k1->entry);

    //remove first
    lru_remove(table, &k2->entry);
    unit_assert(table->lru_head == &k1->entry &&
                table->lru_tail == &k1->entry);
    lru_front(table, &k2->entry);
    unit_assert(table->lru_head == &k2->entry &&
                table->lru_tail == &k1->entry);

    //remove last
    lru_remove(table, &k1->entry);
    unit_assert(table->lru_head == &k2->entry &&
                table->lru_tail == &k2->entry);

    //empty
    lru_remove(table, &k2->entry);
    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);

    lock_basic_unlock(&table->lock);

    delkey(k1);
    delkey(k2);
}
Пример #2
0
static void cacheset_add(struct cache_set *map, unsigned char *md5, size_t size, mpool_t *mempool)
{
    int ret;
    uint32_t pos;
    struct cache_key *newkey;

    if (map->elements >= map->maxelements) {
	cacheset_lru_remove(map, 1);
	if (map->deleted >= map->maxdeleted) {
	    cacheset_rehash(map, mempool);
	}
    }
    assert(map->elements < map->maxelements);

    ret = cacheset_lookup_internal(map, md5, size, &pos, 1);
    newkey = &map->data[pos];
    if (newkey->size == CACHE_KEY_DELETED)
	map->deleted--;
    if (ret) {
	/* was already added, remove from LRU list */
	lru_remove(map, newkey);
    }
    /* add new key to tail of LRU list */
    memcpy(&map->data[pos].digest, md5, sizeof(map->data[pos].digest));
    map->data[pos].size = size;
    lru_addtail(map, newkey);

    map->elements++;

    assert(pos < map->maxelements);
}
Пример #3
0
void lruhash_remove(struct lruhash *table, hashvalue_t hash, void *key)
{
    struct lruhash_entry *entry;
    struct lruhash_bucket *bucket;
    void *d;

    lock_basic_lock(&table->lock);
    bucket = &table->array[hash & table->size_mask];
    if((entry=bucket_find_entry(table, bucket, hash, key))) {
        bucket_overflow_remove(bucket, entry);
        lru_remove(table, entry);
    } else {
        lock_basic_unlock(&table->lock);
        return;
    }

    table->num--;
    lock_basic_lock(&entry->lock);
    table->space_used -= (*table->sizefunc)(entry->key, entry->data);
    lock_basic_unlock(&entry->lock);
    lock_basic_unlock(&table->lock);

    //del key data
    d = entry->data;
    (*table->delkeyfunc)(entry->key);
    (*table->deldatafunc)(d);
}
Пример #4
0
static void lru_touch(struct lruhash *table, struct lruhash_entry *entry)
{
    if(entry == table->lru_head)
        return;
    //move to front
    lru_remove(table, entry);
    lru_front(table, entry);
}
Пример #5
0
 void trim_cache(list<VPtr> *to_release)
 {
     while (size > max_size)
     {
         to_release->push_back(lru.back().second);
         lru_remove(lru.back().first);
     }
 }
Пример #6
0
static inline int
lru_popback(void) {
    if (likely(blk_cache->lru_tail) != INVALID_LRU_IDX) {
        lru_remove(blk_cache->lru_tail);
        return 1;
    }
    ASSERT(blk_cache->lru_hdr == INVALID_LRU_IDX);
    return 0;
}
/** test lru_front lru_remove */
static void test_lru(struct lruhash* table)
{
	testkey_t* k = newkey(12);
	testkey_t* k2 = newkey(14);
	lock_quick_lock(&table->lock);

	unit_assert( table->lru_start == NULL && table->lru_end == NULL);
	lru_remove(table, &k->entry);
	unit_assert( table->lru_start == NULL && table->lru_end == NULL);

	/* add one */
	lru_front(table, &k->entry);
	unit_assert( table->lru_start == &k->entry && 
		table->lru_end == &k->entry);
	/* remove it */
	lru_remove(table, &k->entry);
	unit_assert( table->lru_start == NULL && table->lru_end == NULL);

	/* add two */
	lru_front(table, &k->entry);
	unit_assert( table->lru_start == &k->entry && 
		table->lru_end == &k->entry);
	lru_front(table, &k2->entry);
	unit_assert( table->lru_start == &k2->entry && 
		table->lru_end == &k->entry);
	/* remove first in list */
	lru_remove(table, &k2->entry);
	unit_assert( table->lru_start == &k->entry && 
		table->lru_end == &k->entry);
	lru_front(table, &k2->entry);
	unit_assert( table->lru_start == &k2->entry && 
		table->lru_end == &k->entry);
	/* remove last in list */
	lru_remove(table, &k->entry);
	unit_assert( table->lru_start == &k2->entry && 
		table->lru_end == &k2->entry);

	/* empty the list */
	lru_remove(table, &k2->entry);
	unit_assert( table->lru_start == NULL && table->lru_end == NULL);
	lock_quick_unlock(&table->lock);
	delkey(k);
	delkey(k2);
}
Пример #8
0
  void clear(const K& key) {
    VPtr val; // release any ref we have after we drop the lock
    {
      Mutex::Locker l(lock);
      if (weak_refs.count(key)) {
	val = weak_refs[key].lock();
      }
      lru_remove(key);
    }
  }
Пример #9
0
  void clear(const K& key) {
    VPtr val; // release any ref we have after we drop the lock
    {
      Mutex::Locker l(lock);
      typename map<K, pair<WeakVPtr, V*>, C>::iterator i = weak_refs.find(key);
      if (i != weak_refs.end()) {
	val = i->second.first.lock();
      }
      lru_remove(key);
    }
  }
Пример #10
0
  //clear all strong reference from the lru.
  void clear() {
    while (true) {
      VPtr val; // release any ref we have after we drop the lock
      Mutex::Locker l(lock);
      if (size == 0)
        break;

      val = lru.back().second;
      lru_remove(lru.back().first);
    }
  }
Пример #11
0
static int cacheset_lookup(struct cache_set *map, unsigned char *md5, size_t size)
{
    struct cache_key *newkey;
    int ret;
    uint32_t pos;

    ret = cacheset_lookup_internal(map, md5, size, &pos, 0);
    if (!ret)
	return 0;
    newkey = &map->data[pos];
    /* update LRU position: move to tail */
    lru_remove(map, newkey);
    lru_addtail(map, newkey);
    return 1;
}
Пример #12
0
static void cacheset_remove(struct cache_set *map, unsigned char *md5, size_t size, mpool_t *mempool)
{
    int ret;
    uint32_t pos;
    struct cache_key *newkey;
    ret = cacheset_lookup_internal(map, md5, size, &pos, 1);
    newkey = &map->data[pos];
    if (!ret || (newkey->size == CACHE_KEY_DELETED)) {
        /* already deleted */
        return;
    }
    /* remove from list */
    lru_remove(map, newkey);
    newkey->size = CACHE_KEY_DELETED;
    map->deleted++;
    map->elements--;
    if (map->deleted >= map->maxdeleted) {
        cacheset_rehash(map, mempool);
    }
}
Пример #13
0
int
bc_remove_block(page_idx_t start_page, int order, int zap_page) {
    if (zap_page) {
        char* p = get_page_addr(start_page);
        size_t len = ((size_t)(1 << order)) << alloc_info->page_size_log2;
        madvise(p, len, MADV_DONTDUMP|MADV_DONTNEED);
    }

    if (!blk_cache_init || !enable_blk_cache)
        return 0;

    intptr_t idx;
    if (!rbt_delete(blk_cache->blks, start_page, &idx))
        return 0;

    ASSERT(blk_cache->lru_v[idx].order == order);
    blk_cache->total_page_num -= (1 << order);
    ASSERT(blk_cache->total_page_num >= 0);

    lru_remove(idx);

    return 1;
}
Пример #14
0
void object_cache_invalidate(u64 oid) {
    if (objectroot == NULL)
        return;
    lru_remove(object_cache_status, &oid);
}
Пример #15
0
static void lease_clear_dir_cache(Lease *lease) {
    List *allblocks = hash_tolist(lease->dir_cache);

    for ( ; !null(allblocks); allblocks = cdr(allblocks))
        lru_remove(dir_cache, car(allblocks));
}