From 3eadffad0f7a3eba21bd88181f450c14d5050cf5 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 10 Feb 2020 15:48:16 -0500 Subject: [PATCH 1/3] Add static assert macro ENV_BUILD_BUG_ON to posix env Signed-off-by: Adam Rutkowski --- env/posix/ocf_env.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/env/posix/ocf_env.h b/env/posix/ocf_env.h index d255174..c175c31 100644 --- a/env/posix/ocf_env.h +++ b/env/posix/ocf_env.h @@ -71,6 +71,8 @@ typedef uint64_t sector_t; #define ENV_BUG() assert(0) #define ENV_BUG_ON(cond) do { if (cond) ENV_BUG(); } while (0) +#define ENV_BUILD_BUG_ON(cond) _Static_assert(!(cond), "static "\ + "assertion failure") /* MISC UTILITIES */ #define container_of(ptr, type, member) ({ \ From 26fd938ccf702dbb3f46702466ce732ad6480f64 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 10 Feb 2020 15:21:16 -0500 Subject: [PATCH 2/3] Reduce max trim request size to 512K 512K is the maximum request size for which request map fits into one page (4K) regardless of cacheline size. Signed-off-by: Adam Rutkowski --- inc/ocf_def.h | 2 +- src/ocf_request.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/ocf_def.h b/inc/ocf_def.h index b5a4364..bdbe211 100644 --- a/inc/ocf_def.h +++ b/inc/ocf_def.h @@ -352,6 +352,6 @@ typedef enum { * @} */ -#define MAX_TRIM_RQ_SIZE (1 * MiB) +#define MAX_TRIM_RQ_SIZE (512 * KiB) #endif /* __OCF_DEF_H__ */ diff --git a/src/ocf_request.c b/src/ocf_request.c index 8584b71..be98f0a 100644 --- a/src/ocf_request.c +++ b/src/ocf_request.c @@ -224,6 +224,9 @@ int ocf_req_alloc_map(struct ocf_request *req) int ocf_req_alloc_map_discard(struct ocf_request *req) { + ENV_BUILD_BUG_ON(MAX_TRIM_RQ_SIZE / ocf_cache_line_size_4 * + sizeof(struct ocf_map_info) > 4 * KiB); + if (req->byte_length <= MAX_TRIM_RQ_SIZE) return ocf_req_alloc_map(req); From ee37391e976496e824bbd7c802e274b5d3c34894 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 10 Feb 2020 15:23:31 -0500 Subject: [PATCH 3/3] Fix discard request map allocation Discard handling splits large request into several steps. However the actual size of request map for discard was determined based on original request size, not step request size, resulting in waste of memory and allocations > 4K. Signed-off-by: Adam Rutkowski --- src/ocf_request.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocf_request.c b/src/ocf_request.c index be98f0a..d15ca01 100644 --- a/src/ocf_request.c +++ b/src/ocf_request.c @@ -42,7 +42,7 @@ struct ocf_req_allocator { static inline size_t ocf_req_sizeof_map(struct ocf_request *req) { - uint32_t lines = req->alloc_core_line_count; + uint32_t lines = req->core_line_count; size_t size = (lines * sizeof(struct ocf_map_info)); ENV_BUG_ON(lines == 0);