From f4842791b76b69cbe665d6127915ce945188d1d2 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Wed, 3 Jan 2024 16:39:31 -0500 Subject: [PATCH] EX-7601 osc: add COMPR_GAP check to compress_request Currently, compress_request will build the compression buffer (calling merge_chunk()) for requests which are less than the minimum compression gap. This is noticed in the compression code when it checks if there's enough data to attempt compression, but we can do a trivial check in compress_request() to save that work. Also fix a few minor style things. This is not an important fix, but I discovered it while investigating another issue and it's trivial to resolve. Signed-off-by: Patrick Farrell Change-Id: Ieb32e6297e10d229f23c58e2ef4d933ce3dda4f2 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53587 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Artem Blagodarenko Reviewed-by: Andreas Dilger --- lustre/include/lustre_compr.h | 1 + lustre/obdclass/lustre_compr.c | 7 +++---- lustre/osc/osc_compress.c | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lustre/include/lustre_compr.h b/lustre/include/lustre_compr.h index 3ccd308..9a3b31e 100644 --- a/lustre/include/lustre_compr.h +++ b/lustre/include/lustre_compr.h @@ -27,6 +27,7 @@ #define _LUSTRE_COMPR_H_ #include +#define LL_COMPR_GAP 4096 int alloc_compr(const char *obd_name, enum ll_compr_type *type, unsigned int *lvl, struct crypto_comp **cc, bool decompress); diff --git a/lustre/obdclass/lustre_compr.c b/lustre/obdclass/lustre_compr.c index 606eca5..2805a91 100644 --- a/lustre/obdclass/lustre_compr.c +++ b/lustre/obdclass/lustre_compr.c @@ -259,7 +259,6 @@ EXPORT_SYMBOL(alloc_compr); * The minimum delta between compressed and plain data to * use the compressed one. */ -#define COMP_GAP 4096 int compress_chunk(const char *obd_name, struct crypto_comp *cc, const unsigned char *in, unsigned int in_len, unsigned char *out, unsigned int *out_len, @@ -275,7 +274,7 @@ int compress_chunk(const char *obd_name, struct crypto_comp *cc, /* the uncompressed data is shorter than the minimum effective * compressed size, so don't bother compressing */ - if (in_len <= COMP_GAP) { + if (in_len <= LL_COMPR_GAP) { *out_len = in_len; return 0; } @@ -291,8 +290,8 @@ int compress_chunk(const char *obd_name, struct crypto_comp *cc, } /* round the sizes up to the nearest block before comparing */ - effective_compr_size = round_up(len + sizeof(*llch), COMP_GAP); - effective_uncompr_size = round_up(in_len, COMP_GAP); + effective_compr_size = round_up(len + sizeof(*llch), LL_COMPR_GAP); + effective_uncompr_size = round_up(in_len, LL_COMPR_GAP); if (effective_compr_size >= effective_uncompr_size) { CDEBUG(D_SEC, diff --git a/lustre/osc/osc_compress.c b/lustre/osc/osc_compress.c index 7dbb777..0904db3 100644 --- a/lustre/osc/osc_compress.c +++ b/lustre/osc/osc_compress.c @@ -163,8 +163,9 @@ int compress_request(const char *obd_name, struct obdo *oa, bool chunk_unmergeable = false; bool compress_this = false; bool compressed = false; - int chunk_start = -1; + __u64 chunk_len_bytes; int chunk_len = 1; + int chunk_start; int curr; /* if this page isn't aligned to chunk start, skip it */ @@ -207,6 +208,11 @@ int compress_request(const char *obd_name, struct obdo *oa, } /* last page in this chunk (could be == first, that's OK) */ pg_last = pga[chunk_start + chunk_len - 1]; + + chunk_len_bytes = PAGE_SIZE * chunk_len; + + if (chunk_len == pages_per_chunk) { + compress_this = true; /* if the write end is equal to KMS, this write - which we * already verified starts at a chunk boundary - is the * furthest write to this file and can be compressed @@ -214,9 +220,9 @@ int compress_request(const char *obd_name, struct obdo *oa, * we check the end for equality. We could do >=, but == should * always work.) */ - if (chunk_len == pages_per_chunk) - compress_this = true; - else if (!chunk_unmergeable && pg_last->off + pg_last->count == kms) { + } else if (chunk_len_bytes > LL_COMPR_GAP && + !chunk_unmergeable && + pg_last->off + pg_last->count == kms) { compress_this = true; CDEBUG(D_SEC, "Chunk starting at %llu (pages [%d, %d]) matches kms %llu, compressing.\n", @@ -227,7 +233,6 @@ int compress_request(const char *obd_name, struct obdo *oa, pga[chunk_start]->off, pg_last->off + pg_last->count, kms); if (compress_this) { - CDEBUG(D_SEC, "compressing chunk from page [%d, %d], off [%llu, %llu]\n", chunk_start, chunk_start + chunk_len - 1, -- 1.8.3.1