Lines Matching +full:high +full:- +full:threshold

1 // SPDX-License-Identifier: GPL-2.0-only
11 * MS-SMB2 "3.1.4.4 Compressing the Message"
12 * MS-SMB2 "3.1.5.3 Decompressing the Chained Message"
13 * MS-XCA - for details of the supported algorithms
39 * Parsing the sample goes from "low-hanging fruits" (fastest algorithms, likely compressible)
48 * has_low_entropy() - Compute Shannon entropy of the sampled data.
53 * compress the data) is below the minimum threshold.
56 * There _is_ an entropy level here that's > 65 (minimum threshold) that would indicate a
65 const size_t threshold = 65, max_entropy = 8 * ilog2(16); in has_low_entropy() local
74 sum += p * (len - p2); in has_low_entropy()
79 return ((sum * 100 / max_entropy) <= threshold); in has_low_entropy()
86 * calc_byte_distribution() - Compute byte distribution on the sampled data.
91 * BYTE_DIST_BAD: A "hard no" for compression -- a computed uniform distribution of
93 * BYTE_DIST_GOOD: High probability (normal (Gaussian) distribution) of the data being
95 * BYTE_DIST_MAYBE: When computed byte distribution resulted in "low > n < high"
100 const size_t low = 64, high = 200, threshold = slen * 90 / 100; in calc_byte_distribution() local
107 if (sum > threshold) in calc_byte_distribution()
110 for (; i < high && bkt[i].count > 0; i++) { in calc_byte_distribution()
112 if (sum > threshold) in calc_byte_distribution()
119 if (i >= high) in calc_byte_distribution()
132 /* Too many non-ASCII (0-63) bytes. */ in is_mostly_ascii()
151 if (a->count > b->count) in cmp_bkt()
152 return -1; in cmp_bkt()
166 loff_t start = iter->xarray_start + iter->iov_offset; in collect_sample()
172 last = (start + max - 1) / PAGE_SIZE; in collect_sample()
174 nr = xa_extract(iter->xarray, (void **)folios, index, last, ARRAY_SIZE(folios), in collect_sample()
177 return -EIO; in collect_sample()
182 foff = start - folio_pos(folio); in collect_sample()
188 len = min_t(size_t, max, PAGE_SIZE - off); in collect_sample()
197 if (len2 < SZ_2K || s >= max - SZ_2K) in collect_sample()
200 max -= len; in collect_sample()
215 * is_compressible() - Determines if a chunk of data is compressible.
232 /* Preventive double check -- already checked in should_compress(). */ in is_compressible()
237 if (len - read_size > max) in is_compressible()
295 const struct smb2_hdr *shdr = rq->rq_iov->iov_base; in should_compress()
297 if (unlikely(!tcon || !tcon->ses || !tcon->ses->server)) in should_compress()
300 if (!tcon->ses->server->compression.enabled) in should_compress()
303 if (!(tcon->share_flags & SMB2_SHAREFLAG_COMPRESS_DATA)) in should_compress()
306 if (shdr->Command == SMB2_WRITE) { in should_compress()
307 const struct smb2_write_req *wreq = rq->rq_iov->iov_base; in should_compress()
309 if (le32_to_cpu(wreq->Length) < SMB_COMPRESS_MIN_LEN) in should_compress()
312 return is_compressible(&rq->rq_iter); in should_compress()
315 return (shdr->Command == SMB2_READ); in should_compress()
325 if (!server || !rq || !rq->rq_iov || !rq->rq_iov->iov_base) in smb_compress()
326 return -EINVAL; in smb_compress()
328 if (rq->rq_iov->iov_len != sizeof(struct smb2_write_req)) in smb_compress()
329 return -EINVAL; in smb_compress()
331 slen = iov_iter_count(&rq->rq_iter); in smb_compress()
334 ret = -ENOMEM; in smb_compress()
339 iter = rq->rq_iter; in smb_compress()
342 ret = -EIO; in smb_compress()
353 ret = -ENOMEM; in smb_compress()
367 hdr.Offset = cpu_to_le32(rq->rq_iov[0].iov_len); in smb_compress()
371 iov[1] = rq->rq_iov[0]; in smb_compress()
378 } else if (ret == -EMSGSIZE || dlen >= slen) { in smb_compress()