Merge pull request #476 from mmkayPL/cacheline-alignment

Cacheline alignment
This commit is contained in:
Michał Mielewczyk 2021-03-26 12:01:55 +01:00 committed by GitHub
commit c2e588be9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 118 additions and 112 deletions

View File

@ -27,6 +27,9 @@ struct ocf_cache_info {
uint8_t volume_type; uint8_t volume_type;
/*!< Cache volume type */ /*!< Cache volume type */
uint8_t state;
/*!< Cache state (running/flushing/stopping etc...) */
uint32_t size; uint32_t size;
/*!< Actual cache size (in cache lines) */ /*!< Actual cache size (in cache lines) */
@ -69,9 +72,6 @@ struct ocf_cache_info {
set as a result of reaching IO error threshold */ set as a result of reaching IO error threshold */
} fallback_pt; } fallback_pt;
uint8_t state;
/*!< Cache state (running/flushing/stopping etc...) */
ocf_eviction_t eviction_policy; ocf_eviction_t eviction_policy;
/*!< Eviction policy selected */ /*!< Eviction policy selected */

View File

@ -83,16 +83,6 @@ struct ocf_io {
*/ */
ocf_start_io_t start; ocf_start_io_t start;
/**
* @brief OCF IO handle function
*/
ocf_handle_io_t handle;
/**
* @brief OCF IO completion function
*/
ocf_end_io_t end;
/** /**
* @brief OCF IO private 1 * @brief OCF IO private 1
*/ */
@ -102,6 +92,16 @@ struct ocf_io {
* @brief OCF IO private 2 * @brief OCF IO private 2
*/ */
void *priv2; void *priv2;
/**
* @brief OCF IO handle function
*/
ocf_handle_io_t handle;
/**
* @brief OCF IO completion function
*/
ocf_end_io_t end;
}; };
/** /**

View File

@ -851,25 +851,25 @@ struct ocf_mngt_io_class_config {
*/ */
uint32_t class_id; uint32_t class_id;
/**
* @brief IO class maximum size
*/
uint32_t max_size;
/** /**
* @brief IO class name * @brief IO class name
*/ */
const char *name; const char *name;
/**
* @brief IO class eviction priority
*/
int16_t prio;
/** /**
* @brief IO class cache mode * @brief IO class cache mode
*/ */
ocf_cache_mode_t cache_mode; ocf_cache_mode_t cache_mode;
/** /**
* @brief IO class maximum size * @brief IO class eviction priority
*/ */
uint32_t max_size; int16_t prio;
}; };
struct ocf_mngt_io_classes_config { struct ocf_mngt_io_classes_config {

View File

@ -101,6 +101,15 @@ struct ocf_volume_ops {
*/ */
void (*close)(ocf_volume_t volume); void (*close)(ocf_volume_t volume);
/**
* @brief Get volume length
*
* @param[in] volume Volume
*
* @return Volume length in bytes
*/
uint64_t (*get_length)(ocf_volume_t volume);
/** /**
* @brief Get maximum io size * @brief Get maximum io size
* *
@ -109,15 +118,6 @@ struct ocf_volume_ops {
* @return Maximum io size in bytes * @return Maximum io size in bytes
*/ */
unsigned int (*get_max_io_size)(ocf_volume_t volume); unsigned int (*get_max_io_size)(ocf_volume_t volume);
/**
* @brief Get volume length
*
* @param[in] volume Volume
*
* @return Volume lenght in bytes
*/
uint64_t (*get_length)(ocf_volume_t volume);
}; };
/** /**
@ -136,14 +136,14 @@ struct ocf_volume_properties {
struct ocf_volume_caps caps; struct ocf_volume_caps caps;
/*!< Volume capabilities */ /*!< Volume capabilities */
struct ocf_volume_ops ops;
/*!< Volume operations */
struct ocf_io_ops io_ops; struct ocf_io_ops io_ops;
/*!< IO operations */ /*!< IO operations */
void (*deinit)(void); void (*deinit)(void);
/*!< Deinitialize volume type */ /*!< Deinitialize volume type */
struct ocf_volume_ops ops;
/*!< Volume operations */
}; };
/** /**

View File

@ -37,8 +37,8 @@
struct __waiter { struct __waiter {
ocf_cache_line_t line; ocf_cache_line_t line;
void *ctx;
uint32_t ctx_id; uint32_t ctx_id;
void *ctx;
ocf_req_async_lock_cb cb; ocf_req_async_lock_cb cb;
struct list_head item; struct list_head item;
int rw; int rw;

View File

@ -199,8 +199,8 @@ struct ocf_metadata_load_properties {
enum ocf_metadata_shutdown_status shutdown_status; enum ocf_metadata_shutdown_status shutdown_status;
uint8_t dirty_flushed; uint8_t dirty_flushed;
ocf_metadata_layout_t layout; ocf_metadata_layout_t layout;
ocf_cache_line_size_t line_size;
ocf_cache_mode_t cache_mode; ocf_cache_mode_t cache_mode;
ocf_cache_line_size_t line_size;
char *cache_name; char *cache_name;
}; };

View File

@ -14,8 +14,6 @@ struct ocf_user_part_config {
char name[OCF_IO_CLASS_NAME_MAX]; char name[OCF_IO_CLASS_NAME_MAX];
uint32_t min_size; uint32_t min_size;
uint32_t max_size; uint32_t max_size;
int16_t priority;
ocf_cache_mode_t cache_mode;
struct { struct {
uint8_t valid : 1; uint8_t valid : 1;
uint8_t added : 1; uint8_t added : 1;
@ -24,6 +22,8 @@ struct ocf_user_part_config {
* and means that can evict from this partition * and means that can evict from this partition
*/ */
} flags; } flags;
int16_t priority;
ocf_cache_mode_t cache_mode;
}; };
struct ocf_user_part_runtime { struct ocf_user_part_runtime {
@ -40,12 +40,12 @@ typedef bool ( *_lru_hash_locked_pfn)(struct ocf_request *req,
in round robin order */ in round robin order */
struct ocf_lru_iter struct ocf_lru_iter
{ {
/* per-partition cacheline iterator */
ocf_cache_line_t curr_cline[OCF_NUM_EVICTION_LISTS];
/* cache object */ /* cache object */
ocf_cache_t cache; ocf_cache_t cache;
/* target partition */ /* target partition */
struct ocf_user_part *part; struct ocf_user_part *part;
/* per-partition cacheline iterator */
ocf_cache_line_t curr_cline[OCF_NUM_EVICTION_LISTS];
/* available (non-empty) eviction list bitmap rotated so that current /* available (non-empty) eviction list bitmap rotated so that current
@evp is on the most significant bit */ @evp is on the most significant bit */
unsigned long long next_avail_evp; unsigned long long next_avail_evp;

View File

@ -56,12 +56,12 @@ struct ocf_metadata_lock
struct ocf_metadata_global_lock global[OCF_NUM_GLOBAL_META_LOCKS]; struct ocf_metadata_global_lock global[OCF_NUM_GLOBAL_META_LOCKS];
/*!< global metadata lock (GML) */ /*!< global metadata lock (GML) */
env_rwlock eviction[OCF_NUM_EVICTION_LISTS]; /*!< Fast lock for eviction policy */ env_rwlock eviction[OCF_NUM_EVICTION_LISTS]; /*!< Fast lock for eviction policy */
env_spinlock partition[OCF_IO_CLASS_MAX]; /* partition lock */
env_rwsem *hash; /*!< Hash bucket locks */ env_rwsem *hash; /*!< Hash bucket locks */
env_rwsem *collision_pages; /*!< Collision table page locks */ env_rwsem *collision_pages; /*!< Collision table page locks */
env_spinlock partition[OCF_IO_CLASS_MAX]; /* partition lock */ ocf_cache_t cache; /*!< Parent cache object */
uint32_t num_hash_entries; /*!< Hash bucket count */ uint32_t num_hash_entries; /*!< Hash bucket count */
uint32_t num_collision_pages; /*!< Collision table page count */ uint32_t num_collision_pages; /*!< Collision table page count */
ocf_cache_t cache; /*!< Parent cache object */
}; };
/** /**

View File

@ -20,6 +20,10 @@ struct ocf_superblock_config {
* shouldn't change!! */ * shouldn't change!! */
uint8_t clean_shutdown; uint8_t clean_shutdown;
uint8_t dirty_flushed; uint8_t dirty_flushed;
/* Current core sequence number */
ocf_core_id_t curr_core_seq_no;
uint32_t magic_number; uint32_t magic_number;
uint32_t metadata_version; uint32_t metadata_version;
@ -47,9 +51,6 @@ struct ocf_superblock_config {
ocf_eviction_t eviction_policy_type; ocf_eviction_t eviction_policy_type;
/* Current core sequence number */
ocf_core_id_t curr_core_seq_no;
/* /*
* Checksum for each metadata region. * Checksum for each metadata region.
* This field has to be the last one! * This field has to be the last one!

View File

@ -14,7 +14,7 @@ struct ocf_metadata_updater {
struct ocf_metadata_io_syncher { struct ocf_metadata_io_syncher {
struct list_head in_progress_head; struct list_head in_progress_head;
struct list_head pending_head; struct list_head pending_head;
env_mutex lock; env_mutex lock __attribute__((aligned(64)));
} syncher; } syncher;
void *priv; void *priv;

View File

@ -39,8 +39,6 @@
* @brief Helpful struct to start cache * @brief Helpful struct to start cache
*/ */
struct ocf_cache_mngt_init_params { struct ocf_cache_mngt_init_params {
bool metadata_volatile;
ocf_ctx_t ctx; ocf_ctx_t ctx;
/*!< OCF context */ /*!< OCF context */
@ -50,6 +48,8 @@ struct ocf_cache_mngt_init_params {
uint8_t locked; uint8_t locked;
/*!< Keep cache locked */ /*!< Keep cache locked */
bool metadata_volatile;
/** /**
* @brief initialization state (in case of error, it is used to know * @brief initialization state (in case of error, it is used to know
* which assets have to be deallocated in premature exit from function * which assets have to be deallocated in premature exit from function

View File

@ -81,57 +81,60 @@ struct ocf_cache {
struct ocf_lst lst_part; struct ocf_lst lst_part;
struct ocf_user_part user_parts[OCF_IO_CLASS_MAX + 1]; struct ocf_user_part user_parts[OCF_IO_CLASS_MAX + 1];
struct ocf_metadata metadata;
ocf_freelist_t freelist; ocf_freelist_t freelist;
ocf_eviction_t eviction_policy_init; ocf_eviction_t eviction_policy_init;
uint32_t fallback_pt_error_threshold;
ocf_queue_t mngt_queue;
struct ocf_metadata metadata;
struct { struct {
/* cache get/put counter */ /* cache get/put counter */
struct ocf_refcnt cache; struct ocf_refcnt cache __attribute__((aligned(64)));
/* # of requests potentially dirtying cachelines */ /* # of requests potentially dirtying cachelines */
struct ocf_refcnt dirty; struct ocf_refcnt dirty __attribute__((aligned(64)));
/* # of requests accessing attached metadata, excluding /* # of requests accessing attached metadata, excluding
* management reqs */ * management reqs */
struct ocf_refcnt metadata; struct ocf_refcnt metadata __attribute__((aligned(64)));
} refcnt; } refcnt;
uint32_t fallback_pt_error_threshold; struct ocf_core core[OCF_CORE_MAX];
ocf_pipeline_t stop_pipeline;
env_atomic fallback_pt_error_counter; env_atomic fallback_pt_error_counter;
env_atomic pending_read_misses_list_blocked; env_atomic pending_read_misses_list_blocked;
env_atomic pending_read_misses_list_count; env_atomic pending_read_misses_list_count;
env_atomic last_access_ms;
env_atomic pending_eviction_clines; env_atomic pending_eviction_clines;
struct list_head io_queues;
ocf_queue_t mngt_queue;
uint16_t ocf_core_inactive_count;
struct ocf_core core[OCF_CORE_MAX];
env_atomic flush_in_progress; env_atomic flush_in_progress;
env_mutex flush_mutex;
struct ocf_metadata_updater metadata_updater;
struct ocf_cleaner cleaner; struct ocf_cleaner cleaner;
struct ocf_metadata_updater metadata_updater;
struct list_head io_queues;
ocf_promotion_policy_t promotion_policy; ocf_promotion_policy_t promotion_policy;
struct ocf_async_lock lock; struct {
uint32_t max_queue_size;
uint32_t queue_unblock_size;
} backfill;
void *priv;
/* /*
* Most of the time this variable is set to 0, unless user requested * Most of the time this variable is set to 0, unless user requested
* interruption of flushing process. * interruption of flushing process.
*/ */
int flushing_interrupted; int flushing_interrupted;
env_mutex flush_mutex;
struct { uint16_t ocf_core_inactive_count;
uint32_t max_queue_size;
uint32_t queue_unblock_size;
} backfill;
bool pt_unaligned_io; bool pt_unaligned_io;
@ -139,9 +142,9 @@ struct ocf_cache {
struct ocf_trace trace; struct ocf_trace trace;
ocf_pipeline_t stop_pipeline; struct ocf_async_lock lock;
// This should be on it's own cacheline ideally
void *priv; env_atomic last_access_ms;
}; };
static inline ocf_core_t ocf_cache_get_core(ocf_cache_t cache, static inline ocf_core_t ocf_cache_get_core(ocf_cache_t cache,

View File

@ -17,22 +17,25 @@
* @brief OCF main control structure * @brief OCF main control structure
*/ */
struct ocf_ctx { struct ocf_ctx {
const struct ocf_ctx_ops *ops;
const struct ocf_ctx_config *cfg;
struct ocf_logger logger;
struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX]; struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX];
env_atomic ref_count;
env_rmutex lock; env_rmutex lock;
struct ocf_logger logger;
const struct ocf_ctx_ops *ops;
struct {
struct env_mpool *req;
struct env_mpool *mio;
} resources;
struct list_head caches; struct list_head caches;
struct { struct {
struct list_head core_pool_head; struct list_head core_pool_head;
int core_pool_count; int core_pool_count;
} core_pool; } core_pool;
struct {
struct env_mpool *req; const struct ocf_ctx_config *cfg;
struct env_mpool *mio; env_atomic ref_count;
} resources;
}; };
#define ocf_log_prefix(ctx, lvl, prefix, fmt, ...) \ #define ocf_log_prefix(ctx, lvl, prefix, fmt, ...) \

View File

@ -11,12 +11,9 @@
struct ocf_queue { struct ocf_queue {
ocf_cache_t cache; ocf_cache_t cache;
env_atomic io_no; void *priv;
env_atomic ref_count;
struct list_head io_list; struct list_head io_list;
env_spinlock io_list_lock;
/* per-queue free running global metadata lock index */ /* per-queue free running global metadata lock index */
unsigned lock_idx; unsigned lock_idx;
@ -24,20 +21,22 @@ struct ocf_queue {
/* per-queue free running eviction list index */ /* per-queue free running eviction list index */
unsigned eviction_idx; unsigned eviction_idx;
/* Tracing reference counter */ struct ocf_seq_cutoff *seq_cutoff;
env_atomic64 trace_ref_cntr;
/* Tracing stop request */
env_atomic trace_stop;
struct list_head list; struct list_head list;
const struct ocf_queue_ops *ops; const struct ocf_queue_ops *ops;
struct ocf_seq_cutoff *seq_cutoff; /* Tracing reference counter */
env_atomic64 trace_ref_cntr;
void *priv; /* Tracing stop request */
}; env_atomic trace_stop;
env_atomic io_no;
env_atomic ref_count;
env_spinlock io_list_lock;
} __attribute__((__aligned__(64)));
static inline void ocf_queue_kick(ocf_queue_t queue, bool allow_sync) static inline void ocf_queue_kick(ocf_queue_t queue, bool allow_sync)
{ {

View File

@ -106,9 +106,6 @@ struct ocf_request {
struct ocf_io_internal ioi; struct ocf_io_internal ioi;
/*!< OCF IO associated with request */ /*!< OCF IO associated with request */
const struct ocf_engine_callbacks *engine_cbs;
/*!< Engine owning the request */
env_atomic ref_count; env_atomic ref_count;
/*!< Reference usage count, once OCF request reaches zero it /*!< Reference usage count, once OCF request reaches zero it
* will be de-initialed. Get/Put method are intended to modify * will be de-initialed. Get/Put method are intended to modify
@ -128,6 +125,9 @@ struct ocf_request {
env_atomic master_remaining; env_atomic master_remaining;
/*!< Atomic counter for core device */ /*!< Atomic counter for core device */
const struct ocf_engine_callbacks *engine_cbs;
/*!< Engine owning the request */
ocf_cache_t cache; ocf_cache_t cache;
/*!< Handle to cache instance */ /*!< Handle to cache instance */

View File

@ -23,17 +23,17 @@ struct ocf_volume_type {
struct ocf_volume { struct ocf_volume {
ocf_volume_type_t type; ocf_volume_type_t type;
struct ocf_volume_uuid uuid; struct ocf_volume_uuid uuid;
struct {
unsigned discard_zeroes:1;
/* true if reading discarded pages returns 0 */
} features;
bool opened; bool opened;
bool uuid_copy; bool uuid_copy;
void *priv; void *priv;
ocf_cache_t cache; ocf_cache_t cache;
struct list_head core_pool_item; struct list_head core_pool_item;
struct { struct ocf_refcnt refcnt __attribute__((aligned(64)));
unsigned discard_zeroes:1; } __attribute__((aligned(64)));
/* true if reading discarded pages returns 0 */
} features;
struct ocf_refcnt refcnt;
};
int ocf_volume_type_init(struct ocf_volume_type **type, int ocf_volume_type_init(struct ocf_volume_type **type,
const struct ocf_volume_properties *properties, const struct ocf_volume_properties *properties,

View File

@ -96,6 +96,7 @@ struct nhit_list_elem {
}; };
struct nhit_hash { struct nhit_hash {
env_spinlock rb_pointer_lock;
ocf_cache_line_t hash_entries; ocf_cache_line_t hash_entries;
uint64_t rb_entries; uint64_t rb_entries;
@ -104,7 +105,6 @@ struct nhit_hash {
struct nhit_list_elem *ring_buffer; struct nhit_list_elem *ring_buffer;
uint64_t rb_pointer; uint64_t rb_pointer;
env_spinlock rb_pointer_lock;
}; };
static uint64_t calculate_hash_buckets(uint64_t hash_size) static uint64_t calculate_hash_buckets(uint64_t hash_size)

View File

@ -41,13 +41,13 @@ typedef int (*ocf_mlst_cmp)(struct ocf_cache *cache,
struct ocf_lst { struct ocf_lst {
struct ocf_lst_entry *head; struct ocf_lst_entry *head;
ocf_cache_line_t invalid; ocf_cache_line_t invalid;
ocf_mlst_getter getter;
ocf_mlst_cmp cmp;
struct ocf_cache *cache;
struct { struct {
uint32_t active : 1; uint32_t active : 1;
} flags; } flags;
ocf_mlst_getter getter;
ocf_mlst_cmp cmp;
struct ocf_cache *cache;
}; };
static inline void ocf_lst_init_entry(struct ocf_lst *lst, static inline void ocf_lst_init_entry(struct ocf_lst *lst,

View File

@ -43,10 +43,10 @@ class Io(Structure):
("_dir", c_uint32), ("_dir", c_uint32),
("_io_queue", c_void_p), ("_io_queue", c_void_p),
("_start", START), ("_start", START),
("_handle", HANDLE),
("_end", END),
("_priv1", c_void_p), ("_priv1", c_void_p),
("_priv2", c_void_p), ("_priv2", c_void_p),
("_handle", HANDLE),
("_end", END),
] ]
@classmethod @classmethod

View File

@ -23,10 +23,10 @@ class IoClassInfo(Structure):
class IoClassConfig(Structure): class IoClassConfig(Structure):
_fields_ = [ _fields_ = [
("_class_id", c_uint32), ("_class_id", c_uint32),
("_name", c_char_p),
("_prio", c_uint16),
("_cache_mode", c_int),
("_max_size", c_uint32), ("_max_size", c_uint32),
("_name", c_char_p),
("_cache_mode", c_int),
("_prio", c_uint16),
] ]

View File

@ -19,6 +19,7 @@ class CacheInfo(Structure):
_fields_ = [ _fields_ = [
("attached", c_bool), ("attached", c_bool),
("volume_type", c_uint8), ("volume_type", c_uint8),
("state", c_uint8),
("size", c_uint32), ("size", c_uint32),
("inactive", _Inactive), ("inactive", _Inactive),
("occupancy", c_uint32), ("occupancy", c_uint32),
@ -27,7 +28,6 @@ class CacheInfo(Structure):
("dirty_for", c_uint64), ("dirty_for", c_uint64),
("cache_mode", c_uint32), ("cache_mode", c_uint32),
("fallback_pt", _FallbackPt), ("fallback_pt", _FallbackPt),
("state", c_uint8),
("eviction_policy", c_uint32), ("eviction_policy", c_uint32),
("cleaning_policy", c_uint32), ("cleaning_policy", c_uint32),
("promotion_policy", c_uint32), ("promotion_policy", c_uint32),

View File

@ -53,8 +53,8 @@ class VolumeOps(Structure):
("_submit_write_zeroes", SUBMIT_WRITE_ZEROES), ("_submit_write_zeroes", SUBMIT_WRITE_ZEROES),
("_open", OPEN), ("_open", OPEN),
("_close", CLOSE), ("_close", CLOSE),
("_get_max_io_size", GET_MAX_IO_SIZE),
("_get_length", GET_LENGTH), ("_get_length", GET_LENGTH),
("_get_max_io_size", GET_MAX_IO_SIZE),
] ]
@ -64,9 +64,9 @@ class VolumeProperties(Structure):
("_io_priv_size", c_uint32), ("_io_priv_size", c_uint32),
("_volume_priv_size", c_uint32), ("_volume_priv_size", c_uint32),
("_caps", VolumeCaps), ("_caps", VolumeCaps),
("_ops", VolumeOps),
("_io_ops", IoOps), ("_io_ops", IoOps),
("_deinit", c_char_p), ("_deinit", c_char_p),
("_ops", VolumeOps),
] ]