PK11_PutCRL is very memory inefficient

RESOLVED FIXED in 3.12

Status

NSS
Libraries
P2
normal
RESOLVED FIXED
15 years ago
9 years ago

People

(Reporter: Julien Pierre, Assigned: Alexei Volkov)

Tracking

({perf})

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

3.40 KB, patch
Nelson Bolyard (seldom reads bugmail)
: review+
Julien Pierre
: review+
Details | Diff | Splinter Review
987 bytes, patch
Nelson Bolyard (seldom reads bugmail)
: review+
Details | Diff | Splinter Review
(Reporter)

Description

15 years ago
When storing a new CRL to a token, the memory usage grows significantly.
Tasks manager shows the process memory for crlutil going from 170 MB to 270 MB
at the time of importing a 25 MB DER CRL to the softoken. This is roughly 4x the
size of the DER CRL. I have not yet traced where the successive copies of the
DER are being made exactly.

The call to PK11_PutCRL is being made from crl_storeCRL in crl.c .

Comment 1

15 years ago
Assigned the bug to Julien.
Assignee: wtc → jpierre
Priority: -- → P2
Target Milestone: --- → 3.6
(Reporter)

Comment 2

15 years ago
With the current version of the tip, the peak memory for this test is 157 MB.
This is still too much, but a lot less than when the bug was first reported.

Comment 3

15 years ago
Julien, could you set some criteria for this bug
to be considered fixed?
Target Milestone: 3.6 → 3.7
(Reporter)

Comment 4

15 years ago
Wan-Teh,

Ideally, the process shouldn't grow to more than 2x or 3x the size of the CRL to
be stored. That would amount to somewhere between 55 and 80 MB.

Comment 5

15 years ago
Moved to target milestone 3.8 because the original
NSS 3.7 release has been renamed 3.8.
Target Milestone: 3.7 → 3.8
Remove target milestone of 3.8, since these bugs didn't get into that release.
Target Milestone: 3.8 → ---
(Reporter)

Comment 7

14 years ago
Performance enhancement. Reprioritizing to P3.
Priority: P2 → P3
(Assignee)

Comment 8

12 years ago
The additional copies of der crl are done in two functions, NewDBCrlEntry and
WriteDBCrlEntry, that get called from nsslowcert_UpdateCrl.

First one creates certDBEntryRevocation object and copies derCrl.data into its
derCrl. Then in the next line of nsslowcert_UpdateCrl we call WriteDBCrlEntry
which makes another copy by calling EncodeDBCrlEntry function.

The problem can be fixed by introducing a copy flag, similar to
CRL_DECODE_DONT_COPY_DER, like it is done in
CERT_DecodeDERCrlWithFlags.
(Reporter)

Comment 9

12 years ago
Alexei,

The code you mentioned is in the softoken. Where would that new option be
getting passed from/to ? Are you sure a new option is required ? I think we
should try to get the code optimized without a new option, if possible.
(Assignee)

Comment 10

12 years ago
Sorry for not clarifying it earlier.

I propose the modification of NewDBCrlEntry function parameters. But you are
right: this is a static function and it is called only from one place. We can
modify the body of the function instead of modification of parameters and
use the same memory derCrl.data is pointing to for certDBEntryRevocation
object.

*** pcertdb.c.~1.48.~	2004-04-25 08:03:16.000000000 -0700
--- pcertdb.c	2005-03-17 14:44:42.000000000 -0800
***************
*** 1268,1274 ****
  
  	
      entry->derCrl.len = derCrl->len;
!     PORT_Memcpy(entry->derCrl.data, derCrl->data, derCrl->len);
  
      return(entry);
  
--- 1268,1274 ----
  
  	
      entry->derCrl.len = derCrl->len;
!     entry->derCrl.data = derCrl->data;
  
      return(entry);
  
(Reporter)

Comment 11

12 years ago
Alexei,

Doesn't this change create a memory leak ?
If there was a memcpy, presumably entry->derCrl.data was already allocated. So,
just assigning the variable would leak the buffer.
Please show more of the code in future diffs. 10 lines of context (cvs -q diff
-u10) would be good.
Even for tiny little diff patches like the one in comment 10, it's a good 
idea to attach them as patches to the bug.  That way, the reviewer can 
get bugzilla to display as much or as little context as he wants.  
(Assignee)

Comment 13

12 years ago
I didn't mean to include whole fix into the report. Memory allocation 
for derCrl.data will be removed as well. The patch is attached.
(Assignee)

Comment 14

12 years ago
Created attachment 177895 [details] [diff] [review]
the fix

Comment 15

12 years ago
Comment on attachment 177895 [details] [diff] [review]
the fix

We need to add a comment to NewDBCrlEntry and nsslowcert_UpdateCrl that the
entry must be destroyed before the derCRL goes out of scope. 

It might be better to make 'NewDBCrlEntry' a function at takes a static
CrlEntry and initializes all the fields (setting arena to NULL).
QA Contact: bishakhabanerjee → jason.m.reid
(Reporter)

Comment 16

12 years ago
Reassigning this bug to Alexei.
Assignee: julien.pierre.bugs → alexei.volkov.bugs
QA Contact: jason.m.reid → libraries
(Assignee)

Updated

11 years ago
Priority: P3 → P2
Target Milestone: --- → 3.12
(Assignee)

Comment 17

11 years ago
Created attachment 241761 [details] [diff] [review]
skip extra data copy

avoid memory allocation for certDBEntryRevocation data
Attachment #177895 - Attachment is obsolete: true
Attachment #241761 - Flags: review?(nelson)
Comment on attachment 241761 [details] [diff] [review]
skip extra data copy

This eliminates one allocation and copy.  
Julien, is this sufficient?
Attachment #241761 - Flags: review?(nelson)
Attachment #241761 - Flags: review?
Attachment #241761 - Flags: review+
Attachment #241761 - Flags: review? → review?(julien.pierre.bugs)
(Reporter)

Comment 19

11 years ago
Comment on attachment 241761 [details] [diff] [review]
skip extra data copy

This fix is good. I can't answer whether this is sufficient. When I filed the bug, I had been given a very large CRL (26 MB) that took CMS 4 hours to generate. I had then imported with crlutil, and noted that the process memory exploded - it allocated it about 6 times. PK11_PutCRL was one of the offenders.
I would suggest creating a large CRL again now that crlutil can do so, in much less time. Then observe the process VM size and see how many times the CRL size it is, and how much it grows from the time of before the call to PK11_PutCRL to after it returns.
I think ideally there should be zero copy in that function and thus little process growth. I'm not sure if the PKCS#11 layering actually allows that, but I think so.
Attachment #241761 - Flags: review?(julien.pierre.bugs) → review+
(Assignee)

Comment 20

11 years ago
/cvsroot/mozilla/security/nss/lib/softoken/pcertdb.c,v  <--  pcertdb.c
new revision: 1.64; previous revision: 1.63

The patch eliminates one out of four in memory copies of importing CRL. 
(Assignee)

Comment 21

11 years ago
Created attachment 256105 [details] [diff] [review]
skipping crl entry decoding decoding

skipping entry decoding will be more efficient.
Attachment #256105 - Flags: review?(nelson)
Comment on attachment 256105 [details] [diff] [review]
skipping crl entry decoding decoding

Alexei, have you committed the previously reviewed patch yet?
Attachment #256105 - Flags: review?(nelson) → review+
(Assignee)

Comment 23

11 years ago
previous patch was committed into trunk (see comment #20).
(Reporter)

Updated

10 years ago
Keywords: perf
(Assignee)

Comment 24

9 years ago
No additional work is foreseen for this bug. Closing..
Status: NEW → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.