mirror of
https://review.haiku-os.org/haiku
synced 2025-02-12 08:39:18 +01:00
Zstd wants a ~90 KB scratch buffer to decompress our 64 KB chunks. Rather than let it allocate that itself every time, pass in a 2*64KB "scratch" buffer and statically allocate the working memory from it. Pass it down using iovecs, and pass down the other buffers in the same way, to reduce parameters. Further, rework the object_cache used for heap decompression buffers to contain objects sized as 4x64KB, so we only need to do one allocation and deallocation for the compression/decompression and scratch buffers. Set the minimum reserve to 1 so that the low-memory manager doesn't reclaim this, as we'll need it when reading back data. Improves packagefs I/O performance (and thus boot speeds at least a bit, it appears.) Change-Id: Id51f6f598b33b9d757a283184c533bb97049529f Reviewed-on: https://review.haiku-os.org/c/haiku/+/8717 Reviewed-by: waddlesplash <waddlesplash@gmail.com> Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
93 lines
2.5 KiB
C++
93 lines
2.5 KiB
C++
/*
|
|
* Copyright 2017, Jérôme Duval.
|
|
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _ZSTD_COMPRESSION_ALGORITHM_H_
|
|
#define _ZSTD_COMPRESSION_ALGORITHM_H_
|
|
|
|
|
|
#include <CompressionAlgorithm.h>
|
|
|
|
|
|
// compression level
|
|
enum {
|
|
B_ZSTD_COMPRESSION_NONE = 0,
|
|
B_ZSTD_COMPRESSION_FASTEST = 1,
|
|
B_ZSTD_COMPRESSION_BEST = 22,
|
|
B_ZSTD_COMPRESSION_DEFAULT = 4,
|
|
};
|
|
|
|
|
|
class BZstdCompressionParameters : public BCompressionParameters {
|
|
public:
|
|
BZstdCompressionParameters(
|
|
int compressionLevel
|
|
= B_ZSTD_COMPRESSION_DEFAULT);
|
|
virtual ~BZstdCompressionParameters();
|
|
|
|
int32 CompressionLevel() const;
|
|
void SetCompressionLevel(int32 level);
|
|
|
|
size_t BufferSize() const;
|
|
void SetBufferSize(size_t size);
|
|
|
|
private:
|
|
int32 fCompressionLevel;
|
|
size_t fBufferSize;
|
|
};
|
|
|
|
|
|
class BZstdDecompressionParameters : public BDecompressionParameters {
|
|
public:
|
|
BZstdDecompressionParameters();
|
|
virtual ~BZstdDecompressionParameters();
|
|
|
|
size_t BufferSize() const;
|
|
void SetBufferSize(size_t size);
|
|
|
|
private:
|
|
size_t fBufferSize;
|
|
};
|
|
|
|
|
|
class BZstdCompressionAlgorithm : public BCompressionAlgorithm {
|
|
public:
|
|
BZstdCompressionAlgorithm();
|
|
virtual ~BZstdCompressionAlgorithm();
|
|
|
|
virtual status_t CreateCompressingInputStream(BDataIO* input,
|
|
const BCompressionParameters* parameters,
|
|
BDataIO*& _stream);
|
|
virtual status_t CreateCompressingOutputStream(BDataIO* output,
|
|
const BCompressionParameters* parameters,
|
|
BDataIO*& _stream);
|
|
virtual status_t CreateDecompressingInputStream(BDataIO* input,
|
|
const BDecompressionParameters* parameters,
|
|
BDataIO*& _stream);
|
|
virtual status_t CreateDecompressingOutputStream(BDataIO* output,
|
|
const BDecompressionParameters* parameters,
|
|
BDataIO*& _stream);
|
|
|
|
virtual status_t CompressBuffer(const iovec& input, iovec& output,
|
|
const BCompressionParameters* parameters = NULL,
|
|
iovec* scratch = NULL);
|
|
virtual status_t DecompressBuffer(const iovec& input, iovec& output,
|
|
const BDecompressionParameters* parameters = NULL,
|
|
iovec* scratch = NULL);
|
|
|
|
private:
|
|
struct CompressionStrategy;
|
|
struct DecompressionStrategy;
|
|
|
|
template<typename BaseClass, typename Strategy, typename StreamType> struct Stream;
|
|
template<typename BaseClass, typename Strategy, typename StreamType>
|
|
friend struct Stream;
|
|
|
|
private:
|
|
static status_t _TranslateZstdError(size_t error);
|
|
};
|
|
|
|
|
|
#endif // _ZSTD_COMPRESSION_ALGORITHM_H_
|