Combine cache ref counter and valid flag into ocf_refcnt
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
parent
4251cc63e7
commit
aafc067fa5
@ -561,7 +561,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cachemng_init_params *params)
|
|||||||
|
|
||||||
INIT_LIST_HEAD(&cache->list);
|
INIT_LIST_HEAD(&cache->list);
|
||||||
list_add_tail(&cache->list, ¶ms->ctx->caches);
|
list_add_tail(&cache->list, ¶ms->ctx->caches);
|
||||||
env_atomic_set(&cache->ref_count, 1);
|
ocf_refcnt_inc(&cache->refcnt.cache);
|
||||||
cache->owner = params->ctx;
|
cache->owner = params->ctx;
|
||||||
|
|
||||||
/* start with freezed metadata ref counter to indicate detached device*/
|
/* start with freezed metadata ref counter to indicate detached device*/
|
||||||
@ -1221,7 +1221,7 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
|
|||||||
cache_unlock convention. User is expected to call
|
cache_unlock convention. User is expected to call
|
||||||
ocf_mngt_cache_unlock in future which would up the
|
ocf_mngt_cache_unlock in future which would up the
|
||||||
semaphore as well as decrement ref_count. */
|
semaphore as well as decrement ref_count. */
|
||||||
env_atomic_inc(&(*cache)->ref_count);
|
ocf_refcnt_inc(&(*cache)->refcnt.cache);
|
||||||
} else {
|
} else {
|
||||||
/* User did not request to lock cache instance after creation -
|
/* User did not request to lock cache instance after creation -
|
||||||
up the semaphore here since we have acquired the lock to
|
up the semaphore here since we have acquired the lock to
|
||||||
@ -1244,7 +1244,6 @@ static void _ocf_mng_cache_set_valid(ocf_cache_t cache)
|
|||||||
* Clear initialization state and set the valid bit so we know
|
* Clear initialization state and set the valid bit so we know
|
||||||
* its in use.
|
* its in use.
|
||||||
*/
|
*/
|
||||||
cache->valid_ocf_cache_device_t = 1;
|
|
||||||
env_bit_clear(ocf_cache_state_initializing, &cache->cache_state);
|
env_bit_clear(ocf_cache_state_initializing, &cache->cache_state);
|
||||||
env_bit_set(ocf_cache_state_running, &cache->cache_state);
|
env_bit_set(ocf_cache_state_running, &cache->cache_state);
|
||||||
}
|
}
|
||||||
@ -2000,7 +1999,7 @@ static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline,
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
env_mutex_lock(&ctx->lock);
|
env_mutex_lock(&ctx->lock);
|
||||||
/* Mark device uninitialized */
|
/* Mark device uninitialized */
|
||||||
cache->valid_ocf_cache_device_t = 0;
|
ocf_refcnt_freeze(&cache->refcnt.cache);
|
||||||
/* Remove cache from the list */
|
/* Remove cache from the list */
|
||||||
list_del(&cache->list);
|
list_del(&cache->list);
|
||||||
env_mutex_unlock(&ctx->lock);
|
env_mutex_unlock(&ctx->lock);
|
||||||
|
@ -121,7 +121,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache)
|
|||||||
{
|
{
|
||||||
OCF_CHECK_NULL(cache);
|
OCF_CHECK_NULL(cache);
|
||||||
|
|
||||||
if (env_atomic_dec_return(&cache->ref_count) == 0) {
|
if (ocf_refcnt_dec(&cache->refcnt.cache) == 0) {
|
||||||
ocf_metadata_deinit(cache);
|
ocf_metadata_deinit(cache);
|
||||||
env_vfree(cache);
|
env_vfree(cache);
|
||||||
}
|
}
|
||||||
@ -155,10 +155,7 @@ int ocf_mngt_cache_get_by_id(ocf_ctx_t ocf_ctx, ocf_cache_id_t id, ocf_cache_t *
|
|||||||
|
|
||||||
if (instance) {
|
if (instance) {
|
||||||
/* if cache is either fully initialized or during recovery */
|
/* if cache is either fully initialized or during recovery */
|
||||||
if (instance->valid_ocf_cache_device_t) {
|
if (!ocf_refcnt_inc(&instance->refcnt.cache)) {
|
||||||
/* Increase reference counter */
|
|
||||||
env_atomic_inc(&instance->ref_count);
|
|
||||||
} else {
|
|
||||||
/* Cache not initialized yet */
|
/* Cache not initialized yet */
|
||||||
instance = NULL;
|
instance = NULL;
|
||||||
}
|
}
|
||||||
@ -210,7 +207,8 @@ static int _ocf_mngt_cache_lock(ocf_cache_t cache, int (*lock_fn)(env_rwsem *s),
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Increment reference counter */
|
/* Increment reference counter */
|
||||||
env_atomic_inc(&cache->ref_count);
|
if (!ocf_refcnt_inc(&cache->refcnt.cache))
|
||||||
|
return -OCF_ERR_CACHE_NOT_EXIST;
|
||||||
|
|
||||||
env_atomic_inc(&cache->lock_waiter);
|
env_atomic_inc(&cache->lock_waiter);
|
||||||
ret = lock_fn(&cache->lock);
|
ret = lock_fn(&cache->lock);
|
||||||
@ -266,13 +264,7 @@ int ocf_mngt_cache_read_trylock(ocf_cache_t cache)
|
|||||||
/* if cache is either fully initialized or during recovery */
|
/* if cache is either fully initialized or during recovery */
|
||||||
static bool _ocf_mngt_cache_try_get(ocf_cache_t cache)
|
static bool _ocf_mngt_cache_try_get(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
if (!!cache->valid_ocf_cache_device_t) {
|
return !!ocf_refcnt_inc(&cache->refcnt.cache);
|
||||||
/* Increase reference counter */
|
|
||||||
env_atomic_inc(&cache->ref_count);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ocf_mngt_cache_get(ocf_cache_t cache)
|
int ocf_mngt_cache_get(ocf_cache_t cache)
|
||||||
|
@ -146,13 +146,10 @@ struct ocf_cache {
|
|||||||
ocf_ctx_t owner;
|
ocf_ctx_t owner;
|
||||||
|
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
/* set to make valid */
|
|
||||||
uint8_t valid_ocf_cache_device_t;
|
|
||||||
/* unset running to not serve any more I/O requests */
|
/* unset running to not serve any more I/O requests */
|
||||||
unsigned long cache_state;
|
unsigned long cache_state;
|
||||||
|
|
||||||
env_atomic ref_count;
|
|
||||||
|
|
||||||
struct ocf_superblock_config *conf_meta;
|
struct ocf_superblock_config *conf_meta;
|
||||||
|
|
||||||
struct ocf_cache_device *device;
|
struct ocf_cache_device *device;
|
||||||
@ -169,8 +166,14 @@ struct ocf_cache {
|
|||||||
char name[OCF_CACHE_NAME_SIZE];
|
char name[OCF_CACHE_NAME_SIZE];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
/* cache get/put counter */
|
||||||
|
struct ocf_refcnt cache;
|
||||||
|
/* # of requests potentially dirtying cachelines */
|
||||||
struct ocf_refcnt dirty;
|
struct ocf_refcnt dirty;
|
||||||
|
/* # of requests accessing attached metadata, excluding
|
||||||
|
* management reqs */
|
||||||
struct ocf_refcnt metadata;
|
struct ocf_refcnt metadata;
|
||||||
|
/* # of forced cleaning requests (eviction path) */
|
||||||
struct ocf_refcnt cleaning[OCF_IO_CLASS_MAX];
|
struct ocf_refcnt cleaning[OCF_IO_CLASS_MAX];
|
||||||
} refcnt;
|
} refcnt;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user