Hi, I'm using cp command to copy some files. After some copies, the system became slow. I used the "free" command, and I noted that free memory was just 1 mb. [root@eduardo /home]# dd if=/dev/zero of=./fileTest bs=1024 count=10000 10000+0 records in 10000+0 records out dd if=/dev/zero of=./fileTest bs=1024 count=10000 [root@eduardo /home]# ls -ls -rwxr-xr-x 1 root root 10240000 Mar 23 12:03 fileTest drwxr-xr-x 1 root root 2048 Dec 14 17:07 plg [root@eduardo /home]# free total used free shared buffers Mem: 58996 21084 37912 0 28 Swap: 0 0 0 Total: 58996 21084 37912 [root@eduardo /home]# [root@eduardo /home]# cp fileTest /tmp/a [root@eduardo /home]# free total used free shared buffers Mem: 58996 41284 17712 0 28 Swap: 0 0 0 Total: 58996 41284 17712 [root@eduardo /home]# cp fileTest /tmp/b [root@eduardo /home]# free total used free shared buffers Mem: 58996 51120 7876 0 28 Swap: 0 0 0 Total: 58996 51120 7876 [root@eduardo /home]# cp fileTest /tmp/c [root@eduardo /home]# free total used free shared buffers Mem: 58996 57452 1544 0 28 Swap: 0 0 0 Total: 58996 57452 1544 It seems that the memory is allocated but not deallocated by the cp command. What could cause that? Anyone have the same problem? (Kernel is a custom compilation of 2.6.32-2 version) Thanks in advance
Memory leak using cp command?
Take a look at the output of the "mount" command. I guess you are using a RAM filesystem (called 'tmpfs') mounted on tmp/ For example on my host here: [...] tmpfs on /tmp type tmpfs (rw,mode=1777,size=2G,nr_inodes=1k) [...]
Hi Juergen, On rcS file (/etc/init.d/rcS) there's four lines: /bin/mount -t ramfs none /dev /bin/mount -n -t tmpfs tmpfs /dev/shm /bin/mount -n -t ramfs none /tmp /bin/mount -n -t ramfs none /var I read about tempfs and ramfs, and now I agree with you... this could be the reason. So, I tried to copy the same file to the same directory where the original file was (/home/): obs: the result of free command is resumed here # free Total: 58996 34800 24196 # cp fileTest ./fileTest11 # free Total: 58996 45180 13816 At this time, I copied it to /home dir (and / is mounted on nand flash). Why ram is in use? Then, I tried to remove: # rm fileTest11 And for my surprise, the memory was deallocated. # free Total: 58996 34800 24196 Now, I don't understand why the memory was allocated and freed when the file was deleted. I suppose that this file should be on disk (nand flash) after each copy, and not on ram... or I'm wrong? I'll read more about ramfs, tempfs and yaffs. On my system I'll need to do some file copies (logs, updates and etc), and I'm afraid that the system could become slow or hang when the memory usage is high.
Linux uses the unused parts of the memory as its filesystem cache ("don't waste unused memory"). If you copy large files this will consume the memory. But this filesystem cache also shrinks again when applications request for more memory. You can check this behaviour by using this command after you copy the file: echo 3 > /proc/sys/vm/drop_caches This will free all cache memory immediately.
Hi Juergen, I see it now. Thanks for your help. The system may be slow for other reasons (and I'll find out)...