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

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

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

Postby massfish » Mon Nov 28, 2016 7:59 am

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
massfish
 
Posts: 3
Joined: Thu Sep 08, 2016 2:56 am

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

Postby morpheus » Tue Nov 29, 2016 5:55 am

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.
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

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

Postby massfish » Wed Nov 30, 2016 6:15 am

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.
massfish
 
Posts: 3
Joined: Thu Sep 08, 2016 2:56 am

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

Postby morpheus » Sun Dec 04, 2016 1:03 am

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.
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

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

Postby massfish » Mon Dec 05, 2016 9:20 am

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.
massfish
 
Posts: 3
Joined: Thu Sep 08, 2016 2:56 am


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 1 guest