4

I am on MacOs 10.12.5. I am trying to do high volume I/O but some task managed by launchd hits every modified disk block every 30 seconds. When this happens my high volume I/O has to compete causing a severe slow down. How do I identify the problem task?

I believe it is something to do with launchd because fs_usage -w -f diskio tells me it is. Every 30 seconds it outputs a list like this for every changed disk block in the system (apologies you have to scroll to see launchd):

14:34:33.887889    WrData[AT3]     D=0x0068c05a  B=0x1000   /dev/disk2  /Users/simon/Library/Application Support/Google/Chrome/Default/Session Storage/000430.log                                                             0.000145 W launchd.9793620
14:34:33.887893    WrData[AT3]     D=0x00549a2b  B=0x1000   /dev/disk2  /Users/simon/Library/Application Support/Google/Chrome/Default/Session Storage/LOG                                                                    0.000107 W launchd.9793620
14:34:33.887895    WrData[AT3]     D=0x00570119  B=0x1000   /dev/disk2  /Users/simon/Library/Saved Application State/com.apple.Terminal.savedState/window_2.data                                                              0.000070 W launchd.9793620
14:34:33.887897    WrData[AT3]     D=0x0056fab5  B=0x1000   /dev/disk2  /Users/simon/Library/Saved Application State/com.apple.Terminal.savedState/window_3.data                                                              0.000064 W launchd.9793620
14:34:33.887912    WrData[ANT3]    D=0x0056ffd0  B=0x1000   /dev/disk2  /Users/simon/Library/Saved Application State/com.apple.Terminal.savedState/windows.plist                                                              0.000072 W launchd.9793620

I thought it might be my McAfee anti-virus software, so I excluded the files I was writing from real-time scanning, and then tried turning it off.

I then thought it might be Spotlight search, but again excluding the volume my data files are on did not prevent this launchd task from re-accessing the files.

Running launchctl list shows a list of 327 tasks. I would love to be able to narrow this down to just one.

Whilst I am sure the task runs every 30 seconds having watched it many times, I cannot find any mention of an appropriate "30" in the configuration files. I have:

  • No mention of "30" in /System/Library/LaunchAgents
  • One mention of "30" in /System/Library/LaunchDaemons
    • com.apple.powerd.swd.plist sets ThrottleInterval to 30
  • No mention of "30" in /Library/LaunchAgents
  • One mention of "30" in /Library/LaunchDaemons
    • com.mcafee.virusscan.fmpd.plist sets ExitTimeout to 30
  • No mention of "30" in ~/Library/LaunchAgents

Although McAfee does mention "30", disabling it and excluding the files made no difference.

Any help in identifying the task which is accessing changed disk blocks would be appreciated.

4
  • Can you remove McAfee completely? I recall some very weird things with McAfee -- it was impossible quit normally, and it had two processes monitoring each other so that one could restart the other if it ever died. Basically, I wouldn't trust them to have the disable button actually disable anything. Jun 20, 2017 at 15:04
  • @BallpointBen - unfortunately removing McAfee completely would not make my local IT guys happy and I have to live with them. We do not even know that it is McAfee, except that we would expect McAfee to hit newly changed files.
    – Simon G.
    Jun 21, 2017 at 15:26
  • probably obvious, but make sure you don't have a cloud sync active on those directories (icloud etc)
    – troseman
    Jun 22, 2017 at 0:37
  • you might try turning off time machine in case it builds a list of modified files
    – troseman
    Jun 22, 2017 at 0:44

3 Answers 3

3

Sadly, this is built-in deep into launchd. It is hardcoded to call sync(2) every 30 seconds and there's little that can be done about it...

/* launchd.c */
/* ... */
int32_t launchd_sync_frequency = 30;

int
main(int argc, char *const *argv)
{
        /* ... */
        pthread_t t = NULL;
        (void)os_assumes_zero(pthread_create(&t, NULL, update_thread, NULL));
        (void)os_assumes_zero(pthread_detach(t));
        /* ... */
}

void *
update_thread(void *nothing __attribute__((unused)))
{
    (void)posix_assumes_zero(setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, IOPOL_THROTTLE));

    while (launchd_sync_frequency) {
        sync();
        sleep(launchd_sync_frequency);
    }

    launchd_syslog(LOG_DEBUG, "Update thread exiting.");
    return NULL;
}
New contributor
anpep is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Apple rewrote launchd in Swift a few years ago. Unfortunately, the latest Swift version is not open source but presumably continues this same behaviour. Dec 3 at 16:14
1

I had the same problem a while back but IIRC, it turned out to be the Spotlight indexing services (mds, mdworker, etc) which are spawned by launchd.

Open Spotlight in System Preferences, switch to the Privacy tab, then drag your home folder into the window. This will cause Spotlight to ignore your home folder and all subfolders.

If you don't want to exclude all your files, create a folder specifically for this high I/O application and configure Spotlight to ignore just this folder.

For a geekier method, here are some shell commands to run that will exclude the entire drive from Spotlight indexing. I use these commands on all external USB/flash drives as soon as I can.

Touch these files at the root of the drive to exclude, so cd / for the main internal drive or cd /Volumes/USB_FLASH_DRIVE_NAME for an external USB/FLASH drive, then

sudo /usr/bin/touch .metadata_never_index
sudo /usr/bin/chflags hidden .metadata_never_index

and to stop prompting if you want to use the disk for TimeMachine backups

sudo /usr/bin/touch .com.apple.timemachine.donotpresent
sudo /usr/bin/chflags hidden .com.apple.timemachine.donotpresent
0

When it happens, try doing

launchctl list|grep xxxxx

int the Terminal where xxxx is the number appearing at the end of your fs_usage output, that is to say the launchd.9793620 in the listing you provided.

3
  • Apologies - I was not able to test until today. The sad answer is "absolutely nothing". I think this is because the number in the fs_usage output is a thread ID, but the number in the launchctl list is a process ID
    – Simon G.
    Jun 20, 2017 at 8:04
  • No need for apologies, you are the one in trouble! You are correct indeed: I have just tested my idea does not work on my Sierra. Sorry about that, I should have tested but I was on my phone…
    – user123861
    Jun 20, 2017 at 8:40
  • I am trying to find a tool to list all running threads. On Linux, there is htop and it can be installed on MacOS, so I went ahead, but there is no support for displaying all threads :-(
    – user123861
    Jun 20, 2017 at 8:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .