--- old/usr/src/cmd/savecore/Makefile.com	Wed Aug  8 01:12:26 2018
+++ new/usr/src/cmd/savecore/Makefile.com	Wed Aug  8 01:12:26 2018
@@ -20,6 +20,7 @@
 #
 #
 # Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2018 Nexenta Systems, Inc. All rights reserved.
 #
 
 PROG= savecore
@@ -32,49 +33,26 @@
 
 CFLAGS += $(CCVERBOSE)
 CFLAGS64 += $(CCVERBOSE)
-CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -DBZ_NO_STDIO -I$(SRC)/uts/common
+CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -I$(SRC)/uts/common
 
-#
-# savecore is compiled with bits from $(SRC)/common/bzip2 and some function
-# symbols there are defined as weak; if you leave them out of
-# savecore.c it will compile, but trying to call that function
-# will jump to 0.  So we use -ztext to avoid that.
-#
-LDFLAGS += -ztext
-
-BZIP2OBJS =	bz2blocksort.o	\
-		bz2compress.o	\
-		bz2decompress.o	\
-		bz2randtable.o	\
-		bz2bzlib.o	\
-		bz2crctable.o	\
-		bz2huffman.o
-
 .KEEP_STATE:
 
 all: $(PROG)
 
-$(PROG): $(OBJS) $(BZIP2OBJS)
-	$(LINK.c) -o $(PROG) $(OBJS) $(BZIP2OBJS) $(LDLIBS)
+$(PROG): $(OBJS)
+	$(LINK.c) -o $(PROG) $(OBJS) $(LDLIBS)
 	$(POST_PROCESS)
 
 clean:
-	$(RM) $(OBJS) $(BZIP2OBJS)
+	$(RM) $(OBJS)
 
-lint := CPPFLAGS += -I$(SRC)/common
-
 #
-# Linting the usr/src/common/bzip2 source produces reams of complaints.
-# So we only lint regular SRCS, but we need to excuse two complaints
-# related to bz_internal_error.
+# savecore only uses the decompress() path of compress.c
+# suppress complaints about unused compress() path
 #
+lint := LINTFLAGS += -erroff=E_NAME_DEF_NOT_USED2
+lint := LINTFLAGS64 += -erroff=E_NAME_DEF_NOT_USED2
 
-lint := BZ2LINTCOPOUTS = -erroff=E_NAME_USED_NOT_DEF2
-lint := BZ2LINTCOPOUTS += -erroff=E_NAME_DEF_NOT_USED2
-
-lint := LINTFLAGS += $(BZ2LINTCOPOUTS)
-lint := LINTFLAGS64 += $(BZ2LINTCOPOUTS)
-
 lint:	$(LINTSRCS)
 	$(LINT.c) $(SRCS) $(LDLIBS)
 
@@ -86,8 +64,4 @@
 
 %.o: ../../../uts/common/os/%.c
 	$(COMPILE.c) $<
-	$(POST_PROCESS_O)
-
-bz2%.o: ../../../common/bzip2/%.c
-	$(COMPILE.c) -o $@ -I$(SRC)/common -I$(SRC)/common/bzip2 $<
 	$(POST_PROCESS_O)
--- old/usr/src/cmd/savecore/savecore.c	Wed Aug  8 01:12:26 2018
+++ new/usr/src/cmd/savecore/savecore.c	Wed Aug  8 01:12:26 2018
@@ -23,7 +23,7 @@
  * Copyright 2016 Joyent, Inc.
  */
 /*
- * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
  */
 
 #include <stdio.h>
@@ -51,7 +51,6 @@
 #include <sys/sysmacros.h>
 #include <sys/stat.h>
 #include <sys/resource.h>
-#include <bzip2/bzlib.h>
 #include <sys/fm/util.h>
 #include <fm/libfmevent.h>
 #include <sys/int_fmtio.h>
@@ -378,6 +377,10 @@
 		    "dump version (%d) != %s version (%d)",
 		    dumphdr.dump_version, progname, DUMP_VERSION);
 
+	if (datahdr.dump_clevel > DUMP_CLEVEL_LZJB)
+		logprint(SC_SL_NONE | SC_EXIT_PEND,
+		    "unsupported compression format (%d)", datahdr.dump_clevel);
+
 	if (dumphdr.dump_wordsize != DUMP_WORDSIZE)
 		logprint(SC_SL_NONE | SC_EXIT_PEND,
 		    "dump is from %u-bit kernel - cannot save on %u-bit kernel",
@@ -700,7 +703,6 @@
 	pgcnt_t curpage;
 	pgcnt_t npages;
 	pgcnt_t done;
-	bz_stream strm;
 	dumpcsize_t sc;
 	dumpstreamhdr_t sh;
 } stream_t;
@@ -963,121 +965,6 @@
 	}
 }
 
-/* bzlib library reports errors with this callback */
-void
-bz_internal_error(int errcode)
-{
-	logprint(SC_SL_ERR | SC_EXIT_ERR, "bz_internal_error: err %s\n",
-	    BZ2_bzErrorString(errcode));
-}
-
-/*
- * Return one object in the stream.
- *
- * An object (stream header or page) will likely span an input block
- * of compression data. Return non-zero when an entire object has been
- * retrieved from the stream.
- */
-static int
-bz2decompress(stream_t *s, void *buf, size_t size)
-{
-	int rc;
-
-	if (s->strm.avail_out == 0) {
-		s->strm.next_out = buf;
-		s->strm.avail_out = size;
-	}
-	while (s->strm.avail_in > 0) {
-		rc = BZ2_bzDecompress(&s->strm);
-		if (rc == BZ_STREAM_END) {
-			rc = BZ2_bzDecompressReset(&s->strm);
-			if (rc != BZ_OK)
-				logprint(SC_SL_ERR | SC_EXIT_ERR,
-				    "BZ2_bzDecompressReset: %s",
-				    BZ2_bzErrorString(rc));
-			continue;
-		}
-
-		if (s->strm.avail_out == 0)
-			break;
-	}
-	return (s->strm.avail_out == 0);
-}
-
-/*
- * Process one bzip2 block.
- * The interface is documented here:
- * http://www.bzip.org/1.0.5/bzip2-manual-1.0.5.html
- */
-static void
-bz2block(int corefd, stream_t *s, char *block, size_t blocksz)
-{
-	int rc = 0;
-	int doflush;
-	char *out;
-
-	if (!s->init) {
-		s->init = 1;
-		rc = BZ2_bzDecompressInit(&s->strm, 0, 0);
-		if (rc != BZ_OK)
-			logprint(SC_SL_ERR | SC_EXIT_ERR,
-			    "BZ2_bzDecompressInit: %s", BZ2_bzErrorString(rc));
-		if (s->blkbuf == NULL)
-			s->blkbuf = Zalloc(coreblksize);
-		s->strm.avail_out = 0;
-		s->state = STREAMSTART;
-	}
-	s->strm.next_in = block;
-	s->strm.avail_in = blocksz;
-
-	while (s->strm.avail_in > 0) {
-		switch (s->state) {
-		case STREAMSTART:
-			if (!bz2decompress(s, &s->sh, sizeof (s->sh)))
-				return;
-			if (strcmp(DUMP_STREAM_MAGIC, s->sh.stream_magic) != 0)
-				logprint(SC_SL_ERR | SC_EXIT_ERR,
-				    "BZ2 STREAMSTART: bad stream header");
-			if (s->sh.stream_npages > datahdr.dump_maxrange)
-				logprint(SC_SL_ERR | SC_EXIT_ERR,
-				    "BZ2 STREAMSTART: bad range: %d > %d",
-				    s->sh.stream_npages, datahdr.dump_maxrange);
-			s->pagenum = s->sh.stream_pagenum;
-			s->npages = s->sh.stream_npages;
-			s->curpage = s->pagenum;
-			s->nout = 0;
-			s->done = 0;
-			s->state = STREAMPAGES;
-			break;
-		case STREAMPAGES:
-			out = s->blkbuf + PTOB(s->nout);
-			if (!bz2decompress(s, out, pagesize))
-				return;
-
-			atomic_inc_64(&saved);
-
-			doflush = 0;
-			if (s->nout == 0 && iszpage(out)) {
-				doflush = 1;
-				atomic_inc_64(&zpages);
-			} else if (++s->nout >= BTOP(coreblksize) ||
-			    isblkbnd(s->curpage + s->nout)) {
-				doflush = 1;
-			}
-			if (++s->done >= s->npages) {
-				s->state = STREAMSTART;
-				doflush = 1;
-			}
-			if (doflush) {
-				putpage(corefd, s->blkbuf, s->curpage, s->nout);
-				s->nout = 0;
-				s->curpage = s->pagenum + s->done;
-			}
-			break;
-		}
-	}
-}
-
 /* report progress */
 static void
 report_progress()
@@ -1120,12 +1007,8 @@
 				b = deqh(&s->blocks);
 				(void) pthread_mutex_unlock(&lock);
 
-				if (datahdr.dump_clevel < DUMP_CLEVEL_BZIP2)
-					lzjbblock(t->corefd, s, b->block,
-					    b->size);
-				else
-					bz2block(t->corefd, s, b->block,
-					    b->size);
+				lzjbblock(t->corefd, s, b->block,
+				    b->size);
 
 				(void) pthread_mutex_lock(&lock);
 				enqt(&freeblocks, b);
@@ -1164,16 +1047,14 @@
  * be processing a crash file from a remote machine, which may have
  * more CPUs.
  *
- * When the kernel uses parallel lzjb or parallel bzip2, we expect a
- * series of 128KB blocks of compression data. In this case, each
- * block has a "tag", in the range 1-4095. Each block is handed off to
- * to the threads running "runstreams". The dump format is either lzjb
- * or bzip2, never a mixture. These threads, in turn, process the
- * compression data for groups of pages. Groups of pages are delimited
- * by a "stream header", which indicates a starting pfn and number of
- * pages. When a stream block has been read, the condition variable
- * "cvwork" is signalled, which causes one of the avaiable threads to
- * wake up and process the stream.
+ * When the kernel uses parallel compression we expect a series of 128KB
+ * blocks of compression data. In this case, each block has a "tag" in
+ * the range 1-4095. Each block is handed off to the threads running
+ * "runstreams". These threads, in turn, process the compression data
+ * for groups of pages. Groups of pages are delimited by a "stream header",
+ * which indicates a starting pfn and number of pages. When a stream block
+ * has been read, the condition variable "cvwork" is signalled, which causes
+ * one of the available threads to wake up and process the stream.
  *
  * In the parallel case there will be streams blocks encoding all data
  * pages. The stream of blocks is terminated by a zero size
--- old/usr/src/uts/common/os/dumpsubr.c	Wed Aug  8 01:12:27 2018
+++ new/usr/src/uts/common/os/dumpsubr.c	Wed Aug  8 01:12:27 2018
@@ -74,29 +74,13 @@
 #include <sys/hold_page.h>
 #include <sys/cpu.h>
 
-#include <bzip2/bzlib.h>
-
 #define	ONE_GIG	(1024 * 1024 * 1024UL)
 
 /*
- * Crash dump time is dominated by disk write time.  To reduce this,
- * the stronger compression method bzip2 is applied to reduce the dump
- * size and hence reduce I/O time.  However, bzip2 is much more
- * computationally expensive than the existing lzjb algorithm, so to
- * avoid increasing compression time, CPUs that are otherwise idle
- * during panic are employed to parallelize the compression task.
- * Many helper CPUs are needed to prevent bzip2 from being a
- * bottleneck, and on systems with too few CPUs, the lzjb algorithm is
- * parallelized instead. Lastly, I/O and compression are performed by
- * different CPUs, and are hence overlapped in time, unlike the older
- * serial code.
- *
- * Another important consideration is the speed of the dump
- * device. Faster disks need less CPUs in order to benefit from
- * parallel lzjb versus parallel bzip2. Therefore, the CPU count
- * threshold for switching from parallel lzjb to paralled bzip2 is
- * elevated for faster disks. The dump device speed is adduced from
- * the setting for dumpbuf.iosize, see dump_update_clevel.
+ * Parallel Dump:
+ * CPUs that are otherwise idle during panic are employed to parallelize
+ * the compression task. I/O and compression are performed by different
+ * CPUs, and are hence overlapped in time, unlike the older serial code.
  */
 
 /*
@@ -112,34 +96,22 @@
 int		dump_timeleft;		/* portion of dump_timeout remaining */
 int		dump_ioerr;		/* dump i/o error */
 int		dump_check_used;	/* enable check for used pages */
-char	    *dump_stack_scratch; /* scratch area for saving stack summary */
+char		*dump_stack_scratch; /* scratch area for saving stack summary */
 
 /*
- * Tunables for dump compression and parallelism. These can be set via
- * /etc/system.
+ * Tunables for dump compression and parallelism.
+ * These can be set via /etc/system.
  *
- * dump_ncpu_low	number of helpers for parallel lzjb
- *	This is also the minimum configuration.
+ * dump_ncpu_low:
+ * This is the minimum configuration for parallel lzjb.
+ * A special value of 0 means that parallel dump will not be used.
  *
- * dump_bzip2_level	bzip2 compression level: 1-9
- *	Higher numbers give greater compression, but take more memory
- *	and time. Memory used per helper is ~(dump_bzip2_level * 1MB).
- *
- * dump_plat_mincpu	the cross-over limit for using bzip2 (per platform):
- *	if dump_plat_mincpu == 0, then always do single threaded dump
- *	if ncpu >= dump_plat_mincpu then try to use bzip2
- *
- * dump_metrics_on	if set, metrics are collected in the kernel, passed
- *	to savecore via the dump file, and recorded by savecore in
- *	METRICS.txt.
+ * dump_metrics_on:
+ * If set, metrics are collected in the kernel, passed to savecore
+ * via the dump file, and recorded by savecore in METRICS.txt.
  */
 uint_t dump_ncpu_low = 4;	/* minimum config for parallel lzjb */
-uint_t dump_bzip2_level = 1;	/* bzip2 level (1-9) */
 
-/* Use dump_plat_mincpu_default unless this variable is set by /etc/system */
-#define	MINCPU_NOT_SET	((uint_t)-1)
-uint_t dump_plat_mincpu = MINCPU_NOT_SET;
-
 /* tunables for pre-reserved heap */
 uint_t dump_kmem_permap = 1024;
 uint_t dump_kmem_pages = 0;
@@ -149,7 +121,7 @@
 #define	NCMAP_PER_HELPER	4
 
 /* minimum number of helpers configured */
-#define	MINHELPERS	(dump_ncpu_low)
+#define	MINHELPERS	(MAX(dump_ncpu_low, 1))
 #define	MINCBUFS	(MINHELPERS * NCBUF_PER_HELPER)
 
 /*
@@ -384,7 +356,6 @@
 	size_t used;			/* counts input consumed */
 	char *page;			/* buffer for page copy */
 	char *lzbuf;			/* lzjb output */
-	bz_stream bzstream;		/* bzip2 state */
 } helper_t;
 
 #define	MAINHELPER	(-1)		/* helper is also the main task */
@@ -395,7 +366,6 @@
  * configuration vars for dumpsys
  */
 typedef struct dumpcfg {
-	int	threshold;	/* ncpu threshold for bzip2 */
 	int	nhelper;	/* number of helpers */
 	int	nhelper_used;	/* actual number of helpers used */
 	int	ncmap;		/* number VA pages for compression */
@@ -502,6 +472,9 @@
 
 /*
  * dump_update_clevel is called when dumpadm configures the dump device.
+ *	Determine the compression level / type
+ *	- DUMP_CLEVEL_SERIAL is single threaded lzjb
+ *	- DUMP_CLEVEL_LZJB   is parallel lzjb
  *	Calculate number of helpers and buffers.
  *	Allocate the minimum configuration for now.
  *
@@ -514,33 +487,6 @@
  *
  * Live dump (savecore -L) always uses the minimum config.
  *
- * clevel 0 is single threaded lzjb
- * clevel 1 is parallel lzjb
- * clevel 2 is parallel bzip2
- *
- * The ncpu threshold is selected with dump_plat_mincpu.
- * On OPL, set_platform_defaults() overrides the sun4u setting.
- * The actual values are defined via DUMP_PLAT_*_MINCPU macros.
- *
- * Architecture		Threshold	Algorithm
- * sun4u		<  51		parallel lzjb
- * sun4u		>= 51		parallel bzip2(*)
- * sun4u OPL		<  8		parallel lzjb
- * sun4u OPL		>= 8		parallel bzip2(*)
- * sun4v		<  128		parallel lzjb
- * sun4v		>= 128		parallel bzip2(*)
- * x86			< 11		parallel lzjb
- * x86			>= 11		parallel bzip2(*)
- * 32-bit		N/A		single-threaded lzjb
- *
- * (*) bzip2 is only chosen if there is sufficient available
- * memory for buffers at dump time. See dumpsys_get_maxmem().
- *
- * Faster dump devices have larger I/O buffers. The threshold value is
- * increased according to the size of the dump I/O buffer, because
- * parallel lzjb performs better with faster disks. For buffers >= 1MB
- * the threshold is 3X; for buffers >= 256K threshold is 2X.
- *
  * For parallel dumps, the number of helpers is ncpu-1. The CPU
  * running panic runs the main task. For single-threaded dumps, the
  * panic CPU does lzjb compression (it is tagged as MAINHELPER.)
@@ -556,7 +502,6 @@
 dump_update_clevel()
 {
 	int tag;
-	size_t bz2size;
 	helper_t *hp, *hpend;
 	cbuf_t *cp, *cpend;
 	dumpcfg_t *old = &dumpcfg;
@@ -609,31 +554,14 @@
 	if (new->nhelper > DUMP_MAX_NHELPER)
 		new->nhelper = DUMP_MAX_NHELPER;
 
-	/* use platform default, unless /etc/system overrides */
-	if (dump_plat_mincpu == MINCPU_NOT_SET)
-		dump_plat_mincpu = dump_plat_mincpu_default;
-
-	/* increase threshold for faster disks */
-	new->threshold = dump_plat_mincpu;
-	if (dumpbuf.iosize >= DUMP_1MB)
-		new->threshold *= 3;
-	else if (dumpbuf.iosize >= (256 * DUMP_1KB))
-		new->threshold *= 2;
-
-	/* figure compression level based upon the computed threshold. */
-	if (dump_plat_mincpu == 0 || new->nhelper < 2) {
-		new->clevel = 0;
+	/* If dump_ncpu_low is 0 or greater than ncpus, do serial dump */
+	if (dump_ncpu_low == 0 || dump_ncpu_low > ncpus || new->nhelper < 2) {
+		new->clevel = DUMP_CLEVEL_SERIAL;
 		new->nhelper = 1;
-	} else if ((new->nhelper + 1) >= new->threshold) {
-		new->clevel = DUMP_CLEVEL_BZIP2;
-	} else {
-		new->clevel = DUMP_CLEVEL_LZJB;
-	}
-
-	if (new->clevel == 0) {
 		new->ncbuf = 1;
 		new->ncmap = 1;
 	} else {
+		new->clevel = DUMP_CLEVEL_LZJB;
 		new->ncbuf = NCBUF_PER_HELPER * new->nhelper;
 		new->ncmap = NCMAP_PER_HELPER * new->nhelper;
 	}
@@ -642,7 +570,6 @@
 	 * Allocate new data structures and buffers for MINHELPERS,
 	 * and also figure the max desired size.
 	 */
-	bz2size = BZ2_bzCompressInitSize(dump_bzip2_level);
 	new->maxsize = 0;
 	new->maxvmsize = 0;
 	new->maxvm = NULL;
@@ -654,13 +581,9 @@
 		if (hp < &new->helper[MINHELPERS]) {
 			hp->lzbuf = kmem_alloc(PAGESIZE, KM_SLEEP);
 			hp->page = kmem_alloc(PAGESIZE, KM_SLEEP);
-		} else if (new->clevel < DUMP_CLEVEL_BZIP2) {
+		} else  {
 			new->maxsize += 2 * PAGESIZE;
-		} else {
-			new->maxsize += PAGESIZE;
 		}
-		if (new->clevel >= DUMP_CLEVEL_BZIP2)
-			new->maxsize += bz2size;
 	}
 
 	new->cbuf = kmem_zalloc(new->ncbuf * sizeof (cbuf_t), KM_SLEEP);
@@ -825,31 +748,6 @@
 }
 
 /*
- * dumpbzalloc and dumpbzfree are callbacks from the bzip2 library.
- * dumpsys_get_maxmem() uses them for BZ2_bzCompressInit().
- */
-static void *
-dumpbzalloc(void *opaque, int items, int size)
-{
-	size_t *sz;
-	char *ret;
-
-	ASSERT(opaque != NULL);
-	sz = opaque;
-	ret = dumpcfg.maxvm + *sz;
-	*sz += items * size;
-	*sz = P2ROUNDUP(*sz, BZ2_BZALLOC_ALIGN);
-	ASSERT(*sz <= dumpcfg.maxvmsize);
-	return (ret);
-}
-
-/*ARGSUSED*/
-static void
-dumpbzfree(void *opaque, void *addr)
-{
-}
-
-/*
  * Perform additional checks on the page to see if we can really use
  * it. The kernel (kas) pages are always set in the bitmap. However,
  * boot memory pages (prom_ppages or P_BOOTPAGES) are not in the
@@ -888,9 +786,7 @@
 
 /*
  * dumpsys_get_maxmem() is called during panic. Find unused ranges
- * and use them for buffers. If we find enough memory switch to
- * parallel bzip2, otherwise use parallel lzjb.
- *
+ * and use them for buffers.
  * It searches the dump bitmap in 2 passes. The first time it looks
  * for CBUF_MAPSIZE ranges. On the second pass it uses small pages.
  */
@@ -901,19 +797,18 @@
 	cbuf_t *endcp = &cfg->cbuf[cfg->ncbuf];
 	helper_t *endhp = &cfg->helper[cfg->nhelper];
 	pgcnt_t bitnum, end;
-	size_t sz, endsz, bz2size;
+	size_t sz, endsz;
 	pfn_t pfn, off;
 	cbuf_t *cp;
-	helper_t *hp, *ohp;
+	helper_t *hp;
 	dumpmlw_t mlw;
 	int k;
 
 	/*
-	 * Setting dump_plat_mincpu to 0 at any time forces a serial
-	 * dump.
+	 * Setting dump_ncpu_low to 0 forces a single threaded dump.
 	 */
-	if (dump_plat_mincpu == 0) {
-		cfg->clevel = 0;
+	if (dump_ncpu_low == 0) {
+		cfg->clevel = DUMP_CLEVEL_SERIAL;
 		return;
 	}
 
@@ -922,10 +817,8 @@
 	 * dumping all memory, then none is spare. If doing a serial
 	 * dump, then already have buffers.
 	 */
-	if (cfg->maxsize == 0 || cfg->clevel < DUMP_CLEVEL_LZJB ||
+	if (cfg->maxsize == 0 || cfg->clevel == DUMP_CLEVEL_SERIAL ||
 	    (dump_conflags & DUMP_ALL) != 0) {
-		if (cfg->clevel > DUMP_CLEVEL_LZJB)
-			cfg->clevel = DUMP_CLEVEL_LZJB;
 		return;
 	}
 
@@ -1009,12 +902,6 @@
 		}
 	}
 
-	/* Fall back to lzjb if we did not get enough memory for bzip2. */
-	endsz = (cfg->maxsize * cfg->threshold) / cfg->nhelper;
-	if (sz < endsz) {
-		cfg->clevel = DUMP_CLEVEL_LZJB;
-	}
-
 	/* Allocate memory for as many helpers as we can. */
 foundmax:
 
@@ -1022,42 +909,21 @@
 	endsz = sz;
 	sz = 0;
 
-	/* Set the size for bzip2 state. Only bzip2 needs it. */
-	bz2size = BZ2_bzCompressInitSize(dump_bzip2_level);
-
 	/* Skip the preallocate output buffers. */
 	cp = &cfg->cbuf[MINCBUFS];
 
-	/* Use this to move memory up from the preallocated helpers. */
-	ohp = cfg->helper;
-
 	/* Loop over all helpers and allocate memory. */
 	for (hp = cfg->helper; hp < endhp; hp++) {
 
 		/* Skip preallocated helpers by checking hp->page. */
 		if (hp->page == NULL) {
-			if (cfg->clevel <= DUMP_CLEVEL_LZJB) {
-				/* lzjb needs 2 1-page buffers */
-				if ((sz + (2 * PAGESIZE)) > endsz)
-					break;
-				hp->page = cfg->maxvm + sz;
-				sz += PAGESIZE;
-				hp->lzbuf = cfg->maxvm + sz;
-				sz += PAGESIZE;
-
-			} else if (ohp->lzbuf != NULL) {
-				/* re-use the preallocted lzjb page for bzip2 */
-				hp->page = ohp->lzbuf;
-				ohp->lzbuf = NULL;
-				++ohp;
-
-			} else {
-				/* bzip2 needs a 1-page buffer */
-				if ((sz + PAGESIZE) > endsz)
-					break;
-				hp->page = cfg->maxvm + sz;
-				sz += PAGESIZE;
-			}
+			/* lzjb needs 2 1-page buffers */
+			if ((sz + (2 * PAGESIZE)) > endsz)
+				break;
+			hp->page = cfg->maxvm + sz;
+			sz += PAGESIZE;
+			hp->lzbuf = cfg->maxvm + sz;
+			sz += PAGESIZE;
 		}
 
 		/*
@@ -1073,25 +939,6 @@
 			sz += CBUF_SIZE;
 			++cp;
 		}
-
-		/*
-		 * bzip2 needs compression state. Use the dumpbzalloc
-		 * and dumpbzfree callbacks to allocate the memory.
-		 * bzip2 does allocation only at init time.
-		 */
-		if (cfg->clevel >= DUMP_CLEVEL_BZIP2) {
-			if ((sz + bz2size) > endsz) {
-				hp->page = NULL;
-				break;
-			} else {
-				hp->bzstream.opaque = &sz;
-				hp->bzstream.bzalloc = dumpbzalloc;
-				hp->bzstream.bzfree = dumpbzfree;
-				(void) BZ2_bzCompressInit(&hp->bzstream,
-				    dump_bzip2_level, 0, 0);
-				hp->bzstream.opaque = NULL;
-			}
-		}
 	}
 
 	/* Finish allocating output buffers */
@@ -1947,136 +1794,6 @@
 }
 
 /*
- * Compress size bytes starting at buf with bzip2
- * mode:
- *	BZ_RUN		add one more compressed page
- *	BZ_FINISH	no more input, flush the state
- */
-static void
-dumpsys_bzrun(helper_t *hp, void *buf, size_t size, int mode)
-{
-	dumpsync_t *ds = hp->ds;
-	const int CSIZE = sizeof (dumpcsize_t);
-	bz_stream *ps = &hp->bzstream;
-	int rc = 0;
-	uint32_t csize;
-	dumpcsize_t cs;
-
-	/* Set input pointers to new input page */
-	if (size > 0) {
-		ps->avail_in = size;
-		ps->next_in = buf;
-	}
-
-	/* CONSTCOND */
-	while (1) {
-
-		/* Quit when all input has been consumed */
-		if (ps->avail_in == 0 && mode == BZ_RUN)
-			break;
-
-		/* Get a new output buffer */
-		if (hp->cpout == NULL) {
-			HRSTART(hp->perpage, outwait);
-			hp->cpout = CQ_GET(freebufq);
-			HRSTOP(hp->perpage, outwait);
-			ps->avail_out = hp->cpout->size - CSIZE;
-			ps->next_out = hp->cpout->buf + CSIZE;
-		}
-
-		/* Compress input, or finalize */
-		HRSTART(hp->perpage, compress);
-		rc = BZ2_bzCompress(ps, mode);
-		HRSTOP(hp->perpage, compress);
-
-		/* Check for error */
-		if (mode == BZ_RUN && rc != BZ_RUN_OK) {
-			dumpsys_errmsg(hp, "%d: BZ_RUN error %s at page %lx\n",
-			    hp->helper, BZ2_bzErrorString(rc),
-			    hp->cpin->pagenum);
-			break;
-		}
-
-		/* Write the buffer if it is full, or we are flushing */
-		if (ps->avail_out == 0 || mode == BZ_FINISH) {
-			csize = hp->cpout->size - CSIZE - ps->avail_out;
-			cs = DUMP_SET_TAG(csize, hp->tag);
-			if (csize > 0) {
-				(void) memcpy(hp->cpout->buf, &cs, CSIZE);
-				dumpsys_swrite(hp, hp->cpout, csize + CSIZE);
-				hp->cpout = NULL;
-			}
-		}
-
-		/* Check for final complete */
-		if (mode == BZ_FINISH) {
-			if (rc == BZ_STREAM_END)
-				break;
-			if (rc != BZ_FINISH_OK) {
-				dumpsys_errmsg(hp, "%d: BZ_FINISH error %s\n",
-				    hp->helper, BZ2_bzErrorString(rc));
-				break;
-			}
-		}
-	}
-
-	/* Cleanup state and buffers */
-	if (mode == BZ_FINISH) {
-
-		/* Reset state so that it is re-usable. */
-		(void) BZ2_bzCompressReset(&hp->bzstream);
-
-		/* Give any unused outout buffer to the main task */
-		if (hp->cpout != NULL) {
-			hp->cpout->used = 0;
-			CQ_PUT(mainq, hp->cpout, CBUF_ERRMSG);
-			hp->cpout = NULL;
-		}
-	}
-}
-
-static void
-dumpsys_bz2compress(helper_t *hp)
-{
-	dumpsync_t *ds = hp->ds;
-	dumpstreamhdr_t sh;
-
-	(void) strcpy(sh.stream_magic, DUMP_STREAM_MAGIC);
-	sh.stream_pagenum = (pgcnt_t)-1;
-	sh.stream_npages = 0;
-	hp->cpin = NULL;
-	hp->cpout = NULL;
-	hp->cperr = NULL;
-	hp->in = 0;
-	hp->out = 0;
-	hp->bzstream.avail_in = 0;
-
-	/* Bump reference to mainq while we are running */
-	CQ_OPEN(mainq);
-
-	/* Get one page at a time */
-	while (dumpsys_sread(hp)) {
-		if (sh.stream_pagenum != hp->cpin->pagenum) {
-			sh.stream_pagenum = hp->cpin->pagenum;
-			sh.stream_npages = btop(hp->cpin->used);
-			dumpsys_bzrun(hp, &sh, sizeof (sh), BZ_RUN);
-		}
-		dumpsys_bzrun(hp, hp->page, PAGESIZE, 0);
-	}
-
-	/* Done with input, flush any partial buffer */
-	if (sh.stream_pagenum != (pgcnt_t)-1) {
-		dumpsys_bzrun(hp, NULL, 0, BZ_FINISH);
-		dumpsys_errmsg(hp, NULL);
-	}
-
-	ASSERT(hp->cpin == NULL && hp->cpout == NULL && hp->cperr == NULL);
-
-	/* Decrement main queue count, we are done */
-	CQ_CLOSE(mainq);
-}
-
-/*
  * Compress with lzjb
  * write stream block if full or size==0
  * if csize==0 write stream header, else write <csize, data>
@@ -2218,14 +1935,8 @@
 			if (hp->helper == FREEHELPER) {
 				hp->helper = CPU->cpu_id;
 				BT_SET(dumpcfg.helpermap, CPU->cpu_seqid);
-
 				dumpsys_spinunlock(&dumpcfg.helper_lock);
-
-				if (dumpcfg.clevel < DUMP_CLEVEL_BZIP2)
-					dumpsys_lzjbcompress(hp);
-				else
-					dumpsys_bz2compress(hp);
-
+				dumpsys_lzjbcompress(hp);
 				hp->helper = DONEHELPER;
 				return;
 			}
@@ -2262,10 +1973,7 @@
 	helper_t *hp = arg;
 
 	BT_ATOMIC_SET(dumpcfg.helpermap, CPU->cpu_seqid);
-	if (dumpcfg.clevel < DUMP_CLEVEL_BZIP2)
-		dumpsys_lzjbcompress(hp);
-	else
-		dumpsys_bz2compress(hp);
+	dumpsys_lzjbcompress(hp);
 }
 
 /*
@@ -2312,12 +2020,11 @@
 	cbuf_t *cp;
 	pgcnt_t baseoff, pfnoff;
 	pfn_t base, pfn;
-	boolean_t dumpserial;
 	int i;
 
 	/*
 	 * Fall back to serial mode if there are no helpers.
-	 * dump_plat_mincpu can be set to 0 at any time.
+	 * dump_ncpu_low can be set to 0 at any time.
 	 * dumpcfg.helpermap must contain at least one member.
 	 *
 	 * It is possible that the helpers haven't registered
@@ -2324,8 +2031,8 @@
 	 * in helpermap yet; wait up to DUMP_HELPER_MAX_WAIT for
 	 * at least one helper to register.
 	 */
-	dumpserial = B_TRUE;
-	if (dump_plat_mincpu != 0 && dumpcfg.clevel != 0) {
+	if (dump_ncpu_low != 0 && dumpcfg.clevel != DUMP_CLEVEL_SERIAL) {
+		boolean_t dumpserial = B_TRUE;
 		hrtime_t hrtmax = MSEC2NSEC(DUMP_HELPER_MAX_WAIT);
 		hrtime_t hrtstart = gethrtime();
 
@@ -2346,7 +2053,7 @@
 		}
 
 		if (dumpserial) {
-			dumpcfg.clevel = 0;
+			dumpcfg.clevel = DUMP_CLEVEL_SERIAL;
 			if (dumpcfg.helper[0].lzbuf == NULL) {
 				dumpcfg.helper[0].lzbuf =
 				    dumpcfg.helper[1].page;
@@ -2494,7 +2201,7 @@
 			 * If there are no helpers the main task does
 			 * non-streams lzjb compress.
 			 */
-			if (dumpserial) {
+			if (dumpcfg.clevel == DUMP_CLEVEL_SERIAL) {
 				dumpsys_lzjb_page(dumpcfg.helper, cp);
 			} else {
 				/* pass mapped pages to a helper */
@@ -2605,12 +2312,8 @@
 	P("Found small pages,%ld\n", cfg->foundsm);
 
 	P("Compression level,%d\n", cfg->clevel);
-	P("Compression type,%s %s", cfg->clevel == 0 ? "serial" : "parallel",
-	    cfg->clevel >= DUMP_CLEVEL_BZIP2 ? "bzip2" : "lzjb");
-	if (cfg->clevel >= DUMP_CLEVEL_BZIP2)
-		P(" (level %d)\n", dump_bzip2_level);
-	else
-		P("\n");
+	P("Compression type,%s lzjb\n",
+	    cfg->clevel == DUMP_CLEVEL_SERIAL ? "serial" : "parallel");
 	P("Compression ratio,%d.%02d\n", compress_ratio / 100, compress_ratio %
 	    100);
 	P("nhelper_used,%d\n", cfg->nhelper_used);
@@ -2871,14 +2574,12 @@
 	dumphdr->dump_data = dumpvp_flush();
 
 	bzero(dumpcfg.helpermap, BT_SIZEOFMAP(NCPU));
-	ds->live = dumpcfg.clevel > 0 &&
+	ds->live = dumpcfg.clevel > DUMP_CLEVEL_SERIAL &&
 	    (dumphdr->dump_flags & DF_LIVE) != 0;
 
 	save_dump_clevel = dumpcfg.clevel;
 	if (panicstr)
 		dumpsys_get_maxmem();
-	else if (dumpcfg.clevel >= DUMP_CLEVEL_BZIP2)
-		dumpcfg.clevel = DUMP_CLEVEL_LZJB;
 
 	dumpcfg.nhelper_used = 0;
 	for (hp = dumpcfg.helper; hp != hpend; hp++) {
@@ -2891,8 +2592,6 @@
 		hp->taskqid = NULL;
 		hp->ds = ds;
 		bzero(&hp->perpage, sizeof (hp->perpage));
-		if (dumpcfg.clevel >= DUMP_CLEVEL_BZIP2)
-			(void) BZ2_bzCompressReset(&hp->bzstream);
 	}
 
 	CQ_OPEN(freebufq);
@@ -2930,7 +2629,7 @@
 	} else {
 		if (panicstr)
 			kmem_dump_begin();
-		dumpcfg.helpers_wanted = dumpcfg.clevel > 0;
+		dumpcfg.helpers_wanted = dumpcfg.clevel > DUMP_CLEVEL_SERIAL;
 		dumpsys_spinunlock(&dumpcfg.helper_lock);
 	}
 
--- old/usr/src/uts/common/sys/dumphdr.h	Wed Aug  8 01:12:27 2018
+++ new/usr/src/uts/common/sys/dumphdr.h	Wed Aug  8 01:12:27 2018
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
  * Copyright (c) 2016 by Delphix. All rights reserved.
  */
 
@@ -164,8 +165,8 @@
 #define	DUMP_DATAHDR_MAGIC	('d' << 24 | 'h' << 16 | 'd' << 8 | 'r')
 
 #define	DUMP_DATAHDR_VERSION	1
+#define	DUMP_CLEVEL_SERIAL	0	/* single-threaded lzjb compression */
 #define	DUMP_CLEVEL_LZJB	1	/* parallel lzjb compression */
-#define	DUMP_CLEVEL_BZIP2	2	/* parallel bzip2 level 1 */
 
 #ifdef _KERNEL
 
@@ -199,25 +200,6 @@
 extern const char *dump_get_uuid(void);
 
 /*
- * Define a CPU count threshold that determines when to employ
- * bzip2. This value is defined per-platform.
- */
-extern uint_t dump_plat_mincpu_default;
-
-#define	DUMP_PLAT_SUN4U_MINCPU		0
-#define	DUMP_PLAT_SUN4U_OPL_MINCPU	0
-#define	DUMP_PLAT_SUN4V_MINCPU		0
-#define	DUMP_PLAT_X86_64_MINCPU		0
-#define	DUMP_PLAT_X86_32_MINCPU		0
-
-/*
- * Override the per-platform default by setting this variable with
- * /etc/system.  The value 0 disables parallelism, and the old format
- * dump is produced.
- */
-extern uint_t dump_plat_mincpu;
-
-/*
  * Pages may be stolen at dump time. Prevent the pages from ever being
  * allocated while dump is running.
  */
--- old/usr/src/uts/i86pc/os/machdep.c	Wed Aug  8 01:12:27 2018
+++ new/usr/src/uts/i86pc/os/machdep.c	Wed Aug  8 01:12:27 2018
@@ -21,6 +21,7 @@
 
 /*
  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  * Copyright 2017, Joyent, Inc.
  */
 /*
@@ -1239,13 +1240,6 @@
 	return (npages);
 }
 
-/* cpu threshold for compressed dumps */
-#ifdef _LP64
-uint_t dump_plat_mincpu_default = DUMP_PLAT_X86_64_MINCPU;
-#else
-uint_t dump_plat_mincpu_default = DUMP_PLAT_X86_32_MINCPU;
-#endif
-
 int
 dump_plat_addr()
 {
--- old/usr/src/uts/sun4/os/machdep.c	Wed Aug  8 01:12:28 2018
+++ new/usr/src/uts/sun4/os/machdep.c	Wed Aug  8 01:12:28 2018
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2017, Joyent, Inc.  All rights reserved.
  */
 
@@ -836,13 +837,6 @@
 	return (ENOTSUP);
 }
 
-/* cpu threshold for compressed dumps */
-#ifdef sun4v
-uint_t dump_plat_mincpu_default = DUMP_PLAT_SUN4V_MINCPU;
-#else
-uint_t dump_plat_mincpu_default = DUMP_PLAT_SUN4U_MINCPU;
-#endif
-
 int
 dump_plat_addr()
 {
--- old/usr/src/uts/sun4/os/startup.c	Wed Aug  8 01:12:28 2018
+++ new/usr/src/uts/sun4/os/startup.c	Wed Aug  8 01:12:28 2018
@@ -22,6 +22,7 @@
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  */
 
 #include <sys/machsystm.h>
@@ -630,7 +631,7 @@
 	/*
 	 * Force a serial dump, since there are no CPUs to help.
 	 */
-	dump_plat_mincpu = 0;
+	dump_ncpu_low = 0;
 
 	/*
 	 * We've managed to get here without going through the
@@ -2438,7 +2439,7 @@
  */
 static void
 memlist_add(uint64_t start, uint64_t len, struct memlist **memlistp,
-	struct memlist **curmemlistp)
+    struct memlist **curmemlistp)
 {
 	struct memlist *new = *memlistp;
 
--- old/usr/src/uts/sun4u/opl/os/opl.c	Wed Aug  8 01:12:28 2018
+++ new/usr/src/uts/sun4u/opl/os/opl.c	Wed Aug  8 01:12:28 2018
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  */
 
 #include <sys/cpuvar.h>
@@ -221,9 +222,6 @@
 	tsb_lgrp_affinity = 1;
 
 	set_max_mmu_ctxdoms();
-
-	/* set OPL threshold for compressed dumps */
-	dump_plat_mincpu_default = DUMP_PLAT_SUN4U_OPL_MINCPU;
 }
 
 /*
@@ -861,8 +859,7 @@
 /*ARGSUSED*/
 int
 plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
-	int flt_in_memory, ushort_t flt_status,
-	char *buf, int buflen, int *lenp)
+    int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
 {
 	/*
 	 * check if it's a Memory error.
