1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-07-02 12:52:38 +00:00

Added option --backend-devices-keepfree to configure X percentage of device memory available to keep free

This commit is contained in:
Jens Steube 2025-06-04 10:13:29 +02:00
parent 3d4901a60c
commit d60658102b
6 changed files with 37 additions and 8 deletions

View File

@ -66,6 +66,7 @@
- Added new feature (-Y) that creates N virtual instances for each device in your system at the cost of N times the device memory consumption
- Added options --benchmark-min and --benchmark-max to set a hash-mode range to be used during the benchmark
- Added option --backend-devices-keepfree to configure X percentage of device memory available to keep free
##
## Performance

View File

@ -426,8 +426,8 @@ _hashcat ()
local BUILD_IN_CHARSETS='?l ?u ?d ?a ?b ?s ?h ?H'
local SHORT_OPTS="-m -a -V -h -b -t -T -o -p -c -d -D -w -n -u -j -k -r -g -1 -2 -3 -4 -i -I -s -l -O -S -z -M -Y -R"
local LONG_OPTS="--hash-type --attack-mode --version --help --quiet --benchmark --benchmark-all --hex-salt --hex-wordlist --hex-charset --force --status --status-json --status-timer --stdin-timeout-abort --machine-readable --loopback --markov-hcstat2 --markov-disable --markov-inverse --markov-classic --markov-threshold --runtime --session --speed-only --progress-only --restore --restore-file-path --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-json --outfile-check-timer --outfile-check-dir --wordlist-autohex-disable --separator --show --deprecated-check-disable --left --username --dynamic-x --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --example-hashes --hash-info --backend-ignore-cuda --backend-ignore-opencl --backend-ignore-hip --backend-ignore-metal --backend-info --backend-devices --backend-devices-virtmulti --backend-devices-virthost --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-disable --hwmon-temp-abort --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-func-sel --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --stdout --keep-guessing --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --optimized-kernel-enable --multiply-accel-disable --self-test-disable --slow-candidates --brain-server --brain-server-timer --brain-client --brain-client-features --brain-host --brain-port --brain-session --brain-session-whitelist --brain-password --identify --bridge-parameter1 --bridge-parameter2 --bridge-parameter3 --bridge-parameter4"
local OPTIONS="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --status-timer --stdin-timeout-abort --markov-hcstat2 --markov-threshold --runtime --session --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --restore-file-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --backend-devices --backend-devices-virtmulti --backend-devices-virthost --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-temp-abort --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-func-sel --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment-min --increment-max --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --brain-server-timer --brain-client-features --brain-host --brain-password --brain-port --brain-session --brain-session-whitelist --bridge-parameter1 --bridge-parameter2 --bridge-parameter3 --bridge-parameter4"
local LONG_OPTS="--hash-type --attack-mode --version --help --quiet --benchmark --benchmark-all --hex-salt --hex-wordlist --hex-charset --force --status --status-json --status-timer --stdin-timeout-abort --machine-readable --loopback --markov-hcstat2 --markov-disable --markov-inverse --markov-classic --markov-threshold --runtime --session --speed-only --progress-only --restore --restore-file-path --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-json --outfile-check-timer --outfile-check-dir --wordlist-autohex-disable --separator --show --deprecated-check-disable --left --username --dynamic-x --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --example-hashes --hash-info --backend-ignore-cuda --backend-ignore-opencl --backend-ignore-hip --backend-ignore-metal --backend-info --backend-devices --backend-devices-virtmulti --backend-devices-virthost --backend-devices-keepfree --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-disable --hwmon-temp-abort --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-func-sel --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --stdout --keep-guessing --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --optimized-kernel-enable --multiply-accel-disable --self-test-disable --slow-candidates --brain-server --brain-server-timer --brain-client --brain-client-features --brain-host --brain-port --brain-session --brain-session-whitelist --brain-password --identify --bridge-parameter1 --bridge-parameter2 --bridge-parameter3 --bridge-parameter4"
local OPTIONS="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --status-timer --stdin-timeout-abort --markov-hcstat2 --markov-threshold --runtime --session --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --restore-file-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --backend-devices --backend-devices-virtmulti --backend-devices-virthost --backend-devices-keepfree --opencl-device-types --backend-vector-width --workload-profile --kernel-accel --kernel-loops --kernel-threads --spin-damp --hwmon-temp-abort --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-func-sel --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --hook-threads --increment-min --increment-max --scrypt-tmto --keyboard-layout-mapping --truecrypt-keyfiles --veracrypt-keyfiles --veracrypt-pim-start --veracrypt-pim-stop --hccapx-message-pair --nonce-error-corrections --encoding-from --encoding-to --brain-server-timer --brain-client-features --brain-host --brain-password --brain-port --brain-session --brain-session-whitelist --bridge-parameter1 --bridge-parameter2 --bridge-parameter3 --bridge-parameter4"
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"

View File

@ -670,6 +670,7 @@ typedef enum user_options_defaults
AUTODETECT = false,
BACKEND_DEVICES_VIRTMULTI = 1,
BACKEND_DEVICES_VIRTHOST = 1,
BACKEND_DEVICES_KEEPFREE = 20,
BENCHMARK_ALL = false,
BENCHMARK_MAX = 99999,
BENCHMARK_MIN = 0,
@ -777,6 +778,7 @@ typedef enum user_options_map
IDX_BACKEND_DEVICES = 'd',
IDX_BACKEND_DEVICES_VIRTMULTI = 'Y',
IDX_BACKEND_DEVICES_VIRTHOST = 'R',
IDX_BACKEND_DEVICES_KEEPFREE = 0xff60,
IDX_BACKEND_IGNORE_CUDA = 0xff01,
IDX_BACKEND_IGNORE_HIP = 0xff02,
IDX_BACKEND_IGNORE_METAL = 0xff03,
@ -1954,6 +1956,7 @@ typedef struct backend_ctx
int backend_devices_cnt;
int backend_devices_virtmulti;
int backend_devices_virthost;
int backend_devices_keepfree;
int backend_devices_active;
int cuda_devices_cnt;
@ -2486,6 +2489,7 @@ typedef struct user_options
u32 attack_mode;
u32 backend_devices_virtmulti;
u32 backend_devices_virthost;
u32 backend_devices_keepfree;
u32 backend_info;
u32 benchmark_max;
u32 benchmark_min;

View File

@ -5608,7 +5608,7 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
continue;
}
device_param->device_available_mem = (u64) free;
device_param->device_available_mem = ((u64) free * (100 - user_options->backend_devices_keepfree)) / 100;
if (hc_cuCtxPopCurrent (hashcat_ctx, &cuda_context) == -1)
{
@ -6037,7 +6037,7 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
continue;
}
device_param->device_available_mem = (u64) free;
device_param->device_available_mem = ((u64) free * (100 - user_options->backend_devices_keepfree)) / 100;
if (hc_hipCtxPopCurrent (hashcat_ctx, &hip_context) == -1)
{
@ -8116,7 +8116,13 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
device_param->device_available_mem = device_param->device_global_mem - MAX_ALLOC_CHECKS_SIZE;
if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
if (user_options->backend_devices_keepfree)
{
device_param->device_available_mem = (device_param->device_global_mem * (100 - user_options->backend_devices_keepfree)) / 100;
}
// this section is creating more problems than it solves, so lets use a fixed multiplier instead
// users can override with --backend-devices-keepfree=0
else if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && (device_param->device_host_unified_memory == 0))
{
// following the same logic as for OpenCL, explained later
@ -8341,8 +8347,13 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
device_param->device_available_mem = device_param->device_global_mem - MAX_ALLOC_CHECKS_SIZE;
if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) &&
(((device_param->opencl_platform_vendor_id != VENDOR_ID_INTEL_SDK) && (device_param->opencl_platform_vendor_id != VENDOR_ID_MICROSOFT) && (device_param->opencl_platform_vendor_id != VENDOR_ID_GENERIC)) || (device_param->device_host_unified_memory == 0)))
if (user_options->backend_devices_keepfree)
{
device_param->device_available_mem = (device_param->device_global_mem * (100 - user_options->backend_devices_keepfree)) / 100;
}
// this section is creating more problems than it solves, so lets use a fixed multiplier instead
// users can override with --backend-devices-keepfree=0
else if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) && (device_param->device_host_unified_memory == 0))
{
// OK, so the problem here is the following:
// There's just CL_DEVICE_GLOBAL_MEM_SIZE to ask OpenCL about the total memory on the device,

View File

@ -110,6 +110,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] =
" -d, --backend-devices | Str | Backend devices to use, separated with commas | -d 1",
" -Y, --backend-devices-virtmulti| Num | Spawn X virtual instances on a real device | -Y 8",
" -R, --backend-devices-virthost | Num | Sets the real device to create virtual instances | -R 1",
" --backend-devices-keepfree | Num | Keep specified percentage of device memory free | --backend-devices-keepfree=5",
" -D, --opencl-device-types | Str | OpenCL device-types to use, separated with commas | -D 1",
" -O, --optimized-kernel-enable | | Enable optimized kernels (limits password length) |",
" -M, --multiply-accel-disable | | Disable multiply kernel-accel with processor count |",

View File

@ -34,7 +34,8 @@ static const struct option long_options[] =
{"attack-mode", required_argument, NULL, IDX_ATTACK_MODE},
{"backend-devices", required_argument, NULL, IDX_BACKEND_DEVICES},
{"backend-devices-virtmulti", required_argument, NULL, IDX_BACKEND_DEVICES_VIRTMULTI},
{"backend-devices-virthost", required_argument, NULL, IDX_BACKEND_DEVICES_VIRTHOST},
{"backend-devices-virthost", required_argument, NULL, IDX_BACKEND_DEVICES_VIRTHOST},
{"backend-devices-keepfree", required_argument, NULL, IDX_BACKEND_DEVICES_KEEPFREE},
{"backend-ignore-cuda", no_argument, NULL, IDX_BACKEND_IGNORE_CUDA},
{"backend-ignore-hip", no_argument, NULL, IDX_BACKEND_IGNORE_HIP},
#if defined (__APPLE__)
@ -184,6 +185,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx)
user_options->backend_devices = NULL;
user_options->backend_devices_virtmulti = BACKEND_DEVICES_VIRTMULTI;
user_options->backend_devices_virthost = BACKEND_DEVICES_VIRTHOST;
user_options->backend_devices_keepfree = BACKEND_DEVICES_KEEPFREE;
user_options->backend_ignore_cuda = BACKEND_IGNORE_CUDA;
user_options->backend_ignore_hip = BACKEND_IGNORE_HIP;
#if defined (__APPLE__)
@ -378,6 +380,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
case IDX_HOOK_THREADS:
case IDX_BACKEND_DEVICES_VIRTMULTI:
case IDX_BACKEND_DEVICES_VIRTHOST:
case IDX_BACKEND_DEVICES_KEEPFREE:
case IDX_BENCHMARK_MAX:
case IDX_BENCHMARK_MIN:
#ifdef WITH_BRAIN
@ -509,6 +512,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
case IDX_BACKEND_DEVICES: user_options->backend_devices = optarg; break;
case IDX_BACKEND_DEVICES_VIRTMULTI: user_options->backend_devices_virtmulti = hc_strtoul (optarg, NULL, 10); break;
case IDX_BACKEND_DEVICES_VIRTHOST: user_options->backend_devices_virthost = hc_strtoul (optarg, NULL, 10); break;
case IDX_BACKEND_DEVICES_KEEPFREE: user_options->backend_devices_keepfree = hc_strtoul (optarg, NULL, 10); break;
case IDX_BACKEND_VECTOR_WIDTH: user_options->backend_vector_width = hc_strtoul (optarg, NULL, 10);
user_options->backend_vector_width_chgd = true; break;
case IDX_OPENCL_DEVICE_TYPES: user_options->opencl_device_types = optarg; break;
@ -814,6 +818,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx)
return -1;
}
if (user_options->backend_devices_keepfree > 100)
{
event_log_error (hashcat_ctx, "Invalid --backend-devices-keepfree value specified.");
return -1;
}
if (user_options->outfile_format == 0)
{
event_log_error (hashcat_ctx, "Invalid --outfile-format value specified.");
@ -3315,6 +3326,7 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx)
logfile_top_uint (user_options->attack_mode);
logfile_top_uint (user_options->backend_devices_virtmulti);
logfile_top_uint (user_options->backend_devices_virthost);
logfile_top_uint (user_options->backend_devices_keepfree);
logfile_top_uint (user_options->benchmark);
logfile_top_uint (user_options->benchmark_all);
logfile_top_uint (user_options->benchmark_max);