1919#include " common/dout.h"
2020#include " common/errno.h"
2121#include " QatAccel.h"
22+ #include " zlib.h"
2223
2324// -----------------------------------------------------------------------------
2425#define dout_context g_ceph_context
@@ -33,6 +34,7 @@ static std::ostream& _prefix(std::ostream* _dout)
3334// -----------------------------------------------------------------------------
3435// default window size for Zlib 1.2.8, negated for raw deflate
3536#define ZLIB_DEFAULT_WIN_SIZE -15
37+ #define GZIP_WRAPPER 16
3638
3739/* Estimate data expansion after decompression */
3840static const unsigned int expansion_ratio[] = {5 , 20 , 50 , 100 , 200 , 1000 , 10000 };
@@ -42,6 +44,10 @@ void QzSessionDeleter::operator() (struct QzSession_S *session) {
4244 delete session;
4345}
4446
47+ QzPollingMode_T busy_polling (bool isSet) {
48+ return isSet ? QZ_BUSY_POLLING : QZ_PERIODICAL_POLLING;
49+ }
50+
4551static bool setup_session (const std::string &alg, QatAccel::session_ptr &session) {
4652 int rc;
4753 rc = qzInit (session.get (), QZ_SW_BACKUP_DEFAULT);
@@ -52,10 +58,12 @@ static bool setup_session(const std::string &alg, QatAccel::session_ptr &session
5258 rc = qzGetDefaultsDeflate (¶ms);
5359 if (rc != QZ_OK)
5460 return false ;
55- params.data_fmt = QZ_DEFLATE_RAW;
61+
62+ params.data_fmt = QZ_DEFLATE_GZIP_EXT;
5663 params.common_params .comp_algorithm = QZ_DEFLATE;
5764 params.common_params .comp_lvl = g_ceph_context->_conf ->compressor_zlib_level ;
5865 params.common_params .direction = QZ_DIR_BOTH;
66+ params.common_params .polling_mode = busy_polling (g_ceph_context->_conf .get_val <bool >(" qat_compressor_busy_polling" ));
5967 rc = qzSetupSessionDeflate (session.get (), ¶ms);
6068 if (rc != QZ_OK)
6169 return false ;
@@ -136,6 +144,8 @@ bool QatAccel::init(const std::string &alg) {
136144 }
137145
138146 alg_name = alg;
147+ windowBits = GZIP_WRAPPER + MAX_WBITS;
148+
139149 return true ;
140150}
141151
@@ -145,7 +155,8 @@ int QatAccel::compress(const bufferlist &in, bufferlist &out, std::optional<int3
145155 return -1 ; // session initialization failed
146156 }
147157 auto session = cached_session_t {this , std::move (s)}; // returns to the session pool on destruction
148- compressor_message = ZLIB_DEFAULT_WIN_SIZE;
158+ compressor_message = windowBits;
159+
149160 int begin = 1 ;
150161 for (auto &i : in.buffers ()) {
151162 const unsigned char * c_in = (unsigned char *) i.c_str ();
@@ -188,28 +199,31 @@ int QatAccel::decompress(bufferlist::const_iterator &p,
188199
189200 int rc = 0 ;
190201 bufferlist tmp;
191- size_t remaining = std::min<size_t >(p.get_remaining (), compressed_len);
192-
193- while (remaining) {
194- unsigned int ratio_idx = 0 ;
195- const char * c_in = nullptr ;
196- unsigned int len = p.get_ptr_and_advance (remaining, &c_in);
197- remaining -= len;
198- len -= begin;
199- c_in += begin;
200- begin = 0 ;
202+ unsigned int ratio_idx = 0 ;
203+ const char * c_in = nullptr ;
204+ p.copy_all (tmp);
205+ c_in = tmp.c_str ();
206+ unsigned int len = std::min<unsigned int >(tmp.length (), compressed_len);
207+
208+ len -= begin;
209+ c_in += begin;
210+ begin = 0 ;
211+
212+ bufferptr ptr;
213+ do {
201214 unsigned int out_len = QZ_HW_BUFF_SZ;
202-
203- bufferptr ptr;
215+ unsigned int len_current = len;
204216 do {
205- while (out_len <= len * expansion_ratio[ratio_idx]) {
217+ while (out_len <= len_current * expansion_ratio[ratio_idx]) {
206218 out_len *= 2 ;
207219 }
208220
209221 ptr = buffer::create_small_page_aligned (out_len);
210- rc = qzDecompress (session.get (), (const unsigned char *)c_in, &len , (unsigned char *)ptr.c_str (), &out_len);
222+ rc = qzDecompress (session.get (), (const unsigned char *)c_in, &len_current , (unsigned char *)ptr.c_str (), &out_len);
211223 ratio_idx++;
212224 } while (rc == QZ_BUF_ERROR && ratio_idx < std::size (expansion_ratio));
225+ c_in += len_current;
226+ len -= len_current;
213227
214228 if (rc == QZ_OK) {
215229 dst.append (ptr, 0 , out_len);
@@ -223,7 +237,7 @@ int QatAccel::decompress(bufferlist::const_iterator &p,
223237 dout (1 ) << " QAT compressor NOT OK" << dendl;
224238 return -1 ;
225239 }
226- }
227240
241+ } while (len != 0 );
228242 return 0 ;
229243}
0 commit comments