The short answer to what iOS is doing while my iPhone is sleeping is that I did some digging, and I still don’t know, but something doesn’t seem quite right.
I upgraded my 3 year old iPhone XR to iOS 15 a few days after release. Overall I’ve been happy with it, but I noticed something odd a few days after upgrading. When I clicked the People album in photos, which is populated by face detection and analysis algorithms, it said that it had only processed about half of the 42K photos in my photo library and that I should lock my phone and connect it to power to complete the process.
I didn’t think to much of it at first. I usually charge my phone at my desk in the morning, rather than overnight by my bedside, so I can use a solar-charged battery bank. This means it only spends a couple hours a day locked and connected to a charger instead of the average 8 hours most phones get when charged overnight. So, I left my phone locked plugged into power for most of the day. I was surprised to see that the face scanning made little-to-no progress in that time.
I tried leaving it charging overnight without much improvement. I tried force quitting photos before powering and locking the phone. That yielded some progress the first time I did it, but not the second or third time. I tried lots of different obscure things which didn’t make much difference either. I tried putting it in airplane mode before leaving it powered and locked on the theory that perhaps iCloud was locking a critical resource and not releasing it. No one thing made an obvious impact, and certainly not twice. Never the less, in the space of a few days, it managed to process almost 40K of my photos in fits and starts. There were, however, 2,032 left and the phone made no progress against that.
At this point I started wondering if I could gain insight into what the phone was doing while locked and powered. I thought I remembered that the Console app on MacOS could stream logs from iOS devices, in addition to those of the host Mac system. I started out by filtering the copious log messages by “face,” and then excluding terms like “interface.”
In time I learned that there was something called com.mediaanalysisd.photos.face that sounded processing, only it wasn’t getting the chance to run because it wasn’t compatible with something else that was running. By watching the logs a bit I learned of other agents that contended with eachother for the chance to run on my sleeping phone. Many of them also seemed involved in analyzing photos, for example:
I’ve seen most of them get chances to run. Once they run, they run for tens of minutes. However, they all take a back seat to com.apple.corespotlight.knowledge and the associated spotlightknowledged process, which runs for at least 15 minutes at a time, and seems to get the chance to run every other time. I’d guess than in the last 18 hours or so it’s been running for at least 10 hours. I have no idea what it’s doing, either.
Most of the other agents write a fair amount of information to the console. It can be pretty esoteric, but one gets a sense of progress. Spotlightknowledged says very little and most of what it says comes at the beginning of a run. From then on, the main indication of progress is dasd giving updates on how long it’s been running and all the other jobs that aren’t running because of it. Then, at the end, often near the 15 minute mark, spotlightknowledged announces “SpotlightKnowledge – too long till check in” and then that it’s exiting. Often as not, dasd then gets spotlightknowledged running again, though sometimes it gives others a chance.
Google doesn’t turn up any information about com.apple.corespotlight.knowledge or spotlightknowledged, none at all! There is Siri Knowledge which provides access, in various contexts, to information from Wikipedia, Wolfram Alpha and perhaps other curated sources. There is also something called knowledgeC.db tucked away in /private/var/mobile/Library/CoreDuet/Knowledge/ which stores information on all sorts of your activities on your iOS device. Spotlightknowledged could be involved in either of those, both of them, or neither of them. Whatever it’s doing, it seems to be busy.
Or maybe spotlightknowledged is buggy? “SpotlightKnowledge – too long till check in,” along with the relative lack of other log messages makes me wonder if it never finishes what it’s setting out to do and starts all over again. In doing so it deprives other agents, like the one doing face analysis, of time to do their own work.