mirror of
https://review.haiku-os.org/haiku
synced 2025-01-31 10:47:14 +01:00
f44cb411cc
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>
118 lines
3.0 KiB
C++
118 lines
3.0 KiB
C++
/*
|
|
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _COMPRESSION_ALGORITHM_H_
|
|
#define _COMPRESSION_ALGORITHM_H_
|
|
|
|
|
|
#include <DataIO.h>
|
|
#include <sys/uio.h>
|
|
|
|
|
|
class BCompressionParameters {
|
|
public:
|
|
BCompressionParameters();
|
|
virtual ~BCompressionParameters();
|
|
};
|
|
|
|
|
|
class BDecompressionParameters {
|
|
public:
|
|
BDecompressionParameters();
|
|
virtual ~BDecompressionParameters();
|
|
};
|
|
|
|
|
|
class BCompressionAlgorithm {
|
|
public:
|
|
BCompressionAlgorithm();
|
|
virtual ~BCompressionAlgorithm();
|
|
|
|
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);
|
|
|
|
protected:
|
|
class BAbstractStream;
|
|
class BAbstractInputStream;
|
|
class BAbstractOutputStream;
|
|
};
|
|
|
|
|
|
class BCompressionAlgorithm::BAbstractStream : public BDataIO {
|
|
public:
|
|
BAbstractStream();
|
|
virtual ~BAbstractStream();
|
|
|
|
status_t Init(size_t bufferSize);
|
|
|
|
protected:
|
|
virtual status_t ProcessData(const void* input, size_t inputSize,
|
|
void* output, size_t outputSize,
|
|
size_t& bytesConsumed,
|
|
size_t& bytesProduced) = 0;
|
|
// must consume or produce at least 1 byte
|
|
// or return an error
|
|
virtual status_t FlushPendingData(void* output,
|
|
size_t outputSize,
|
|
size_t& bytesProduced) = 0;
|
|
|
|
protected:
|
|
uint8* fBuffer;
|
|
size_t fBufferCapacity;
|
|
size_t fBufferOffset;
|
|
size_t fBufferSize;
|
|
};
|
|
|
|
|
|
class BCompressionAlgorithm::BAbstractInputStream : public BAbstractStream {
|
|
public:
|
|
BAbstractInputStream(BDataIO* input);
|
|
virtual ~BAbstractInputStream();
|
|
|
|
virtual ssize_t Read(void* buffer, size_t size);
|
|
|
|
private:
|
|
BDataIO* fInput;
|
|
bool fEndOfInput;
|
|
bool fNoMorePendingData;
|
|
};
|
|
|
|
|
|
class BCompressionAlgorithm::BAbstractOutputStream : public BAbstractStream {
|
|
public:
|
|
BAbstractOutputStream(BDataIO* output);
|
|
virtual ~BAbstractOutputStream();
|
|
|
|
virtual ssize_t Write(const void* buffer, size_t size);
|
|
|
|
virtual status_t Flush();
|
|
|
|
private:
|
|
ssize_t _Write(const void* buffer, size_t size,
|
|
bool flush);
|
|
|
|
private:
|
|
BDataIO* fOutput;
|
|
};
|
|
|
|
|
|
#endif // _COMPRESSION_ALGORITHM_H_
|