I’m creating a gst plugin that uses OpenCV to apply some filters, and based on the gst example plugin, I have this code that is making the Virtual Memory of the cgroup to explode after 50 minutes of processing 2 different RTSP sources at 15 fps.
for (guint i = 0; i < batch->frames.size (); i++) {
GstMapInfo in_map_info;
NvBufSurface *in_surf;
if (!gst_buffer_map(batch->inbuf, &in_map_info, GST_MAP_READ))
{
GST_ELEMENT_ERROR(clahe, STREAM, FAILED,
("%s:gst buffer map to get pointer to NvBufSurface failed", __func__), (NULL));
return FALSE;
}
in_surf = (NvBufSurface *)in_map_info.data;
// Map the buffer so that it can be accessed by CPU
if (NvBufSurfaceMap(in_surf, i, 0, NVBUF_MAP_READ_WRITE) != 0)
{
GST_ELEMENT_ERROR(clahe, STREAM, FAILED,
("%s:buffer map to be accessed by CPU failed", __func__), (NULL));
return FALSE;
}
// sync mapped data for CPU access
NvBufSurfaceSyncForCpu(in_surf, i, 0);
int h = in_surf->surfaceList[i].height;
int w = in_surf->surfaceList[i].width;
int p = in_surf->surfaceList[i].pitch;
for (int j=0; j < h; j++) {
memcpy(in_surf->surfaceList[i].mappedAddr.addr[0] + (j*p) , batch->cvmat[i].data + (j * w * 4), w * 4);
}
NvBufSurfaceSyncForDevice(in_surf, i, 0);
if (NvBufSurfaceUnMap(in_surf, i, 0))
{
GST_ELEMENT_ERROR(clahe, STREAM, FAILED,
("%s:buffer unmap to be accessed by CPU failed", __func__), (NULL));
return FALSE;
}
gst_buffer_unmap(batch->inbuf, &in_map_info);
}
Could you please help me to find out why this code is creating a memory leak? I´m not able to see any problem.
Thanks for the answer, but if I remove this code, I will not have the frame available in surfaceList[i].mappedAddr.addr[0] copied into batch->cvmat[i].data. Is there any other method to copy data between them?
Hi,
Would suggest remove some part in the code and see if the issue is still present. To find which function makes the leak. Or may remove NvBufSurfaceMap() and NvBufSurfaceUnMap for a try.
And you may make a patch to deepstream-test3 so that we can replicate the error and check. Do you run r32.4.4 + DS5.0.1? You can check the version by executing $ head -1 /etc/nv_Tegra_release.
It seems the problem is that there is a leak of 100kb in the NvBufSurfaceMap, since there is a post here talking about the same issue that has the first piece of code i posted here. All these code is working and it is in the gst-example, but this is to copy a CvMat into a NvBufSurface, in order to replace the original frame with the one of the Opencv matrix, which already has that frame with some filters applied.
Any help with the leak coming from the NvBufSurfaceMap/Unmap??
Thanks for the help
Hi,
We would need to replicate the issue for further investigation. Please make a patch to gstdsexample.cpp so that we can enable it and run deepstream-app to reproduce the issue.
There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks