Skip to content

Commit

Permalink
GZIP compression offloading with QAT accelerator
Browse files Browse the repository at this point in the history
This patch implement the hardware accelerator method in GZIP compression
in ZFS. When the ZFS pool is enabled GZIP compression, the compression
API will be automatically transferred to the hardware accelerator to
free up CPU resource and speed up the compression time.

* To enable Intel QAT hardware acceleration in ZOL you need have QAT
  hardware and driver installed:
  * QAT hardware DH8950:
  http://ark.intel.com/products/79483/Intel-QuickAssist-Adapter-8950
  * QAT driver:
  https://01.org/intel-quickassist-technology
* Start QAT driver in your system:
  service qat_service start
* Enable QAT in ZFS, e.g.:
  ./configure --with-qat=<qat-driver-path>/QAT1.6
  make
* Set GZIP compression in ZFS dataset:
  zfs set compression = gzip <dataset>
* Get QAT hardware statistics by:
  cat /proc/icp_dh895xcc_dev/qat
* To disable QAT in ZFS:
  insmod zfs.ko zfs_qat_disable=1
  • Loading branch information
wli5 committed Feb 28, 2017
1 parent 912e2ba commit cd6389a
Show file tree
Hide file tree
Showing 8 changed files with 560 additions and 0 deletions.
90 changes: 90 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dnl #
AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
ZFS_AC_KERNEL
ZFS_AC_SPL
ZFS_AC_QAT
ZFS_AC_TEST_MODULE
ZFS_AC_KERNEL_CONFIG
ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
Expand Down Expand Up @@ -467,6 +468,95 @@ AC_DEFUN([ZFS_AC_SPL], [
AC_SUBST(SPL_SYMBOLS)
])

dnl #
dnl # Detect the QAT module to be built against
dnl # QAT provides hardware acceleration for data compression:
dnl # https://01.org/intel-quickassist-technology
dnl # * Download and install QAT driver from the above link
dnl # * Start QAT driver in your system:
dnl # service qat_service start
dnl # * Enable QAT in ZFS, e.g.:
dnl # ./configure --with-qat=<qat-driver-path>/QAT1.6
dnl # make
dnl # * Set GZIP compression in ZFS dataset:
dnl # zfs set compression = gzip <dataset>
dnl # Then the data written to this ZFS pool is compressed
dnl # by QAT accelerator automatically, and de-compressed by
dnl # QAT when read from the pool.
dnl # * Get QAT hardware statistics by:
dnl # cat /proc/icp_dh895xcc_dev/qat
dnl # * To disable QAT:
dnl # insmod zfs.ko zfs_qat_disable=1
dnl #
AC_DEFUN([ZFS_AC_QAT], [
AC_ARG_WITH([qat],
AS_HELP_STRING([--with-qat=PATH],
[Path to qat source]),
AS_IF([test "$withval" = "yes"],
AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
[qatsrc="$withval"]))
AC_ARG_WITH([qat-obj],
AS_HELP_STRING([--with-qat-obj=PATH],
[Path to qat build objects]),
[qatbuild="$withval"])
AS_IF([test ! -z "${qatsrc}"], [
AC_MSG_CHECKING([qat source directory])
AC_MSG_RESULT([$qatsrc])
QAT_SRC="${qatsrc}/quickassist"
AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
AC_MSG_ERROR([
*** Please make sure the qat driver package is installed
*** and specify the location of the qat source with the
*** '--with-qat=PATH' option then try again. Failed to
*** find cpa.h in:
${QAT_SRC}/include])
])
])
AS_IF([test ! -z "${qatsrc}"], [
AC_MSG_CHECKING([qat build directory])
AS_IF([test -z "$qatbuild"], [
qatbuild="${qatsrc}/build"
])
AC_MSG_RESULT([$qatbuild])
QAT_OBJ=${qatbuild}
AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko"], [
AC_MSG_ERROR([
*** Please make sure the qat driver is installed then try again.
*** Failed to find icp_qa_al.ko in:
$QAT_OBJ])
])
AC_SUBST(QAT_SRC)
AC_SUBST(QAT_OBJ)
AC_DEFINE(HAVE_QAT, 1,
[qat is enabled and existed])
])
dnl #
dnl # Detect the name used for the QAT Module.symvers file.
dnl #
AS_IF([test ! -z "${qatsrc}"], [
AC_MSG_CHECKING([qat file for module symbols])
QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
AS_IF([test -r $QAT_SYMBOLS], [
AC_MSG_RESULT([$QAT_SYMBOLS])
AC_SUBST(QAT_SYMBOLS)
],[
AC_MSG_ERROR([
*** Please make sure the qat driver is installed then try again.
*** Failed to find Module.symvers in:
$QAT_SYMBOLS])
])
])
])
])

dnl #
dnl # Basic toolchain sanity check.
dnl #
Expand Down
3 changes: 3 additions & 0 deletions config/zfs-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ AC_DEFUN([ZFS_AC_CONFIG], [
[test "x$enable_linux_builtin" != xyes ])
AM_CONDITIONAL([WANT_DEVNAME2DEVID],
[test "x$user_libudev" = xyes ])
AM_CONDITIONAL([CONFIG_QAT],
[test "$ZFS_CONFIG" = kernel -o "$ZFS_CONFIG" = all] &&
[test "x$qatsrc" != x ])
])

dnl #
Expand Down
2 changes: 2 additions & 0 deletions module/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ INSTALL_MOD_DIR ?= extra
ZFS_MODULE_CFLAGS += -include @SPL_OBJ@/spl_config.h
ZFS_MODULE_CFLAGS += -include @abs_top_builddir@/zfs_config.h
ZFS_MODULE_CFLAGS += -I@abs_top_srcdir@/include -I@SPL@/include -I@SPL@
@CONFIG_QAT_TRUE@ZFS_MODULE_CFLAGS += -I@QAT_SRC@/include
@CONFIG_QAT_TRUE@KBUILD_EXTRA_SYMBOLS += @QAT_SYMBOLS@
export ZFS_MODULE_CFLAGS

SUBDIR_TARGETS = icp
Expand Down
1 change: 1 addition & 0 deletions module/zfs/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ $(MODULE)-objs += zrlock.o
$(MODULE)-objs += zvol.o
$(MODULE)-objs += dsl_destroy.o
$(MODULE)-objs += dsl_userhold.o
$(MODULE)-objs += qat_compress.o

$(MODULE)-$(CONFIG_X86) += vdev_raidz_math_sse2.o
$(MODULE)-$(CONFIG_X86) += vdev_raidz_math_ssse3.o
Expand Down
17 changes: 17 additions & 0 deletions module/zfs/gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <sys/debug.h>
#include <sys/types.h>
#include "qat_compress.h"

#ifdef _KERNEL

Expand Down Expand Up @@ -56,6 +57,14 @@ gzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)

ASSERT(d_len <= s_len);

if (use_qat(s_len)) {
if (qat_compress(0, s_start, s_len, d_start, d_len, &dstlen) !=
CPA_STATUS_SUCCESS)
return (s_len);

return ((size_t)dstlen);
}

if (compress_func(d_start, &dstlen, s_start, s_len, n) != Z_OK) {
if (d_len != s_len)
return (s_len);
Expand All @@ -75,6 +84,14 @@ gzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)

ASSERT(d_len >= s_len);

if (use_qat(s_len)) {
if (qat_compress(1, s_start, s_len, d_start, d_len, &dstlen) !=
CPA_STATUS_SUCCESS)
return (-1);

return (0);
}

if (uncompress_func(d_start, &dstlen, s_start, s_len) != Z_OK)
return (-1);

Expand Down
Loading

0 comments on commit cd6389a

Please sign in to comment.