Open Xaroth opened 10 years ago
Hmm. I did wrap initializations with ffi.gc(), for instance:
def libzfs_fini(zhp):
"""Closes libzfs_handle"""
return czfs.libzfs_fini(zhp)
def libzfs_init():
"""Initialize libzfs_handle"""
return ffi.gc(czfs.libzfs_init(), libzfs_fini)
A single libzfs handle is created upon import of zfs.py as LZH.
I do need to verify if zpool_get_handle/zfs_get_handle
can be closed without messing with the original, but IIRC they are not used in the current code, although they are provided as a private function (_get_libzfs_handle
). One even has a copy/paste error, which I'll fix today, heh.
If you add a manual gc collect after undefining any vars in question, does memory get cleaned up at all?
import gc
gc.collect()
You can use gc.get_referrers(var)
to see why a variable is still alive as well, although CFFI can complicate things.
It might be worth pointing out that objects do not clean up the libzfs handles; as such, frequent interaction with zfs will cause in excessive amounts of memory used.
Now this issue does arrise that quickly, it'll take several thousand iterations to manifest itself (obviously less if you have more zpools), but it exists nonetheless
A quick way to 'force'this is running the following repeatedly:
even if you delete the pools var after each run, you'll quickly note that after several uses memory consumption of the process has raised significantly...