Wednesday, April 24, 2019

Linux: Why Deleting Files Does Not Free Up Memory

This is a very old blog post from a place I contributed to:

You are in the middle of compiling your code and you see errors:
/disk/user1/platform_dev/driver/openwrt/staging_dir_arm_platform/bin/arm-unknown-linux-uclibcgnueabi-objcopy:/disk/user1/platform_dev/driver/base/build_platform/kmod/linuxmodule/stI4AuYi: No space left on device
make[5]: *** Waiting for unfinished jobs....

So this is just like old times. You run df -h and check if you are running at disk capacity.
I find that I am at 70% disk usage but still the make process is complaining.

I decide to be conservative and free up more space on the system.
Then I see something interesting. Despite doing the rm -Rf on a couple of big chunks of data,
I do not see the free space on my system going up. 

That gets me thinking why this might be happening. The reason is that the deletes I did were through screen. And, Linux will not free up any descriptors (Inodes) as long as they are being referred through some process.

So I ran the command
lsof | grep deleted

This command listed a buch of my recent deletes that had not gone through. I tried to manually do the cleanup by restarting the processes and killing the screen sessions. It was too much work so I ended up rebooting the machine instead.

This fixed the problem.

For comments please respond here.