Add promotion policy API and use it in I/O path
Promotion policy is supposed to perform ALRU noise filtering by eliminating one-hit wonders being added to cache and polluting it. Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
36
src/promotion/nhit.c
Normal file
36
src/promotion/nhit.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright(c) 2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#include "../metadata/metadata.h"
|
||||
|
||||
#include "nhit.h"
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nhit_deinit(ocf_promotion_policy_t policy)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
uint64_t param_value)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nhit_req_purge(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool nhit_req_should_promote(ocf_promotion_policy_t policy, struct ocf_request *req)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
26
src/promotion/nhit.h
Normal file
26
src/promotion/nhit.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright(c) 2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef NHIT_PROMOTION_POLICY_H_
|
||||
#define NHIT_PROMOTION_POLICY_H_
|
||||
|
||||
#include "ocf/ocf.h"
|
||||
#include "../ocf_request.h"
|
||||
#include "promotion.h"
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy);
|
||||
|
||||
void nhit_deinit(ocf_promotion_policy_t policy);
|
||||
|
||||
ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
uint64_t param_value);
|
||||
|
||||
void nhit_req_purge(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req);
|
||||
|
||||
bool nhit_req_should_promote(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req);
|
||||
|
||||
#endif /* NHIT_PROMOTION_POLICY_H_ */
|
42
src/promotion/ops.h
Normal file
42
src/promotion/ops.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright(c) 2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef PROMOTION_OPS_H_
|
||||
#define PROMOTION_OPS_H_
|
||||
|
||||
#include "../metadata/metadata.h"
|
||||
#include "promotion.h"
|
||||
|
||||
struct ocf_promotion_policy {
|
||||
ocf_promotion_t type;
|
||||
void *ctx;
|
||||
};
|
||||
|
||||
struct promotion_policy_ops {
|
||||
const char *name;
|
||||
/*!< Promotion policy name */
|
||||
|
||||
ocf_error_t (*init)(ocf_cache_t cache, ocf_promotion_policy_t policy);
|
||||
/*!< Allocate and initialize promotion policy */
|
||||
|
||||
void (*deinit)(ocf_promotion_policy_t policy);
|
||||
/*!< Deinit and free promotion policy */
|
||||
|
||||
ocf_error_t (*set_param)(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
uint64_t param_value);
|
||||
/*!< Set promotion policy parameter */
|
||||
|
||||
void (*req_purge)(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req);
|
||||
/*!< Call when request core lines have been inserted or it is
|
||||
* a discard request */
|
||||
|
||||
bool (*req_should_promote)(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req);
|
||||
/*!< Should request lines be inserted into cache */
|
||||
};
|
||||
|
||||
#endif /* PROMOTION_OPS_H_ */
|
||||
|
99
src/promotion/promotion.c
Normal file
99
src/promotion/promotion.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright(c) 2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#include "../metadata/metadata.h"
|
||||
|
||||
#include "promotion.h"
|
||||
#include "ops.h"
|
||||
#include "nhit.h"
|
||||
|
||||
struct promotion_policy_ops ocf_promotion_policies[ocf_promotion_max] = {
|
||||
[ocf_promotion_nop] = {
|
||||
.name = "nop",
|
||||
},
|
||||
[ocf_promotion_nhit] = {
|
||||
.name = "nhit",
|
||||
.init = nhit_init,
|
||||
.deinit = nhit_deinit,
|
||||
.set_param = nhit_set_param,
|
||||
.req_purge = nhit_req_purge,
|
||||
.req_should_promote = nhit_req_should_promote,
|
||||
},
|
||||
};
|
||||
|
||||
ocf_error_t ocf_promotion_init(ocf_cache_t cache, ocf_promotion_policy_t *policy)
|
||||
{
|
||||
ocf_promotion_t type = cache->conf_meta->promotion_policy_type;
|
||||
ocf_error_t result = 0;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
*policy = env_vmalloc(sizeof(**policy));
|
||||
if (!*policy)
|
||||
return -OCF_ERR_NO_MEM;
|
||||
|
||||
(*policy)->type = type;
|
||||
|
||||
if (ocf_promotion_policies[type].init)
|
||||
result = ocf_promotion_policies[type].init(cache, *policy);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ocf_promotion_deinit(ocf_promotion_policy_t policy)
|
||||
{
|
||||
ocf_promotion_t type = policy->type;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
if (ocf_promotion_policies[type].deinit)
|
||||
ocf_promotion_policies[type].deinit(policy);
|
||||
|
||||
env_vfree(policy);
|
||||
}
|
||||
|
||||
ocf_error_t ocf_promotion_set_param(ocf_promotion_policy_t policy,
|
||||
uint8_t param_id, uint64_t param_value)
|
||||
{
|
||||
ocf_promotion_t type = policy->type;
|
||||
ocf_error_t result = 0;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
if (ocf_promotion_policies[type].set_param) {
|
||||
result = ocf_promotion_policies[type].set_param(policy, param_id,
|
||||
param_value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ocf_promotion_req_purge(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req)
|
||||
{
|
||||
ocf_promotion_t type = policy->type;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
if (ocf_promotion_policies[type].req_purge)
|
||||
ocf_promotion_policies[type].req_purge(policy, req);
|
||||
}
|
||||
|
||||
bool ocf_promotion_req_should_promote(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req)
|
||||
{
|
||||
ocf_promotion_t type = policy->type;
|
||||
bool result = true;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
if (ocf_promotion_policies[type].req_should_promote) {
|
||||
result = ocf_promotion_policies[type].req_should_promote(policy,
|
||||
req);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
69
src/promotion/promotion.h
Normal file
69
src/promotion/promotion.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright(c) 2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef PROMOTION_H_
|
||||
#define PROMOTION_H_
|
||||
|
||||
#include "ocf/ocf.h"
|
||||
#include "../ocf_request.h"
|
||||
|
||||
typedef struct ocf_promotion_policy *ocf_promotion_policy_t;
|
||||
/**
|
||||
* @brief Allocate and initialize promotion policy. Should be called after cache
|
||||
* metadata has been allocated and cache->conf_meta->promotion_policy_type has
|
||||
* been set.
|
||||
*
|
||||
* @param[in] cache OCF cache instance
|
||||
* @param[out] param initialized policy handle
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_init(ocf_cache_t cache, ocf_promotion_policy_t *policy);
|
||||
|
||||
/**
|
||||
* @brief Stop, deinitialize and free promotion policy structures.
|
||||
*
|
||||
* @param[in] policy promotion policy handle
|
||||
*
|
||||
* @retval none
|
||||
*/
|
||||
void ocf_promotion_deinit(ocf_promotion_policy_t policy);
|
||||
|
||||
/**
|
||||
* @brief Set promotion policy parameter
|
||||
*
|
||||
* @param[in] policy promotion policy handle
|
||||
* @param[in] param_id id of parameter to be set
|
||||
* @param[in] param_value value of parameter to be set
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_set_param(ocf_promotion_policy_t policy,
|
||||
uint8_t param_id, uint64_t param_value);
|
||||
|
||||
/**
|
||||
* @brief Update promotion policy after cache lines have been promoted to cache
|
||||
* or discarded from core device
|
||||
*
|
||||
* @param[in] policy promotion policy handle
|
||||
* @param[in] req OCF request to be purged
|
||||
*
|
||||
* @retval none
|
||||
*/
|
||||
void ocf_promotion_req_purge(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req);
|
||||
|
||||
/**
|
||||
* @brief Check in promotion policy whether core lines in request can be promoted
|
||||
*
|
||||
* @param[in] policy promotion policy handle
|
||||
* @param[in] req OCF request which is to be promoted
|
||||
*
|
||||
* @retval should core lines belonging to this request be promoted
|
||||
*/
|
||||
bool ocf_promotion_req_should_promote(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req);
|
||||
|
||||
#endif /* PROMOTION_H_ */
|
Reference in New Issue
Block a user