Memory Leak in canonical_label with bliss?

122 views
Skip to first unread message

Thomas Willwacher

unread,
Apr 23, 2022, 12:50:26 PM4/23/22
to sage-devel
Dear all,

there seems to be a memory leak in canonical_label(...), using bliss.
Here is a test script to demonstrate the problem:

-----------------

import os, psutil

from sage.all import *

process = psutil.Process(os.getpid())
oldmem = process.memory_info().rss

for i in range(1000000):
    G = graphs.RandomGNM(10,20)
    canonG = G.canonical_label(algorithm='bliss')
    # canonG = G.canonical_label(algorithm='sage')

    if i%1000 == 0:
       print(f"graph count {i}, mem usage (Delta) {process.memory_info().rss - oldmem}")
       oldmem = process.memory_info().rss

--------

This uses up more and more memory if I use 'bliss' as algorithm:
On my machine around 260KB/1000 calls are lost.
Invoking garbage collection manually does not help.
I believe this might be a bug.

There is no memory leak using 'sage' as algorithm.

Info on my system:
MacBook Pro with M1 processor, macOS Monterey,
sage 9.4, bliss 0.73

Thanks a lot for your help,

Thomas

P.S.: The amount of memory lost in the sample script is small on an absolute scale, but our  programs run for a week or two and we end up losing many GB.
The obvious bugfix is to use algorithm='sage', but this is twice slower than bliss.




Travis Scrimshaw

unread,
Apr 24, 2022, 8:49:07 PM4/24/22
to sage-devel
Hi Thomas,
   Could the memleak be coming from within bliss?

Best,
Travis

Thomas Willwacher

unread,
Apr 25, 2022, 4:47:07 PM4/25/22
to sage-devel
Hi Travis,
I do not know whether the leak is caused within bliss or by sage's wrapper unfortunately.
But can you reproduce the problem?
Best,
Thomas

Travis Scrimshaw

unread,
May 1, 2022, 7:20:12 PM5/1/22
to sage-devel
Hi Thomas,
   Sorry for taking so long to respond as I was away from my computer last week to test.

Yes, I seem to be seeing it as well. However, if it is within bliss, then it needs to be solved upstream (and/or with a patch here).

Best,
Travis

Ricardo Buring

unread,
May 16, 2022, 11:34:14 AM5/16/22
to sage-devel
Dear Thomas and list,

I've also run into this problem. Building SageMath and bliss with debug symbols and running

    valgrind -s --keep-debuginfo=yes --tool=memcheck --leak-check=full --show-leak-kinds=all --suppressions=valgrind-python.supp --log-file=bliss_leak.log ./sage/venv/bin/python3 bliss_leak.py

gives the attached log file bliss_leak.log, which refers to the C++ code in bliss.cpp generated from bliss.pyx in SageMath, as well as to the bliss source code.

Specifically bliss::AbstractGraph::canonical_form calls bliss::AbstractGraph::search, which sometimes calls bliss::Partition::cr_init without calling bliss::Partition::cr_free, due to a (conditional) early return.
This leak is fixed in the latest upstream release available from https://users.aalto.fi/~tjunttil/bliss/

Best,
Ricardo
bliss_leak.log
bliss_leak.py

Antonio Rojas

unread,
May 16, 2022, 11:52:24 AM5/16/22
to sage-devel
El lunes, 16 de mayo de 2022 a las 17:34:14 UTC+2, Ricardo Buring escribió:
Specifically bliss::AbstractGraph::canonical_form calls bliss::AbstractGraph::search, which sometimes calls bliss::Partition::cr_init without calling bliss::Partition::cr_free, due to a (conditional) early return.
This leak is fixed in the latest upstream release available from https://users.aalto.fi/~tjunttil/bliss/

Updating bliss is tracked at #33010 (and needs help) 
Reply all
Reply to author
Forward
0 new messages