A bug about jetson system memory calculate?

Use ‘top’ or ‘cat /proc/PID/status’ to view the system memory,as a result, there are more than 100 percent (8GB) bug.

But if you use ‘free’ or ‘jtop’, you still have a lot of memory left:

It was found that converting nvmm buffers into cpu buffers using cuda interfaces caused this,Is this a memory leak or just a bug in the jetson system statistics process?

NvBufSurface *surface = NULL;
NvBufSurfTransformRect src_rect, dst_rect;
surface = (NvBufSurface *) map.data;  
int batch_size= surface->batchSize;
src_rect.top   = 0;
src_rect.left  = 0;
src_rect.width = (guint) surface->surfaceList[0].width;
src_rect.height= (guint) surface->surfaceList[0].height;
dst_rect.top   = 0;
dst_rect.left  = 0;
dst_rect.width = (guint) surface->surfaceList[0].width;
dst_rect.height= (guint) surface->surfaceList[0].height;

NvBufSurfTransformParams nvbufsurface_params;
nvbufsurface_params.src_rect = &src_rect;
nvbufsurface_params.dst_rect = &dst_rect;
nvbufsurface_params.transform_filter = NvBufSurfTransformInter_Default;

if(NULL == dst_surface)
	cudaSetDevice (surface->gpuId);
	cudaStreamCreate (&cuda_stream);

	NvBufSurfaceCreateParams nvbufsurface_create_params;
	nvbufsurface_create_params.gpuId  = surface->gpuId;
	nvbufsurface_create_params.width  = (gint) surface->surfaceList[0].width;
	nvbufsurface_create_params.height = (gint) surface->surfaceList[0].height;
	nvbufsurface_create_params.size = 0;
	nvbufsurface_create_params.colorFormat = NVBUF_COLOR_FORMAT_NV12;
	nvbufsurface_create_params.layout = NVBUF_LAYOUT_PITCH;
	nvbufsurface_create_params.memType = NVBUF_MEM_DEFAULT;
	int create_result = NvBufSurfaceCreate(&dst_surface,batch_size,&nvbufsurface_create_params);

NvBufSurfTransformConfigParams transform_config_params;
NvBufSurfTransform_Error err;

transform_config_params.compute_mode = NvBufSurfTransformCompute_Default;
transform_config_params.gpu_id = surface->gpuId;
transform_config_params.cuda_stream = cuda_stream;

err = NvBufSurfTransformSetSessionParams (&transform_config_params);
NvBufSurfaceMemSet (dst_surface, 0, 0, 0);
err = NvBufSurfTransform (surface, dst_surface, &nvbufsurface_params);
if (err != NvBufSurfTransformError_Success) 
   g_print ("Error: NvBufSurfTransform failed with error %d while converting buffer\n", err);

int templen = 0;

for(int i=0;i<2;i++)
	NvBufSurfaceMap (dst_surface, 0, i, NVBUF_MAP_READ);                        
	NvBufSurfaceSyncForCpu (dst_surface, 0, 0);
	if(0 == i)
		for (int n = 0; n < dst_surface->surfaceList[0].height; ++n)
			memcpy((char*)snap_yuv_img.data+templen,(char *)(char*)dst_surface->surfaceList[0].mappedAddr.addr[i] + n * dst_surface->surfaceList[0].pitch,dst_surface->surfaceList[0].width);
			templen += dst_surface->surfaceList[0].width;
		for (int n = 0; n < dst_surface->surfaceList[0].height/2; ++n)
				memcpy((char*)snap_yuv_img.data+templen,(char*)dst_surface->surfaceList[0].mappedAddr.addr[i] + n  * dst_surface->surfaceList[0].pitch,dst_surface->surfaceList[0].width);
				templen += dst_surface->surfaceList[0].width;

if (NvBufSurfaceUnMap (dst_surface, 0, 0))
	printf("Error:NvBufSurfaceUnMap fail!\r\n");



The app uses some virtual memory so the total memory might be over the physical memory amount.


But the amount of memory is increasing infinitely, so the cuda api doesn’t free virtual memory, right?

On the top screen,the “RES” stands for physical memory, not virtual memory, It’s also over 8GB.


Do you mean the summary of PID 10855 and 10758 that is over 8G?
The process on the top looks like from the same application.


That’s an executable file executed on multiple terminals with different parameters.
such as:
./blst_app 0 0 run in terminals-0
./blst_app 1 1 run in terminals-1
This result has nothing to do with executables and everything to do with cuda video memory to memory interfaces.
The same thing happens when I call this transformation api with multiple different programs.


Could you share the app or some public app that can reproduce this issue?
We want to discuss this with our internal team.


nvarguscamerasrc(4000*3000 nvmm nv12)->appsink()
In appsink, one frame of nvmm-NV12 data is transferred to the cpu every two seconds.
The method of data format conversion was provided by your colleague more than a year ago, but we did not notice this phenomenon before.

I’m closing this topic due to there is no update from you for a period, assuming this issue was resolved.
If still need the support, please open a new topic. Thanks


Do you have the complete source or topic link?