Page 1 of 1

Deleting files from HFS+ doesn't free storage space timely

PostPosted: Mon Nov 28, 2016 7:59 am
by massfish
I have made many write and delete operations on HFS+ partition of /private/var in jailbreak iPad(iOS9.3.3). All written files in that partition are definitely deleted. But the left space of that partition is increased all the time. Only reboot the iPad can free up the storage space. I guess maybe HFS+ doesn't release the unused storage space immediately and reboot iPad is one way to recycle unused space.

Is there any method to let HFS+ recycle unused storage space immediately? Thanks

Re: Deleting files from HFS+ doesn't free storage space time

PostPosted: Tue Nov 29, 2016 5:55 am
by morpheus
it's not that HFS+ is bad, it's VFS.

A file is actually deleted only when all open handles to it are closed. When close(2) occurs and the inode ref count is 0, the space may be reclaimed. This is why when you reboot it works.

Consider using procexp all fds to see who's got open handles to the files. Kill those processes, rather than rebooting, and as they restart the files will be deleted and space reclaimed.

Re: Deleting files from HFS+ doesn't free storage space time

PostPosted: Wed Nov 30, 2016 6:15 am
by massfish
Thanks, J. That's the point. There are zombie processes hold the handle of 'deleted' files, and the space of those 'deleted' files are not freed.

There's no way to kill zombie process. Right? So I need to avoid emergence of zombie processes.

Re: Deleting files from HFS+ doesn't free storage space time

PostPosted: Sun Dec 04, 2016 1:03 am
by morpheus
A zombie is usually created when its mother won't wait4() it. Kill the mommy, the children expire. Otherwise, it may be a process that's just uninterruptible due to some device driver or other kernel hold.

Re: Deleting files from HFS+ doesn't free storage space time

PostPosted: Mon Dec 05, 2016 9:20 am
by massfish
Hi J, in my case. The zombie's mommy is /sbin/launchd. When kill it, the OS complains '-sh: kill: (1) - Operation not permitted'. Also the zombie cannot be killed. In my code there's waitpid logic to wait child exit. The program logic is as follows:

{
signal(SIGCHLD, &sig_handler)
posix_spawnattr_t attr;
posix_spawnattr_setflags (&attr, POSIX_SPAWN_START_SUSPENDED) // suspended child process
posix_spawnp (&pid, path, NULL, &attr, NULL, NULL);

// operate on child process
kill(pid, SIGCONT)
kill(pid, SIGKILL)

}

sig_handler() {
while ((pid = waitpid(-1, &stat, WNOHANG)) > 0) {
}
}


Actually, the kill signal -SIGCONT and -SIGKILL seems have no effect to the child process. The child process didn't exit, and the mommy process didn't receive the SIGCHLD signal. When mommy process exit, the /sbin/launchd adopt the child process, finally the child became zombie, and cannot be killed. So J, do you any suggestion for this? Thanks.

By the way when I use debugserver to attach the child process and exit(ctrl+c) debugserver. The child process exit and the parent process received the SIGCHLD signal, and the zombie disappeared.