Saya menggunakan High Sierra di MacBook Pro dengan 16GB RAM dengan SSD.
Mendapat 15G file swap, apakah ada metode untuk membebaskan ruang swap / file tanpa restart?
$ sysctl -a | grep swap
vm.swapusage: total = 15360.00M used = 14468.75M free = 891.25M (encrypted)
vm.compressor_swapout_target_age: 0
vm.swapfileprefix: /private/var/vm/swapfile
debug.intel.swapCount: 0
$ ll -h /var/vm/swap*
-rw------- 1 root wheel 1.0G Apr 30 16:10 /var/vm/swapfile0
-rw------- 1 root wheel 1.0G Apr 30 17:16 /var/vm/swapfile1
-rw------- 1 root wheel 1.0G May 11 21:28 /var/vm/swapfile10
-rw------- 1 root wheel 1.0G May 11 21:46 /var/vm/swapfile11
-rw------- 1 root wheel 1.0G May 11 22:04 /var/vm/swapfile12
-rw------- 1 root wheel 1.0G May 11 23:00 /var/vm/swapfile13
-rw------- 1 root wheel 1.0G May 11 23:01 /var/vm/swapfile14
-rw------- 1 root wheel 1.0G May 11 23:02 /var/vm/swapfile15
-rw------- 1 root wheel 1.0G May 2 12:45 /var/vm/swapfile2
-rw------- 1 root wheel 1.0G May 4 14:02 /var/vm/swapfile3
-rw------- 1 root wheel 1.0G May 4 05:50 /var/vm/swapfile4
-rw------- 1 root wheel 1.0G May 8 11:05 /var/vm/swapfile5
-rw------- 1 root wheel 1.0G May 9 16:18 /var/vm/swapfile6
-rw------- 1 root wheel 1.0G May 10 03:02 /var/vm/swapfile7
-rw------- 1 root wheel 1.0G May 11 13:03 /var/vm/swapfile8
-rw------- 1 root wheel 1.0G May 11 21:07 /var/vm/swapfile9
Saya ingin menjatuhkan file-file ini tanpa menonaktifkan dynamic_pager
.
Saya sudah mencoba:
- jalankan
sudo purge
(paksa cache disk untuk dihapus); - keluar dari semua aplikasi yang tidak saya gunakan;
mengelabui sistem dengan membuat file tukar tiruan sebelum dibuat:
cd /var/vm sudo touch swapfile{0..20} 2>/dev/null; sudo chmod 000 swapfile{0..20} 2>/dev/null
tetapi tidak berhasil, karena sistem masih membuat / mengubah file meskipun ada
000
izin, aneh.
Untuk beberapa alasan, htop
menunjukkan memori virtual sebagai 532G, tapi saya percaya itu adalah bug, karena top
menunjukkan kurang digunakan.
Di atas htop
/ top
hanya menampilkan 2 tugas yang berjalan, 445 sedang tidur, CPU tidak digunakan sebanyak itu, tetapi kernel sibuk dengan menukar antara 15G file.
Saya bisa memulai kembali tetapi setelah beberapa hari masalah ini berulang setiap minggu. Idealnya, saya ingin membunuh dan menghancurkan (menghapus) file swap dan mulai lagi pada proses yang sama, tetapi macOS tidak memungkinkan saya untuk melakukannya.
$ sudo rm -fr swapfile*
Password:
rm: cannot remove 'swapfile0': Operation not permitted
Apakah ada peretas yang tersedia untuk memaksa dynamic_pager
menjatuhkan file-file ini? Saya tidak butuh itu.
Btw. File swap ini kosong! Lihat:
$ sudo strings swapfile*
swapfile0
swapfile1
swapfile10
swapfile11
swapfile12
swapfile13
swapfile2
swapfile3
swapfile4
swapfile5
swapfile6
swapfile7
swapfile8
swapfile9
/var/vm$ sudo gzip swapfile*
/var/vm $ ll -h *.gz
-rw------- 1 root wheel 1.6M Apr 30 16:10 swapfile0.gz
-rw------- 1 root wheel 1.6M Apr 30 17:16 swapfile1.gz
-rw------- 1 root wheel 1.6M May 11 21:28 swapfile10.gz
-rw------- 1 root wheel 1.6M May 11 21:46 swapfile11.gz
-rw------- 1 root wheel 1.6M May 11 22:04 swapfile12.gz
-rw------- 1 root wheel 1.6M May 11 23:00 swapfile13.gz
-rw------- 1 root wheel 1.6M May 2 12:45 swapfile2.gz
-rw------- 1 root wheel 1.6M May 4 14:02 swapfile3.gz
-rw------- 1 root wheel 1.6M May 4 05:50 swapfile4.gz
-rw------- 1 root wheel 1.6M May 8 11:05 swapfile5.gz
-rw------- 1 root wheel 1.6M May 9 16:18 swapfile6.gz
-rw------- 1 root wheel 1.6M May 10 03:02 swapfile7.gz
-rw------- 1 root wheel 1.6M May 11 13:03 swapfile8.gz
-rw------- 1 root wheel 1.6M May 11 21:07 swapfile9.gz
Jika ini kosong, mengapa macOS tidak bisa menghapusnya begitu saja. Saya cukup yakin bahwa lambatnya sistem saya (seperti memuat rata-rata dan termasuk sering membekukan mouse) disebabkan oleh penciptaan dan penghapusan file-file ini secara konstan, karena saya tidak memiliki proses lain yang banyak menggunakan CPU saya.
Sebagai contoh, sebelum menulis posting ini, saya punya 13G file swap (masing-masing 1G), selama tulisan saya dan menempelkan output di atas saya berakhir dengan 15G (dengan tidak melakukan apa-apa), maka macOS benar-benar dihapus swapfile14
dan swapfile15
(jadi 13G swap) ketika menulis ini. Kemudian dihapus swapfile13
ketika menulis kalimat ini. Kemudian dibuat hingga swapfile16
(16G) saat menulis kalimat ini. Dan dihapus swapfile16
lagi saat menulis kalimat ini. Dan seterusnya. Berantakan sekali. Jika ini adalah file kosong, mengapa macOS terus membuat mereka, ketika itu tidak mengisi apa pun di sana.
Info lain:
$ sudo launchctl list | grep pager
- 0 com.apple.dynamic_pager
$ launchctl print system | grep dynamic_pager
0 0 com.apple.dynamic_pager
$ ps wuax | grep dynamic_pager
# No running?!
$ launchctl dumpstate | grep -A20 com.apple.dynamic_pager
0 0 com.apple.dynamic_pager
--
com.apple.dynamic_pager = {
active count = 0
path = /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
state = waiting
program = /sbin/dynamic_pager
arguments = {
/sbin/dynamic_pager
}
default environment = {
PATH => /usr/bin:/bin:/usr/sbin:/sbin
}
environment = {
XPC_SERVICE_NAME => com.apple.dynamic_pager
}
domain = com.apple.xpc.launchd.domain.system
minimum runtime = 10
exit timeout = 5
runs = 1
successive crashes = 0
excessive crashing = 0
last exit code = 0
Berikut adalah contoh WindowServer
proses 1 detik , di mana setidaknya setengah detik dihabiskan untuk swap:
Command: WindowServer
Parent: launchd [1]
Duration: 1.01s
Steps: 10 (100ms sampling interval)
Active cpus: 8
Fan speed: 2159 rpm
Thread 0x1ab Thread name "VM_cswap_trigger" 10 samples (1-10) priority 91 (base 91) cpu time 0.222s
<IO tier 0>
*10 call_continuation + 23 (kernel + 2098423) [0xffffff80004004f7] 1-10
*10 ??? (kernel + 2882629) [0xffffff80004bfc45] 1-10
*6 ??? (kernel + 2883102) [0xffffff80004bfe1e] 1-6
*6 thread_block_reason + 175 (kernel + 2530911) [0xffffff8000469e5f] 1-6
*6 ??? (kernel + 2534903) [0xffffff800046adf7] 1-6
*6 machine_switch_context + 205 (kernel + 3578125) [0xffffff800056990d] 1-6
*1 ??? (kernel + 2883122) [0xffffff80004bfe32] 7
*1 ??? (kernel + 2885317) [0xffffff80004c06c5] 7
*1 c_seg_do_minor_compaction_and_unlock + 303 (kernel + 2886351) [0xffffff80004c0acf] 7
*1 c_seg_minor_compaction_and_unlock + 344 (kernel + 2887576) [0xffffff80004c0f98] (running) 7
*2 ??? (kernel + 2883102) [0xffffff80004bfe1e] 8-9
*2 thread_block_reason + 175 (kernel + 2530911) [0xffffff8000469e5f] 8-9
*2 ??? (kernel + 2534903) [0xffffff800046adf7] 8-9
*2 machine_switch_context + 205 (kernel + 3578125) [0xffffff800056990d] 8-9
*1 ??? (kernel + 2883122) [0xffffff80004bfe32] 10
*1 ??? (kernel + 2885317) [0xffffff80004c06c5] 10
*1 c_seg_do_minor_compaction_and_unlock + 303 (kernel + 2886351) [0xffffff80004c0acf] 10
*1 c_seg_minor_compaction_and_unlock + 633 (kernel + 2887865) [0xffffff80004c10b9] 10
*1 kernel_memory_depopulate + 194 (kernel + 2976354) [0xffffff80004d6a62] 10
*1 pmap_remove_options + 1124 (kernel + 3488404) [0xffffff8000553a94] 10
*1 pmap_remove_range_options + 1988 (kernel + 3485812) [0xffffff8000553074] (running) 10
Thread 0x1ac Thread name "VM_compressor" 10 samples (1-10) priority 91 (base 91) cpu time 0.201s
<IO tier 0>
*6 call_continuation + 23 (kernel + 2098423) [0xffffff80004004f7] 1-6
*6 vm_pageout_iothread_internal_continue + 1129 (kernel + 3134345) [0xffffff80004fd389] 1-6
*6 vm_pageout_compress_page + 268 (kernel + 3135052) [0xffffff80004fd64c] 1-6
*6 vm_compressor_pager_put + 160 (kernel + 2903904) [0xffffff80004c4f60] 1-6
*6 vm_compressor_put + 1389 (kernel + 2900045) [0xffffff80004c404d] 1-6
*1 WKdm_compress_new + 736 (kernel + 2092960) [0xffffff80003fefa0] (running) 1
*1 WKdm_compress_new + 776 (kernel + 2093000) [0xffffff80003fefc8] (running) 2
*1 WKdm_compress_new + 781 (kernel + 2093005) [0xffffff80003fefcd] (running) 3
*1 WKdm_compress_new + 303 (kernel + 2092527) [0xffffff80003fedef] (running) 4
*1 WKdm_compress_new + 748 (kernel + 2092972) [0xffffff80003fefac] (running) 5
*1 WKdm_compress_new + 771 (kernel + 2092995) [0xffffff80003fefc3] (running) 6
*1 vm_pageout_iothread_internal_continue + 0 (kernel + 3133216) [0xffffff80004fcf20] 7
*1 call_continuation + 23 (kernel + 2098423) [0xffffff80004004f7] 8
*1 vm_pageout_iothread_internal_continue + 1129 (kernel + 3134345) [0xffffff80004fd389] 8
*1 vm_pageout_compress_page + 268 (kernel + 3135052) [0xffffff80004fd64c] 8
*1 vm_compressor_pager_put + 127 (kernel + 2903871) [0xffffff80004c4f3f] (running) 8
*2 vm_pageout_iothread_internal_continue + 0 (kernel + 3133216) [0xffffff80004fcf20] 9-10
Thread 0x1ad Thread name "VM_compressor" 10 samples (1-10) priority 91 (base 91) cpu time 0.144s
<IO tier 0>
*3 call_continuation + 23 (kernel + 2098423) [0xffffff80004004f7] 1-3
*3 vm_pageout_iothread_internal_continue + 1129 (kernel + 3134345) [0xffffff80004fd389] 1-3
*3 vm_pageout_compress_page + 268 (kernel + 3135052) [0xffffff80004fd64c] 1-3
*3 vm_compressor_pager_put + 160 (kernel + 2903904) [0xffffff80004c4f60] 1-3
*3 vm_compressor_put + 1389 (kernel + 2900045) [0xffffff80004c404d] 1-3
*1 WKdm_compress_new + 280 (kernel + 2092504) [0xffffff80003fedd8] (running) 1
*1 WKdm_compress_new + 286 (kernel + 2092510) [0xffffff80003fedde] (running) 2
*1 WKdm_compress_new + 309 (kernel + 2092533) [0xffffff80003fedf5] (running) 3
*1 vm_pageout_iothread_internal_continue + 0 (kernel + 3133216) [0xffffff80004fcf20] 4
*2 call_continuation + 23 (kernel + 2098423) [0xffffff80004004f7] 5-6
*1 vm_pageout_iothread_internal_continue + 1187 (kernel + 3134403) [0xffffff80004fd3c3] 5
*1 vm_page_free_list + 124 (kernel + 3219628) [0xffffff80005120ac] 5
*1 vm_page_free_prepare_object + 146 (kernel + 3207826) [0xffffff800050f292] (running) 5
*1 vm_pageout_iothread_internal_continue + 1129 (kernel + 3134345) [0xffffff80004fd389] 6
*1 vm_pageout_compress_page + 304 (kernel + 3135088) [0xffffff80004fd670] (running) 6
*4 vm_pageout_iothread_internal_continue + 0 (kernel + 3133216) [0xffffff80004fcf20] 7-10