[GH-ISSUE #1707] Forked OpenCL runs wastes some device memory #1120

Closed
opened 2026-10-14 03:35:47 +07:00 by bsakaguchi · 10 comments
Owner

Originally created by @magnumripper on GitHub (Aug 25, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1707

http://www.openwall.com/lists/john-dev/2015/08/25/2

Maybe we can close or clean something up somewhere right before forking? I thought we did though.

Originally created by @magnumripper on GitHub (Aug 25, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1707 http://www.openwall.com/lists/john-dev/2015/08/25/2 Maybe we can close or clean something up somewhere right before forking? I thought we did though.
bsakaguchi 2026-10-14 03:35:47 +07:00
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2015):

I wonder it it's this simple (can't test right now):

diff --git a/src/opencl_cryptmd5_fmt_plug.c b/src/opencl_cryptmd5_fmt_plug.c
index 7e96542..a6057bf 100644
--- a/src/opencl_cryptmd5_fmt_plug.c
+++ b/src/opencl_cryptmd5_fmt_plug.c
@@ -324,7 +324,6 @@ static char *get_key(int index)
 static void init(struct fmt_main *_self)
 {
        self = _self;
-       opencl_prepare_dev(gpu_id);
 }

 static void reset(struct db_main *db)
@@ -332,6 +331,8 @@ static void reset(struct db_main *db)
        if (!autotuned) {
                char build_opts[64];

+               opencl_prepare_dev(gpu_id);
+
                snprintf(build_opts, sizeof(build_opts),
                         "-DPLAINTEXT_LENGTH=%u", PLAINTEXT_LENGTH);

That would mean we have to audit every format for this. We need to avoid any and all OpenCL stuff in init(), if possible.

Note: I'm not quite sure we even need to add it to reset() at all - we may do fine with just dropping that line from init().

<!-- gh-comment-id:135572732 --> @magnumripper commented on GitHub (Aug 27, 2015): I wonder it it's this simple (can't test right now): ``` diff diff --git a/src/opencl_cryptmd5_fmt_plug.c b/src/opencl_cryptmd5_fmt_plug.c index 7e96542..a6057bf 100644 --- a/src/opencl_cryptmd5_fmt_plug.c +++ b/src/opencl_cryptmd5_fmt_plug.c @@ -324,7 +324,6 @@ static char *get_key(int index) static void init(struct fmt_main *_self) { self = _self; - opencl_prepare_dev(gpu_id); } static void reset(struct db_main *db) @@ -332,6 +331,8 @@ static void reset(struct db_main *db) if (!autotuned) { char build_opts[64]; + opencl_prepare_dev(gpu_id); + snprintf(build_opts, sizeof(build_opts), "-DPLAINTEXT_LENGTH=%u", PLAINTEXT_LENGTH); ``` That would mean we have to audit every format for this. We need to avoid any and all OpenCL stuff in init(), if possible. Note: I'm not quite sure we even need to add it to reset() at all - we may do fine with just dropping that line from init().
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2015):

Aha... this rings a bell.

Current code:

Device 2: GeForce GT 650M
Benchmarking: md5crypt-opencl, crypt(3) $1$ [MD5 OpenCL]... DONE
Raw:    254508 c/s real, 26214K c/s virtual

Drop that line in init():

Benchmarking: md5crypt-opencl, crypt(3) $1$ [MD5 OpenCL]... Device 2: GeForce GT 650M
DONE
Raw:    257003 c/s real, 13107K c/s virtual

So we added that line (in every format) for cosmetic reasons, and it has this unfortunate side effect with fork.

<!-- gh-comment-id:135573119 --> @magnumripper commented on GitHub (Aug 27, 2015): Aha... this rings a bell. Current code: ``` Device 2: GeForce GT 650M Benchmarking: md5crypt-opencl, crypt(3) $1$ [MD5 OpenCL]... DONE Raw: 254508 c/s real, 26214K c/s virtual ``` Drop that line in init(): ``` Benchmarking: md5crypt-opencl, crypt(3) $1$ [MD5 OpenCL]... Device 2: GeForce GT 650M DONE Raw: 257003 c/s real, 13107K c/s virtual ``` So we added that line (in every format) for cosmetic reasons, and it has this unfortunate side effect with fork.
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2015):

No, this wasn't it at all. init() is post-poned when forking.

<!-- gh-comment-id:135577535 --> @magnumripper commented on GitHub (Aug 27, 2015): No, this wasn't it at all. init() is post-poned when forking.
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2015):

We do absolutely nothing OpenCL prior to the fork. But after it, we enumerate devices and create contexts and stuff, and then we pick just one of them. The rest is the answer to Solar's question. We currently have no way of "destroying" contexts for the devices we won't use.

I actually think this exact problem exist without fork too. Next step is to verify that.

<!-- gh-comment-id:135578785 --> @magnumripper commented on GitHub (Aug 27, 2015): We do absolutely **nothing** OpenCL prior to the fork. But after it, we enumerate devices and create contexts and stuff, and then we pick just one of them. The rest is the answer to Solar's question. We currently have no way of "destroying" contexts for the devices we won't use. I actually think this exact problem exist without fork too. Next step is to verify that.
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2015):

LOL, we've been here before: http://www.openwall.com/lists/john-dev/2013/07/02/11

<!-- gh-comment-id:135583892 --> @magnumripper commented on GitHub (Aug 27, 2015): LOL, we've been here before: http://www.openwall.com/lists/john-dev/2013/07/02/11
Author
Owner

@ghost commented on GitHub (Oct 10, 2015):

Is this fixed? I was curious, so (on super, now):

../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=1,2 -mask='?l?l?l?l?l?l?l?l'

[...]
1 0g 0:00:01:19  0g/s 0p/s 39415c/s 39415C/s aaaaaaaa..xovdbaaa
2 0g 0:00:01:21  0g/s 0p/s 64321c/s 64321C/s aaaaaaan..vdrhcaan
  • Meanwhile, using another ssh connection:
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
[
<!-- gh-comment-id:147094850 --> @ghost commented on GitHub (Oct 10, 2015): Is this fixed? I was curious, so (on super, now): ``` ../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=1,2 -mask='?l?l?l?l?l?l?l?l' [...] 1 0g 0:00:01:19 0g/s 0p/s 39415c/s 39415C/s aaaaaaaa..xovdbaaa 2 0g 0:00:01:21 0g/s 0p/s 64321c/s 64321C/s aaaaaaan..vdrhcaan ``` - Meanwhile, using another ssh connection: ``` +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+ [ ```
Author
Owner

@ghost commented on GitHub (Oct 10, 2015):

../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=6,7 -mask='?l?l?l?l?l?l?l?l'

1 0g 0:00:01:16 0.00% (ETA: 2016-02-04 12:58) 0g/s 5117p/s 112581c/s 112581C/s GPU:79°C util:99% fan:36% srjwaaaa..jjtsbaaa
2 0g 0:00:01:10  0g/s 0p/s 39203c/s 39203C/s GPU:73°C util:99% fan:44% aaaaaaan..hqcabaan
  • Suboptimal, but not that bad.
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0      4290    C   ../run/john                                     68MiB |
|    0      4291    C   ../run/john                                    155MiB |
|    1      4290    C   ../run/john                                    185MiB |
|    1      4291    C   ../run/john                                    111MiB |
+-----------------------------------------------------------------------------+
<!-- gh-comment-id:147096444 --> @ghost commented on GitHub (Oct 10, 2015): ``` ../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=6,7 -mask='?l?l?l?l?l?l?l?l' 1 0g 0:00:01:16 0.00% (ETA: 2016-02-04 12:58) 0g/s 5117p/s 112581c/s 112581C/s GPU:79°C util:99% fan:36% srjwaaaa..jjtsbaaa 2 0g 0:00:01:10 0g/s 0p/s 39203c/s 39203C/s GPU:73°C util:99% fan:44% aaaaaaan..hqcabaan ``` - Suboptimal, but not that bad. ``` +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 4290 C ../run/john 68MiB | | 0 4291 C ../run/john 155MiB | | 1 4290 C ../run/john 185MiB | | 1 4291 C ../run/john 111MiB | +-----------------------------------------------------------------------------+ ```
Author
Owner

@ghost commented on GitHub (Oct 10, 2015):

../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=2,6 -mask='?l?l?l?l?l?l?l?l'

2 0g 0:00:02:02  0g/s 0p/s 102375c/s 102375C/s GPU:86°C util:99% fan:57% aaaaaaan..tsmldaan
1 0g 0:00:01:59  0g/s 0p/s 70462c/s 70462C/s aaaaaaaa..vdrhcaaa
  • We need to avoid (an AMD GPU process using memory of a NVIDIA GPU)
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    1      4349    C   ../run/john                                    111MiB |
|    1      4350    C   ../run/john                                    401MiB |
+-----------------------------------------------------------------------------+
<!-- gh-comment-id:147096880 --> @ghost commented on GitHub (Oct 10, 2015): ``` ../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=2,6 -mask='?l?l?l?l?l?l?l?l' 2 0g 0:00:02:02 0g/s 0p/s 102375c/s 102375C/s GPU:86°C util:99% fan:57% aaaaaaan..tsmldaan 1 0g 0:00:01:59 0g/s 0p/s 70462c/s 70462C/s aaaaaaaa..vdrhcaaa ``` - We need to avoid (an AMD GPU process using memory of a NVIDIA GPU) ``` +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 1 4349 C ../run/john 111MiB | | 1 4350 C ../run/john 401MiB | +-----------------------------------------------------------------------------+ ```
Author
Owner

@ghost commented on GitHub (Oct 10, 2015):

I actually think this exact problem exist without fork too.

No, it does not exist without fork. It only wastes memory if a GPU is listed in the -devices list.

<!-- gh-comment-id:147100242 --> @ghost commented on GitHub (Oct 10, 2015): > I actually think this exact problem exist without fork too. No, it does not exist without fork. It only wastes memory if a GPU is listed in the -devices list.
Author
Owner

@ghost commented on GitHub (Oct 10, 2015):

Now:

../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=2,6 -mask='?l?l?l?l?l?l?l?l'

2 0g 0:00:01:33  0g/s 0p/s 118349c/s 118349C/s GPU:83°C util:99% fan:46% aaaaaaan..tsmldaan
1 0g 0:00:01:29  0g/s 0p/s 70453c/s 70453C/s aaaaaaaa..vdrhcaaa

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    1      5569    C   ../run/john                                    401MiB |
+-----------------------------------------------------------------------------+

Will create a PR soon. More tests needed (?): node, MPI, whatever that might share code with fork.

<!-- gh-comment-id:147110434 --> @ghost commented on GitHub (Oct 10, 2015): Now: ``` ../run/john ~/testhashes -form=sha256crypt-opencl -fork=2 -dev=2,6 -mask='?l?l?l?l?l?l?l?l' 2 0g 0:00:01:33 0g/s 0p/s 118349c/s 118349C/s GPU:83°C util:99% fan:46% aaaaaaan..tsmldaan 1 0g 0:00:01:29 0g/s 0p/s 70453c/s 70453C/s aaaaaaaa..vdrhcaaa ``` ``` +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 1 5569 C ../run/john 401MiB | +-----------------------------------------------------------------------------+ ``` Will create a PR soon. More tests needed (?): node, MPI, whatever that might share code with fork.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1120
No description provided.