Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Cardano transactions signature/proof #1629

Closed
4 tasks done
jpraynaud opened this issue Apr 10, 2024 · 1 comment · Fixed by #1649
Closed
4 tasks done

Memory leak in Cardano transactions signature/proof #1629

jpraynaud opened this issue Apr 10, 2024 · 1 comment · Fixed by #1649
Assignees
Labels
bug ⚠️ Something isn't working

Comments

@jpraynaud
Copy link
Member

jpraynaud commented Apr 10, 2024

Why

There is a memory leak in the signature/proof generation of the Cardano transactions. A first investigation shows that it seems to be due to the Merkle tree used to sign that is not released from memory (~2GB leak on testing-preview)

What

Investigate and fix the memory leak

How

  • Deactivate the signature of Cardano transactions on testing-preview
  • Investigate the memory leak
  • Fix the problem
  • Reactivate the signature of Cardano transactions on testing-preview
@jpraynaud jpraynaud added the bug ⚠️ Something isn't working label Apr 10, 2024
@Alenar Alenar self-assigned this Apr 11, 2024
@jpraynaud jpraynaud self-assigned this Apr 15, 2024
@jpraynaud
Copy link
Member Author

Analysis

Memory leak analysis

The investigations have led us to identify that the problem is occurring when the Cardano transactions is activated and that it is probably due to the Merkle tree used to sign.

We have created a test to identify the memory behavior with this Merkle tree:

  • Create the data used to feed to Merkle tree
  • Wait
  • Loop 3 times:
    • Load the Merkle tree
    • Drop the Merkle tree
    • Wait

We have implemented Drop methods on all the structs of the corresponding module and we have confirmed that all the objects created were properly dropped within the test which indicates that there is no reference counting issue and no cycle created, i.e no memory leak

We have profiled the test with 10M leaves and have confirmed that there is no memory leak, and the following memory profiled was created:
mithril-mkmap-test-heap-memory-consumed-without-jemallocator

Memory fragmentation

After investigation, it appears that the RES memory was being released properly by the program. With the same test as above, we had recorded this process memory evolution (where memory is never given back to the OS):
mithril-mkmap-test-RES-without-jemallocator

Fix

We are currently using HashMap and BtreeMap which tend to create memory fragmentation when the number of elements is high. The fix consist in replacing the default memory allocator of the program in order to avoid memory fragmentation. We have implemented it in PR #1649 with the jemallocator memory allocator. We have re-run the same test as above and see that the memory is now given back to the system properly:
mithril-mkmap-test-RES-with-jemallocator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ⚠️ Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants