remove metadata updater

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2021-04-03 21:29:13 -05:00 committed by Kozlowski Mateusz
parent 953e0f25d7
commit f589341c9a
13 changed files with 25 additions and 457 deletions

View File

@ -159,32 +159,6 @@ static void ctx_cleaner_stop(ocf_cleaner_t c)
{ {
} }
/*
* Initialize metadata updater thread. Metadata updater thread is left
* non-implemented to keep this example as simple as possible.
*/
static int ctx_metadata_updater_init(ocf_metadata_updater_t mu)
{
return 0;
}
/*
* Kick metadata updater thread. Metadata updater thread is left
* non-implemented to keep this example as simple as possible.
*/
static void ctx_metadata_updater_kick(ocf_metadata_updater_t mu)
{
ocf_metadata_updater_run(mu);
}
/*
* Stop metadata updater thread. Metadata updater thread is left
* non-implemented to keep this example as simple as possible.
*/
static void ctx_metadata_updater_stop(ocf_metadata_updater_t mu)
{
}
/* /*
* Function prividing interface for printing to log used by OCF internals. * Function prividing interface for printing to log used by OCF internals.
* It can handle differently messages at varous log levels. * It can handle differently messages at varous log levels.
@ -257,12 +231,6 @@ static const struct ocf_ctx_config ctx_cfg = {
.stop = ctx_cleaner_stop, .stop = ctx_cleaner_stop,
}, },
.metadata_updater = {
.init = ctx_metadata_updater_init,
.kick = ctx_metadata_updater_kick,
.stop = ctx_metadata_updater_stop,
},
.logger = { .logger = {
.print = ctx_logger_print, .print = ctx_logger_print,
.dump_stack = ctx_logger_dump_stack, .dump_stack = ctx_logger_dump_stack,

View File

@ -26,7 +26,6 @@
#include "cleaning/acp.h" #include "cleaning/acp.h"
#include "promotion/nhit.h" #include "promotion/nhit.h"
#include "ocf_metadata.h" #include "ocf_metadata.h"
#include "ocf_metadata_updater.h"
#include "ocf_io_class.h" #include "ocf_io_class.h"
#include "ocf_stats.h" #include "ocf_stats.h"
#include "ocf_mngt.h" #include "ocf_mngt.h"

View File

@ -159,39 +159,15 @@ struct ocf_cleaner_ops {
void (*stop)(ocf_cleaner_t c); void (*stop)(ocf_cleaner_t c);
}; };
/** typedef struct ocf_persistent_meta_zone *ocf_persistent_meta_zone_t;
* @brief Metadata updater operations
*/
struct ocf_metadata_updater_ops {
/**
* @brief Initialize metadata updater.
*
* This function should create worker, thread, timer or any other
* mechanism responsible for calling metadata updater routine.
*
* @param[in] mu Handle to metadata updater to be initialized
*
* @retval 0 Metadata updater has been initializaed successfully
* @retval Non-zero I/O queue initialization failure
*/
int (*init)(ocf_metadata_updater_t mu);
/** struct ocf_persistent_metadata_ops {
* @brief Kick metadata updater processing ocf_persistent_meta_zone_t (*init)(ocf_cache_t cache, size_t size,
* bool *load);
* This function should inform worker, thread or any other mechanism, int (*deinit)(ocf_persistent_meta_zone_t zone);
* that there are new metadata requests to be processed. void *(*alloc)(ocf_persistent_meta_zone_t zone, size_t size,
* int alloc_id, bool *load);
* @param[in] mu Metadata updater to be kicked int (*free)(ocf_persistent_meta_zone_t zone, int alloc_id, void *ptr);
*/
void (*kick)(ocf_metadata_updater_t mu);
/**
* @brief Stop metadata updater
*
* @param[in] mu Metadata updater beeing stopped
*/
void (*stop)(ocf_metadata_updater_t mu);
}; };
/** /**
@ -204,9 +180,6 @@ struct ocf_ctx_ops {
/* Cleaner operations */ /* Cleaner operations */
struct ocf_cleaner_ops cleaner; struct ocf_cleaner_ops cleaner;
/* Metadata updater operations */
struct ocf_metadata_updater_ops metadata_updater;
/* Logger operations */ /* Logger operations */
struct ocf_logger_ops logger; struct ocf_logger_ops logger;
}; };

View File

@ -1,50 +0,0 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_METADATA_UPDATER_H__
#define __OCF_METADATA_UPDATER_H__
/**
* @file
* @brief OCF metadata updater API
*
*/
/**
* @brief Run metadata updater
*
* @param[in] mu Metadata updater instance to run
*
* @retval Hint if there is need to rerun without waiting.
*/
uint32_t ocf_metadata_updater_run(ocf_metadata_updater_t mu);
/**
* @brief Set metadata updater private data
*
* @param[in] c Metadata updater handle
* @param[in] priv Private data
*/
void ocf_metadata_updater_set_priv(ocf_metadata_updater_t mu, void *priv);
/**
* @brief Get metadata updater private data
*
* @param[in] c Metadata updater handle
*
* @retval Metadata updater private data
*/
void *ocf_metadata_updater_get_priv(ocf_metadata_updater_t mu);
/**
* @brief Get cache instance to which metadata updater belongs
*
* @param[in] c Metadata updater handle
*
* @retval Cache instance
*/
ocf_cache_t ocf_metadata_updater_get_cache(ocf_metadata_updater_t mu);
#endif /* __OCF_METADATA_UPDATER_H__ */

View File

@ -301,6 +301,15 @@ static void matadata_io_page_lock_acquired(struct ocf_request *req)
ocf_engine_push_req_front(req, true); ocf_engine_push_req_front(req, true);
} }
void metadata_io_req_finalize(struct metadata_io_request *m_req)
{
struct metadata_io_request_asynch *a_req = m_req->asynch;
if (env_atomic_dec_return(&a_req->req_active) == 0)
env_mpool_del(m_req->cache->owner->resources.mio, a_req,
a_req->alloc_req_count);
}
static void metadata_io_req_submit(struct metadata_io_request *m_req) static void metadata_io_req_submit(struct metadata_io_request *m_req)
{ {
struct metadata_io_request_asynch *a_req = m_req->asynch; struct metadata_io_request_asynch *a_req = m_req->asynch;
@ -311,7 +320,12 @@ static void metadata_io_req_submit(struct metadata_io_request *m_req)
if (a_req->mio_conc) { if (a_req->mio_conc) {
lock = ocf_mio_async_lock(a_req->mio_conc, m_req, lock = ocf_mio_async_lock(a_req->mio_conc, m_req,
matadata_io_page_lock_acquired); matadata_io_page_lock_acquired);
/* TODO: error handling for lock < 0 */
if (lock != OCF_LOCK_ACQUIRED) {
a_req->error = lock;
metadata_io_req_finalize(m_req);
return;
}
} }
if (!a_req->mio_conc || lock == OCF_LOCK_ACQUIRED) if (!a_req->mio_conc || lock == OCF_LOCK_ACQUIRED)
@ -329,15 +343,6 @@ void metadata_io_req_end(struct metadata_io_request *m_req)
ctx_data_free(cache->owner, m_req->data); ctx_data_free(cache->owner, m_req->data);
} }
void metadata_io_req_finalize(struct metadata_io_request *m_req)
{
struct metadata_io_request_asynch *a_req = m_req->asynch;
if (env_atomic_dec_return(&a_req->req_active) == 0)
env_mpool_del(m_req->cache->owner->resources.mio, a_req,
a_req->alloc_req_count);
}
static uint32_t metadata_io_max_page(ocf_cache_t cache) static uint32_t metadata_io_max_page(ocf_cache_t cache)
{ {
uint32_t volume_max_io_pages = ocf_volume_get_max_io_size( uint32_t volume_max_io_pages = ocf_volume_get_max_io_size(

View File

@ -1,163 +0,0 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include "metadata.h"
#include "metadata_io.h"
#include "metadata_updater_priv.h"
#include "../ocf_priv.h"
#include "../engine/engine_common.h"
#include "../ocf_cache_priv.h"
#include "../ocf_ctx_priv.h"
#include "../utils/utils_io.h"
int ocf_metadata_updater_init(ocf_cache_t cache)
{
ocf_metadata_updater_t mu = &cache->metadata_updater;
struct ocf_metadata_io_syncher *syncher = &mu->syncher;
INIT_LIST_HEAD(&syncher->in_progress_head);
INIT_LIST_HEAD(&syncher->pending_head);
env_mutex_init(&syncher->lock);
return ctx_metadata_updater_init(cache->owner, mu);
}
void ocf_metadata_updater_kick(ocf_cache_t cache)
{
ctx_metadata_updater_kick(cache->owner, &cache->metadata_updater);
}
void ocf_metadata_updater_stop(ocf_cache_t cache)
{
ctx_metadata_updater_stop(cache->owner, &cache->metadata_updater);
env_mutex_destroy(&cache->metadata_updater.syncher.lock);
}
void ocf_metadata_updater_set_priv(ocf_metadata_updater_t mu, void *priv)
{
OCF_CHECK_NULL(mu);
mu->priv = priv;
}
void *ocf_metadata_updater_get_priv(ocf_metadata_updater_t mu)
{
OCF_CHECK_NULL(mu);
return mu->priv;
}
ocf_cache_t ocf_metadata_updater_get_cache(ocf_metadata_updater_t mu)
{
OCF_CHECK_NULL(mu);
return container_of(mu, struct ocf_cache, metadata_updater);
}
static int _metadata_updater_iterate_in_progress(ocf_cache_t cache,
struct list_head *finished, struct metadata_io_request *new_req)
{
struct ocf_metadata_io_syncher *syncher =
&cache->metadata_updater.syncher;
struct metadata_io_request *curr, *temp;
list_for_each_entry_safe(curr, temp, &syncher->in_progress_head, list) {
if (env_atomic_read(&curr->finished)) {
list_move_tail(&curr->list, finished);
continue;
}
if (new_req) {
/* If request specified, check if overlap occurs. */
if (ocf_io_overlaps(new_req->page, new_req->count,
curr->page, curr->count)) {
return 1;
}
}
}
return 0;
}
static void metadata_updater_process_finished(struct list_head *finished)
{
struct metadata_io_request *curr, *temp;
list_for_each_entry_safe(curr, temp, finished, list) {
list_del(&curr->list);
metadata_io_req_complete(curr);
}
}
void metadata_updater_submit(struct metadata_io_request *m_req)
{
ocf_cache_t cache = m_req->cache;
struct ocf_metadata_io_syncher *syncher =
&cache->metadata_updater.syncher;
struct list_head finished;
int ret;
INIT_LIST_HEAD(&finished);
env_mutex_lock(&syncher->lock);
ret = _metadata_updater_iterate_in_progress(cache, &finished, m_req);
/* Either add it to in-progress list or pending list for deferred
* execution.
*/
if (ret == 0)
list_add_tail(&m_req->list, &syncher->in_progress_head);
else
list_add_tail(&m_req->list, &syncher->pending_head);
env_mutex_unlock(&syncher->lock);
if (ret == 0)
ocf_engine_push_req_front(&m_req->req, true);
metadata_updater_process_finished(&finished);
}
uint32_t ocf_metadata_updater_run(ocf_metadata_updater_t mu)
{
struct metadata_io_request *curr, *temp;
struct ocf_metadata_io_syncher *syncher;
struct list_head finished;
ocf_cache_t cache;
int ret;
OCF_CHECK_NULL(mu);
INIT_LIST_HEAD(&finished);
cache = ocf_metadata_updater_get_cache(mu);
syncher = &cache->metadata_updater.syncher;
env_mutex_lock(&syncher->lock);
if (list_empty(&syncher->pending_head)) {
/*
* If pending list is empty, we iterate over in progress
* list to free memory used by finished requests.
*/
_metadata_updater_iterate_in_progress(cache, &finished, NULL);
env_mutex_unlock(&syncher->lock);
metadata_updater_process_finished(&finished);
env_cond_resched();
return 0;
}
list_for_each_entry_safe(curr, temp, &syncher->pending_head, list) {
ret = _metadata_updater_iterate_in_progress(cache, &finished, curr);
if (ret == 0) {
/* Move to in-progress list and kick the workers */
list_move_tail(&curr->list, &syncher->in_progress_head);
}
env_mutex_unlock(&syncher->lock);
metadata_updater_process_finished(&finished);
if (ret == 0)
ocf_engine_push_req_front(&curr->req, true);
env_cond_resched();
env_mutex_lock(&syncher->lock);
}
env_mutex_unlock(&syncher->lock);
return 0;
}

View File

@ -1,32 +0,0 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __METADATA_UPDATER_PRIV_H__
#define __METADATA_UPDATER_PRIV_H__
#include "../ocf_def_priv.h"
#include "metadata_io.h"
struct ocf_metadata_updater {
/* Metadata flush synchronizer context */
struct ocf_metadata_io_syncher {
struct list_head in_progress_head;
struct list_head pending_head;
env_mutex lock __attribute__((aligned(64)));
} syncher;
void *priv;
};
void metadata_updater_submit(struct metadata_io_request *m_req);
int ocf_metadata_updater_init(struct ocf_cache *cache);
void ocf_metadata_updater_kick(struct ocf_cache *cache);
void ocf_metadata_updater_stop(struct ocf_cache *cache);
#endif /* __METADATA_UPDATER_PRIV_H__ */

View File

@ -10,6 +10,7 @@
#include "../ocf_core_priv.h" #include "../ocf_core_priv.h"
#include "../ocf_queue_priv.h" #include "../ocf_queue_priv.h"
#include "../metadata/metadata.h" #include "../metadata/metadata.h"
#include "../metadata/metadata_io.h"
#include "../engine/cache_engine.h" #include "../engine/cache_engine.h"
#include "../utils/utils_part.h" #include "../utils/utils_part.h"
#include "../utils/utils_cache_line.h" #include "../utils/utils_cache_line.h"

View File

@ -12,7 +12,6 @@
#include "ocf_core_priv.h" #include "ocf_core_priv.h"
#include "metadata/metadata_structs.h" #include "metadata/metadata_structs.h"
#include "metadata/metadata_partition_structs.h" #include "metadata/metadata_partition_structs.h"
#include "metadata/metadata_updater_priv.h"
#include "utils/utils_list.h" #include "utils/utils_list.h"
#include "utils/utils_pipeline.h" #include "utils/utils_pipeline.h"
#include "utils/utils_refcnt.h" #include "utils/utils_refcnt.h"
@ -114,8 +113,6 @@ struct ocf_cache {
env_atomic flush_in_progress; env_atomic flush_in_progress;
env_mutex flush_mutex; env_mutex flush_mutex;
struct ocf_metadata_updater metadata_updater;
struct ocf_cleaner cleaner; struct ocf_cleaner cleaner;
struct list_head io_queues; struct list_head io_queues;

View File

@ -136,10 +136,6 @@ static void check_ops_provided(const struct ocf_ctx_ops *ops)
ENV_BUG_ON(!ops->cleaner.init); ENV_BUG_ON(!ops->cleaner.init);
ENV_BUG_ON(!ops->cleaner.kick); ENV_BUG_ON(!ops->cleaner.kick);
ENV_BUG_ON(!ops->cleaner.stop); ENV_BUG_ON(!ops->cleaner.stop);
ENV_BUG_ON(!ops->metadata_updater.init);
ENV_BUG_ON(!ops->metadata_updater.kick);
ENV_BUG_ON(!ops->metadata_updater.stop);
} }
/* /*

View File

@ -160,24 +160,6 @@ static inline void ctx_cleaner_kick(ocf_ctx_t ctx, ocf_cleaner_t cleaner)
ctx->ops->cleaner.kick(cleaner); ctx->ops->cleaner.kick(cleaner);
} }
static inline int ctx_metadata_updater_init(ocf_ctx_t ctx,
ocf_metadata_updater_t mu)
{
return ctx->ops->metadata_updater.init(mu);
}
static inline void ctx_metadata_updater_kick(ocf_ctx_t ctx,
ocf_metadata_updater_t mu)
{
ctx->ops->metadata_updater.kick(mu);
}
static inline void ctx_metadata_updater_stop(ocf_ctx_t ctx,
ocf_metadata_updater_t mu)
{
ctx->ops->metadata_updater.stop(mu);
}
/** /**
* @} * @}
*/ */

View File

@ -8,7 +8,6 @@ from ctypes import c_void_p, Structure, c_char_p, cast, pointer, byref, c_int
from .logger import LoggerOps, Logger from .logger import LoggerOps, Logger
from .data import DataOps, Data from .data import DataOps, Data
from .cleaner import CleanerOps, Cleaner from .cleaner import CleanerOps, Cleaner
from .metadata_updater import MetadataUpdaterOps, MetadataUpdater
from .shared import OcfError from .shared import OcfError
from ..ocf import OcfLib from ..ocf import OcfLib
from .queue import Queue from .queue import Queue
@ -19,7 +18,6 @@ class OcfCtxOps(Structure):
_fields_ = [ _fields_ = [
("data", DataOps), ("data", DataOps),
("cleaner", CleanerOps), ("cleaner", CleanerOps),
("metadata_updater", MetadataUpdaterOps),
("logger", LoggerOps), ("logger", LoggerOps),
] ]
@ -29,10 +27,9 @@ class OcfCtxCfg(Structure):
class OcfCtx: class OcfCtx:
def __init__(self, lib, name, logger, data, mu, cleaner): def __init__(self, lib, name, logger, data, cleaner):
self.logger = logger self.logger = logger
self.data = data self.data = data
self.mu = mu
self.cleaner = cleaner self.cleaner = cleaner
self.ctx_handle = c_void_p() self.ctx_handle = c_void_p()
self.lib = lib self.lib = lib
@ -45,7 +42,6 @@ class OcfCtx:
ops=OcfCtxOps( ops=OcfCtxOps(
data=self.data.get_ops(), data=self.data.get_ops(),
cleaner=self.cleaner.get_ops(), cleaner=self.cleaner.get_ops(),
metadata_updater=self.mu.get_ops(),
logger=logger.get_ops(), logger=logger.get_ops(),
), ),
logger_priv=cast(pointer(logger.get_priv()), c_void_p), logger_priv=cast(pointer(logger.get_priv()), c_void_p),
@ -98,7 +94,6 @@ class OcfCtx:
self.cfg = None self.cfg = None
self.logger = None self.logger = None
self.data = None self.data = None
self.mu = None
self.cleaner = None self.cleaner = None
Queue._instances_ = {} Queue._instances_ = {}
Volume._instances_ = {} Volume._instances_ = {}
@ -112,7 +107,6 @@ def get_default_ctx(logger):
b"PyOCF default ctx", b"PyOCF default ctx",
logger, logger,
Data, Data,
MetadataUpdater,
Cleaner, Cleaner,
) )

View File

@ -1,102 +0,0 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
from ctypes import c_void_p, c_int, c_uint32, Structure, CFUNCTYPE
from threading import Thread, Event
from ..ocf import OcfLib
class MetadataUpdaterOps(Structure):
INIT = CFUNCTYPE(c_int, c_void_p)
KICK = CFUNCTYPE(None, c_void_p)
STOP = CFUNCTYPE(None, c_void_p)
_fields_ = [("_init", INIT), ("_kick", KICK), ("_stop", STOP)]
class MetadataUpdater:
pass
def mu_run(*, mu: MetadataUpdater, kick: Event, stop: Event):
while True:
kick.clear()
if OcfLib.getInstance().ocf_metadata_updater_run(mu):
continue
kick.wait()
if stop.is_set():
break
class MetadataUpdater:
_instances_ = {}
ops = None
def __init__(self, ref):
self._as_parameter_ = ref
MetadataUpdater._instances_[ref] = self
self.kick_event = Event()
self.stop_event = Event()
lib = OcfLib.getInstance()
self.thread = Thread(
group=None,
target=mu_run,
name="mu-{}".format(
lib.ocf_cache_get_name(lib.ocf_metadata_updater_get_cache(self))
),
kwargs={"mu": self, "kick": self.kick_event, "stop": self.stop_event},
)
self.thread.start()
@classmethod
def get_ops(cls):
if not cls.ops:
cls.ops = MetadataUpdaterOps(
_init=cls._init, _kick=cls._kick, _stop=cls._stop
)
return cls.ops
@classmethod
def get_instance(cls, ref):
return cls._instances_[ref]
@classmethod
def del_instance(cls, ref):
del cls._instances_[ref]
@staticmethod
@MetadataUpdaterOps.INIT
def _init(ref):
m = MetadataUpdater(ref)
return 0
@staticmethod
@MetadataUpdaterOps.KICK
def _kick(ref):
MetadataUpdater.get_instance(ref).kick()
@staticmethod
@MetadataUpdaterOps.STOP
def _stop(ref):
MetadataUpdater.get_instance(ref).stop()
del MetadataUpdater._instances_[ref]
def kick(self):
self.kick_event.set()
def stop(self):
self.stop_event.set()
self.kick_event.set()
lib = OcfLib.getInstance()
lib.ocf_metadata_updater_get_cache.argtypes = [c_void_p]
lib.ocf_metadata_updater_get_cache.restype = c_void_p
lib.ocf_metadata_updater_run.argtypes = [c_void_p]
lib.ocf_metadata_updater_run.restype = c_uint32