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 .
Assigned the bug to Julien.
Assignee: wtc → jpierre
Priority: -- → P2
Target Milestone: --- → 3.6
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.
Julien, could you set some criteria for this bug to be considered fixed?
Target Milestone: 3.6 → 3.7
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.
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 → ---
Performance enhancement. Reprioritizing to P3.
Priority: P2 → P3
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.
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.
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);
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.
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.
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
Reassigning this bug to Alexei.
Assignee: julien.pierre.bugs → alexei.volkov.bugs
Created attachment 241761 [details] [diff] [review] skip extra data copy avoid memory allocation for certDBEntryRevocation data
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? → review?(julien.pierre.bugs)
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+
/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.
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+
previous patch was committed into trunk (see comment #20).
No additional work is foreseen for this bug. Closing..
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.