I work with a cuda device on an integration branch and I still have some segfault while I am finishing my work.
After each crash, my memory consumption is increased by 500 Mo (seen using free -m
, htop
and one other but I don't remember the name). This memory is never released so on this computer with 4Go of RAM so I have to reboot after some crashes otherwise memory swap and it is really really slow (as usual when memory swap happen).
I know the good answer is : "Fix your segfault!!" but I would like to understand why this behavior happen and how can I prevent it.
I read that CUDA memory should be released by OS on segfault and it looks like it doesn't.
While I tried to debug my program, I notice that if I fix the segfault, memory is free'd correctly but if I also comment the cuda release line : cudaFreeHost(buf)
(with segfault fixed), I still have the memory leak.
My memory is allocated as pinned pages : cudaHostAlloc(&ret, n*sizeof(my_struct), cudaHostAllocPortable)
.
I wanted to make sure the "free" code is called using unique_ptr
but it will not solve the problem with segfault.
I looked at persistent mode for CUDA : http://docs.nvidia.com/deploy/driver-persistence/index.html but it is disable on my computer (I checked it with nvidia-smi
).
I tried to reset the cuda device : nvidia-smi -r
but it say it is not supported on my computer.
Questions are:
- How can we ask program (or OS) to release these resources at the end of the program?
- If we can't, Does a command exists to recover these resources after the crash?
Version:
CUDA 6.0.1
gcc 4.9.2
Driver Version: 340.65
Card : GeForce 610M
Update:
Here is a sample code to reproduce the problem. With commented line, I leak 10 Mo per run.
#include <cuda.h>
#include <cuda_runtime.h>
int main() {
int *ret;
cudaHostAlloc(&ret, 10000000 * sizeof(*ret), cudaHostAllocPortable);
//cudaFreeHost(ret);
return 0;
}
Update 2 :
total used free shared buffers cached
Mem: 3830056 1487156 2342900 66336 142840 527088
-/+ buffers/cache: 817228 3012828
Swap: 7811068 0 7811068
1Erreur de segmentation
2Erreur de segmentation
3Erreur de segmentation
4Erreur de segmentation
5Erreur de segmentation
6Erreur de segmentation
7Erreur de segmentation
8Erreur de segmentation
9Erreur de segmentation
10Erreur de segmentation
11Erreur de segmentation
12Erreur de segmentation
13Erreur de segmentation
14Erreur de segmentation
15Erreur de segmentation
16Erreur de segmentation
17Erreur de segmentation
18Erreur de segmentation
19Erreur de segmentation
20Erreur de segmentation
total used free shared buffers cached
Mem: 3830056 1766580 2063476 64152 142860 531032
-/+ buffers/cache: 1092688 2737368
Swap: 7811068 0 7811068