Best throughput tracker with chunksize
This commit is contained in:
+48
-4
@@ -16,9 +16,28 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <chrono>
|
||||
|
||||
#define CHUNK_SIZE 1024 * 1024 * 32 // amount of bytes that are overwritten at once --> 32MB
|
||||
#define TFNG_DATA_SIZE CHUNK_SIZE // amount of bytes used by tfng
|
||||
// Adaptive chunk size optimization - uncomment to enable
|
||||
#define ADAPTIVE_CHUNK_SIZE
|
||||
|
||||
// Chunk size configuration
|
||||
#define CHUNK_SIZE_START 1024 * 1024 * 32 // Starting chunk size: 32MB
|
||||
#define CHUNK_SIZE_MIN 1024 * 1024 * 4 // Minimum chunk size: 4MB
|
||||
#define CHUNK_SIZE_MAX 1024 * 1024 * 128 // Maximum chunk size: 128MB
|
||||
#define CHUNK_SIZE_STEP_UP 1024 * 1024 * 2 // Increase step: 2MB
|
||||
#define CHUNK_SIZE_STEP_DOWN 1024 * 1024 * 4 // Decrease step: 4MB
|
||||
#define CHUNK_MEASURE_INTERVAL 64 // Measure performance every 64 chunks
|
||||
|
||||
#ifdef ADAPTIVE_CHUNK_SIZE
|
||||
// Use max buffer size when adaptive mode is enabled
|
||||
#define CHUNK_SIZE CHUNK_SIZE_MAX
|
||||
#define TFNG_DATA_SIZE CHUNK_SIZE_MAX
|
||||
#else
|
||||
// Use fixed chunk size when adaptive mode is disabled
|
||||
#define CHUNK_SIZE CHUNK_SIZE_START
|
||||
#define TFNG_DATA_SIZE CHUNK_SIZE
|
||||
#endif
|
||||
|
||||
// #define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB
|
||||
// #define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB
|
||||
@@ -33,22 +52,47 @@ protected:
|
||||
public:
|
||||
Shred();
|
||||
~Shred();
|
||||
int shredDrive(Drive *drive, int *ipSignalFd);
|
||||
int shredDrive(Drive* drive, int* ipSignalFd);
|
||||
|
||||
private:
|
||||
fileDescriptor randomSrcFileDiscr;
|
||||
fileDescriptor driveFileDiscr;
|
||||
|
||||
#ifdef ADAPTIVE_CHUNK_SIZE
|
||||
unsigned char* caTfngData; // Dynamic buffer allocation for adaptive mode
|
||||
unsigned char* caReadBuffer; // Dynamic buffer allocation for adaptive mode
|
||||
#else
|
||||
unsigned char caTfngData[TFNG_DATA_SIZE];
|
||||
unsigned char caReadBuffer[CHUNK_SIZE];
|
||||
#endif
|
||||
|
||||
unsigned long ulDriveByteSize;
|
||||
unsigned long ulDriveByteOverallCount = 0; // all bytes shredded in all iterations + checking -> used for progress calculation
|
||||
double d32Percent = 0.0;
|
||||
double d32TmpPercent = 0.0;
|
||||
|
||||
#ifdef ADAPTIVE_CHUNK_SIZE
|
||||
// Adaptive chunk size optimization members
|
||||
size_t currentChunkSize;
|
||||
size_t bestChunkSize;
|
||||
unsigned int chunkCounter;
|
||||
std::chrono::high_resolution_clock::time_point measurementStartTime;
|
||||
double bestThroughputMBps;
|
||||
double lastThroughputMBps;
|
||||
unsigned long bytesWrittenInMeasurement;
|
||||
bool throughputIncreasing;
|
||||
|
||||
// Adaptive methods
|
||||
void startMeasurement();
|
||||
void evaluateThroughput(Drive* drive);
|
||||
void adjustChunkSize(Drive* drive);
|
||||
size_t getCurrentChunkSize() const;
|
||||
#endif
|
||||
|
||||
inline double calcProgress();
|
||||
int iRewindDrive(fileDescriptor file);
|
||||
long getDriveSizeInBytes(fileDescriptor file);
|
||||
unsigned int uiCalcChecksum(fileDescriptor file, Drive *drive, int *ipSignalFd);
|
||||
unsigned int uiCalcChecksum(fileDescriptor file, Drive* drive, int* ipSignalFd);
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user