#include <algorithm>
#include <optional>
#include <string>
+#include <thread>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
-X, --recompress LEVEL recompress the cache to level LEVEL (integer or
"uncompressed") using the Zstandard algorithm;
see "Cache compression" in the manual for details
+ --recompress-threads THREADS
+ use up to THREADS threads when recompressing the
+ cache; default: number of CPUs
-o, --set-config KEY=VAL set configuration item KEY to value VAL
-x, --show-compression show compression statistics
-p, --show-config show current configuration options in
HASH_FILE,
INSPECT,
PRINT_STATS,
+ RECOMPRESS_THREADS,
SHOW_LOG_STATS,
TRIM_DIR,
TRIM_MAX_SIZE,
{"max-size", required_argument, nullptr, 'M'},
{"print-stats", no_argument, nullptr, PRINT_STATS},
{"recompress", required_argument, nullptr, 'X'},
+ {"recompress-threads", required_argument, nullptr, RECOMPRESS_THREADS},
{"set-config", required_argument, nullptr, 'o'},
{"show-compression", no_argument, nullptr, 'x'},
{"show-config", no_argument, nullptr, 'p'},
uint8_t verbosity = 0;
std::optional<std::string> evict_namespace;
std::optional<uint64_t> evict_max_age;
+ uint32_t recompress_threads = std::thread::hardware_concurrency();
// First pass: Handle non-command options that affect command options.
while ((c = getopt_long(argc,
Util::setenv("CCACHE_CONFIGPATH", arg);
break;
+ case RECOMPRESS_THREADS:
+ recompress_threads = util::value_or_throw<Error>(util::parse_unsigned(
+ arg, 1, std::numeric_limits<uint32_t>::max(), "threads"));
+ break;
+
case TRIM_MAX_SIZE:
trim_max_size = Util::parse_size(arg);
break;
switch (c) {
case CONFIG_PATH:
case 'd': // --dir
+ case RECOMPRESS_THREADS:
case TRIM_MAX_SIZE:
case TRIM_METHOD:
case 'v': // --verbose
ProgressBar progress_bar("Recompressing...");
storage::local::LocalStorage(config).recompress(
- wanted_level, [&](double progress) { progress_bar.update(progress); });
+ wanted_level, recompress_threads, [&](double progress) {
+ progress_bar.update(progress);
+ });
break;
}
#include <memory>
#include <string>
-#include <thread>
namespace storage::local {
void
LocalStorage::recompress(const std::optional<int8_t> level,
+ const uint32_t threads,
const ProgressReceiver& progress_receiver)
{
- const size_t threads = std::thread::hardware_concurrency();
- const size_t read_ahead = 2 * threads;
+ const size_t read_ahead =
+ std::max(static_cast<size_t>(10), 2 * static_cast<size_t>(threads));
ThreadPool thread_pool(threads, read_ahead);
RecompressionStatistics statistics;