Pass buffer to elem rather than alloc in lblk_alloc_elem_{get,put}

This will assist in {read,writ}ing only the needed lblk alloc pages.
This commit is contained in:
Tom Marshall 2019-10-09 11:57:57 -07:00
parent 6dfb8997a8
commit b675fe573a
3 changed files with 21 additions and 19 deletions

View File

@ -435,6 +435,7 @@ lblk_write(struct dm_compress* dc)
int ret;
u32 zone;
u32 zone_lblk;
u8* elem_buf;
size_t d_len;
size_t c_len;
u8* c_buf;
@ -443,6 +444,7 @@ lblk_write(struct dm_compress* dc)
zone = dc->lblk_num / dc->params.lblk_per_zone;
zone_lblk = dc->lblk_num - (zone * dc->params.lblk_per_zone);
elem_buf = dc->zone_lblk_alloc + zone_lblk * lblk_alloc_elem_len(&dc->params);
/*
* We must have dc->zone_lblk_alloc and dc->lblk_alloc_elem cached by
@ -504,8 +506,7 @@ lblk_write(struct dm_compress* dc)
}
}
lblk_alloc_elem_put(&dc->params,
dc->zone_lblk_alloc, zone_lblk, dc->lblk_alloc_elem);
lblk_alloc_elem_put(&dc->params, elem_buf, dc->lblk_alloc_elem);
ret = zone_lblk_alloc_write(dc);
if (ret != 0) {
printk(KERN_ERR " zone_lblk_alloc_write failed\n");
@ -543,6 +544,7 @@ lblk_read(struct dm_compress* dc, u64 idx)
int ret;
u32 zone;
u32 zone_lblk;
u8* elem_buf;
u32 c_len;
u64 pblk;
@ -556,14 +558,14 @@ lblk_read(struct dm_compress* dc, u64 idx)
zone = idx / dc->params.lblk_per_zone;
zone_lblk = idx - (zone * dc->params.lblk_per_zone);
elem_buf = dc->zone_lblk_alloc + zone_lblk * lblk_alloc_elem_len(&dc->params);
ret = zone_lblk_alloc_read(dc, zone);
if (ret != 0) {
printk(KERN_ERR " zone_lblk_alloc_read failed\n");
return ret;
}
lblk_alloc_elem_get(&dc->params,
dc->zone_lblk_alloc, zone_lblk, dc->lblk_alloc_elem);
lblk_alloc_elem_get(&dc->params, elem_buf, dc->lblk_alloc_elem);
c_len = dc->lblk_alloc_elem->len;
if (c_len == 0) {

View File

@ -295,60 +295,58 @@ cbd_bitmap_free(u8* buf, u32 idx)
static inline void
lblk_alloc_elem_get(const struct cbd_params* params,
const u8* buf, u32 idx, struct lblk_alloc_elem* elem)
const u8* buf, struct lblk_alloc_elem* elem)
{
const u8* raw = buf + idx * lblk_alloc_elem_len(params);
u32 n;
if (params->lblk_shift + PBLK_SHIFT > 16) {
elem->len = get32_le(&raw);
elem->len = get32_le(&buf);
}
else {
elem->len = get16_le(&raw);
elem->len = get16_le(&buf);
}
if (params->nr_pblk <= 0xffff) {
for (n = 0; n < lblk_per_pblk(params); ++n) {
elem->pblk[n] = get16_le(&raw);
elem->pblk[n] = get16_le(&buf);
}
}
else if (params->nr_pblk <= 0xffffffff) {
for (n = 0; n < lblk_per_pblk(params); ++n) {
elem->pblk[n] = get32_le(&raw);
elem->pblk[n] = get32_le(&buf);
}
}
else {
for (n = 0; n < lblk_per_pblk(params); ++n) {
elem->pblk[n] = get48_le(&raw);
elem->pblk[n] = get48_le(&buf);
}
}
}
static inline void
lblk_alloc_elem_put(const struct cbd_params* params,
void* buf, u32 idx, const struct lblk_alloc_elem* elem)
u8* buf, const struct lblk_alloc_elem* elem)
{
u8* raw = buf + idx * lblk_alloc_elem_len(params);
u32 n;
if (params->lblk_shift + PBLK_SHIFT > 16) {
put32_le(&raw, elem->len);
put32_le(&buf, elem->len);
}
else {
put16_le(&raw, elem->len);
put16_le(&buf, elem->len);
}
if (params->nr_pblk <= 0xffff) {
for (n = 0; n < lblk_per_pblk(params); ++n) {
put16_le(&raw, elem->pblk[n]);
put16_le(&buf, elem->pblk[n]);
}
}
else if (params->nr_pblk <= 0xffffffff) {
for (n = 0; n < lblk_per_pblk(params); ++n) {
put32_le(&raw, elem->pblk[n]);
put32_le(&buf, elem->pblk[n]);
}
}
else {
for (n = 0; n < lblk_per_pblk(params); ++n) {
put48_le(&raw, elem->pblk[n]);
put48_le(&buf, elem->pblk[n]);
}
}
}

View File

@ -64,12 +64,14 @@ check_one_lblk(const struct cbd_params* params,
u8** pblk_used)
{
struct lblk_alloc_elem* elem;
u8* elem_buf;
u32 n;
u64 pblk;
u32 rel_pblk;
elem = calloc(1, offsetof(struct lblk_alloc_elem, pblk[lblk_per_pblk(params)]));
lblk_alloc_elem_get(params, zm->lblk_alloc, lblk, elem);
elem_buf = zm->lblk_alloc + lblk * lblk_alloc_elem_len(params);
lblk_alloc_elem_get(params, elem_buf, elem);
printf(" lblk[%u]: len=%u\n", lblk, elem->len);
for (n = 0; n < lblk_per_pblk(params); ++n) {
pblk = elem->pblk[n];