Commit 72a9826b authored by Seth Jennings's avatar Seth Jennings Committed by Greg Kroah-Hartman

staging: zcache: fix serialization bug in zv stats

In a multithreaded workload, the zv_curr_dist_counts
and zv_cumul_dist_counts statistics are being corrupted
because the increments and decrements in zv_create
and zv_free are not atomic.

This patch converts these statistics and their corresponding
increments/decrements/reads to atomic operations.
Signed-off-by: default avatarSeth Jennings <sjenning@linux.vnet.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8f9cde23
...@@ -690,8 +690,8 @@ static unsigned int zv_max_zsize = (PAGE_SIZE / 8) * 7; ...@@ -690,8 +690,8 @@ static unsigned int zv_max_zsize = (PAGE_SIZE / 8) * 7;
*/ */
static unsigned int zv_max_mean_zsize = (PAGE_SIZE / 8) * 5; static unsigned int zv_max_mean_zsize = (PAGE_SIZE / 8) * 5;
static unsigned long zv_curr_dist_counts[NCHUNKS]; static atomic_t zv_curr_dist_counts[NCHUNKS];
static unsigned long zv_cumul_dist_counts[NCHUNKS]; static atomic_t zv_cumul_dist_counts[NCHUNKS];
static struct zv_hdr *zv_create(struct xv_pool *xvpool, uint32_t pool_id, static struct zv_hdr *zv_create(struct xv_pool *xvpool, uint32_t pool_id,
struct tmem_oid *oid, uint32_t index, struct tmem_oid *oid, uint32_t index,
...@@ -710,8 +710,8 @@ static struct zv_hdr *zv_create(struct xv_pool *xvpool, uint32_t pool_id, ...@@ -710,8 +710,8 @@ static struct zv_hdr *zv_create(struct xv_pool *xvpool, uint32_t pool_id,
&page, &offset, ZCACHE_GFP_MASK); &page, &offset, ZCACHE_GFP_MASK);
if (unlikely(ret)) if (unlikely(ret))
goto out; goto out;
zv_curr_dist_counts[chunks]++; atomic_inc(&zv_curr_dist_counts[chunks]);
zv_cumul_dist_counts[chunks]++; atomic_inc(&zv_cumul_dist_counts[chunks]);
zv = kmap_atomic(page, KM_USER0) + offset; zv = kmap_atomic(page, KM_USER0) + offset;
zv->index = index; zv->index = index;
zv->oid = *oid; zv->oid = *oid;
...@@ -733,7 +733,7 @@ static void zv_free(struct xv_pool *xvpool, struct zv_hdr *zv) ...@@ -733,7 +733,7 @@ static void zv_free(struct xv_pool *xvpool, struct zv_hdr *zv)
ASSERT_SENTINEL(zv, ZVH); ASSERT_SENTINEL(zv, ZVH);
BUG_ON(chunks >= NCHUNKS); BUG_ON(chunks >= NCHUNKS);
zv_curr_dist_counts[chunks]--; atomic_dec(&zv_curr_dist_counts[chunks]);
size -= sizeof(*zv); size -= sizeof(*zv);
BUG_ON(size == 0); BUG_ON(size == 0);
INVERT_SENTINEL(zv, ZVH); INVERT_SENTINEL(zv, ZVH);
...@@ -773,7 +773,7 @@ static int zv_curr_dist_counts_show(char *buf) ...@@ -773,7 +773,7 @@ static int zv_curr_dist_counts_show(char *buf)
char *p = buf; char *p = buf;
for (i = 0; i < NCHUNKS; i++) { for (i = 0; i < NCHUNKS; i++) {
n = zv_curr_dist_counts[i]; n = atomic_read(&zv_curr_dist_counts[i]);
p += sprintf(p, "%lu ", n); p += sprintf(p, "%lu ", n);
chunks += n; chunks += n;
sum_total_chunks += i * n; sum_total_chunks += i * n;
...@@ -789,7 +789,7 @@ static int zv_cumul_dist_counts_show(char *buf) ...@@ -789,7 +789,7 @@ static int zv_cumul_dist_counts_show(char *buf)
char *p = buf; char *p = buf;
for (i = 0; i < NCHUNKS; i++) { for (i = 0; i < NCHUNKS; i++) {
n = zv_cumul_dist_counts[i]; n = atomic_read(&zv_cumul_dist_counts[i]);
p += sprintf(p, "%lu ", n); p += sprintf(p, "%lu ", n);
chunks += n; chunks += n;
sum_total_chunks += i * n; sum_total_chunks += i * n;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment