V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
bosskwei
V2EX  ›  Apple

MacOS 下 launchd 高磁盘写入的原因是 Spotlight

  •  
  •   bosskwei · 2022-08-23 17:47:08 +08:00 · 2316 次点击
    这是一个创建于 857 天前的主题,其中的信息可能已经有所发展或是发生改变。

    MacOS 下 launchd 平均每天磁盘写入都超过 10GB ,前 ubuntu 用户表示真的忍不了,经过分析写入文件位于 /var/log/com.apple.xpc.launchd/ 的 log ,平均每分钟写入 10M 以上,全是用于启动 SpotLight 的操作

    这个 mdworker 进程被频繁启动然后再被 kill ,不知道是哪个鬼才想出来的好主意,库克知道么?

    2022-08-23 17:43:11.908127 <Notice>: Last log repeated 2 times
    2022-08-23 17:43:11.907854 (system) <Warning>: failed lookup: name = com.apple.AppleLOM.Watchdog, flags = 0x1, requestor = watchdogd[301], error = 3: No such process
    2022-08-23 17:43:27.284613 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000) <Notice>: internal event: WILL_SPAWN, code = 0
    2022-08-23 17:43:27.284718 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000) <Notice>: service state: spawn scheduled
    2022-08-23 17:43:27.284723 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000) <Notice>: service state: spawning
    2022-08-23 17:43:27.285151 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000) <Notice>: launching: ipc (mach)
    2022-08-23 17:43:27.286377 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: xpcproxy spawned with pid 55975
    2022-08-23 17:43:27.286406 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: internal event: SPAWNED, code = 0
    2022-08-23 17:43:27.286413 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: service state: xpcproxy
    2022-08-23 17:43:27.286432 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: internal event: SOURCE_ATTACH, code = 0
    2022-08-23 17:43:27.295285 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: service state: running
    2022-08-23 17:43:27.295298 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: internal event: INIT, code = 0
    2022-08-23 17:43:27.295308 (user/501/com.apple.mdworker.shared.0B000000-0300-0000-0000-000000000000 [55975]) <Notice>: Successfully spawned mdworker_shared[55975] because ipc (mach)
    2022-08-23 17:43:41.908483 (system) <Warning>: failed lookup: name = com.apple.AppleLOM.Watchdog, flags = 0x1, requestor = watchdogd[301], error = 3: No such process
    2022-08-23 17:43:59.239397 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000) <Notice>: internal event: WILL_SPAWN, code = 0
    2022-08-23 17:43:59.239508 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000) <Notice>: service state: spawn scheduled
    2022-08-23 17:43:59.239512 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000) <Notice>: service state: spawning
    2022-08-23 17:43:59.239939 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000) <Notice>: launching: ipc (mach)
    2022-08-23 17:43:59.241171 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: xpcproxy spawned with pid 55976
    2022-08-23 17:43:59.241204 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: internal event: SPAWNED, code = 0
    2022-08-23 17:43:59.241211 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: service state: xpcproxy
    2022-08-23 17:43:59.241230 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: internal event: SOURCE_ATTACH, code = 0
    2022-08-23 17:43:59.250474 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: service state: running
    2022-08-23 17:43:59.250492 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: internal event: INIT, code = 0
    2022-08-23 17:43:59.250505 (user/501/com.apple.mdworker.shared.0A000000-0300-0000-0000-000000000000 [55976]) <Notice>: Successfully spawned mdworker_shared[55976] because ipc (mach)
    2022-08-23 17:44:09.824141 (gui/501 [100019]) <Warning>: failed lookup: name = com.apple.DFRSystemExtra.InputMenu.disableinput, flags = 0x1, requestor = TextInputMenuAg[724], error = 3: No such process
    2022-08-23 17:44:11.909041 <Notice>: Last log repeated 1 times
    2022-08-23 17:44:11.908979 (system) <Warning>: failed lookup: name = com.apple.AppleLOM.Watchdog, flags = 0x1, requestor = watchdogd[301], error = 3: No such process
    2022-08-23 17:44:13.598349 (gui/501 [100019]) <Warning>: failed lookup: name = com.apple.DFRSystemExtra.InputMenu.disableinput, flags = 0x1, requestor = TextInputMenuAg[724], error = 3: No such process
    2022-08-23 17:44:39.219725 <Notice>: Last log repeated 3 times
    
    第 1 条附言  ·  2022-08-24 17:13:46 +08:00
    此话题终结,感谢 12 楼
    第 2 条附言  ·  2022-08-24 20:54:40 +08:00
    时隔一日更新:
    + Macbook Air M2 16 + 1T ,每日高强度 Chrome + VSCode
    + 没有关闭 Spotlight 之前,每日 launchd + md* 写入约 10-20 GB ,kernel_taskd 写入 3-5 GB 左右
    + 关闭 Spotlight 后,launchd 写入约 0.5-2 GB ,kernel_taskd 写入 2 GB 左右
    13 条回复    2022-08-24 17:13:19 +08:00
    starrystarry
        1
    starrystarry  
       2022-08-23 18:26:56 +08:00
    这个 bug 自从 macOS 10.14.6 的某个 Combo 更新之后就有了
    国外论坛反馈 /private/var/folders/*/*/C/com.Apple.metadata.mdworker 里有数十万的空文件夹
    xtinput
        2
    xtinput  
       2022-08-23 19:15:07 +08:00
    关掉重建就 OK 了,这个是创建系统搜索的索引
    xtinput
        3
    xtinput  
       2022-08-23 19:22:56 +08:00
    @starrystarry #1 我在用 macOS13b5 ,没找到这个文件夹
    bosskwei
        4
    bosskwei  
    OP
       2022-08-23 19:45:20 +08:00
    @starrystarry 我找到了你说的这个帖子,一年前就有人讨论了 https://forums.macrumors.com/threads/spotlight-mdworker-shared-file-flooding-system-log-removal-stops-search-index-from-working-properly.2248163/page-4


    @xtinput 自己看 log 吧 /var/log/com.apple.xpc.launchd/
    xtinput
        5
    xtinput  
       2022-08-23 19:58:37 +08:00
    我在活动监视器里面只看到 mdworker 进程读磁盘,没看到它写入
    试试重建 Spotlight 索引吧
    bosskwei
        6
    bosskwei  
    OP
       2022-08-23 20:07:27 +08:00
    @xtinput 大哥,你看一眼 log 好么??怎么给你说 A 你总是回复 B 。。。。。这个读写是 launchd 的
    bosskwei
        7
    bosskwei  
    OP
       2022-08-23 20:07:59 +08:00
    @xtinput 你不会用 terminal ?? 搞笑呢
    bosskwei
        8
    bosskwei  
    OP
       2022-08-23 20:08:17 +08:00
    vim /var/log/com.apple.xpc.launchd/* 懂了么?
    xtinput
        9
    xtinput  
       2022-08-23 20:21:50 +08:00
    你的意思是每分钟写入了 10M 的日志???我这 launchd 进程 10 天写入量是 42GB
    既然知道是 Spotlight ,那把它关了就 OK 了呀

    /var/log/com.apple.xpc.launchd/ 文件夹下面只有 3 个文件,最早的一个是今天下午创建的,三个文件一共 20M 不到
    bosskwei
        10
    bosskwei  
    OP
       2022-08-23 21:18:09 +08:00
    @xtinput 看文件的尺寸没有意义,因为旧的日志会被自动删除。你进去看里面的内容,搜索 mdworker.shared 试试,有惊喜 :)
    xtinput
        11
    xtinput  
       2022-08-23 21:24:55 +08:00
    活动监视器有硬盘写入记录呀 launchd 10 天 42GB
    YoungShook
        12
    YoungShook  
       2022-08-24 14:52:14 +08:00   ❤️ 1
    Disable spotlight indexing on macOS to heavily speed up Virtual Instances.
    # massively increase virtualized macOS by disabling spotlight.
    sudo mdutil -i off -a

    # since you can't use spotlight to find apps, you can renable with
    # sudo mdutil -i on -a
    bosskwei
        13
    bosskwei  
    OP
       2022-08-24 17:13:19 +08:00
    @YoungShook 感谢,这个命令不用关 sip ,非常有用。我试试搞个 crontab 定时任务,每天只允许 spotlight 启动一个小时,然后立刻 disable ,这样应该既可以用功能又不会一直在后台刷新
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2814 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:00 · PVG 22:00 · LAX 06:00 · JFK 09:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.