Why did Vim create a constantly growing .swp file?

126 views Asked by At

Someone had opened vi via ssh, and pasted output into a buffer, and then later closed / crashed that terminal. The system was later discovered to be out of disk.

Self-answering.

Prior unaddressed reports, usually with no or mocking responses:

https://groups.google.com/g/vim_dev/c/RRJOfwOXtlA?pli=1

I use vim on Linux all the time and found a problem with creating just huge swp files that can take up all the hard disk space. If you open vim and copy a large text that can cause the linux console to hang and then you force close the console, after a couple of days the swp file size can reach hundreds of gigabytes. I have already encountered this problem twice and each time I had to look for where these swp files were created in which directory. I am using vim version 8.0.1453.

https://www.reddit.com/r/vim/comments/8oy57j/issue_about_huge_swp_file_cause_disk_full/

today ,one of my linux server disk full and i find two vim swap file cause this problem

https://www.reddit.com/r/vim/comments/86ny08/cause_of_300gb_swap_file_oo/

I had a text file (python code, maybe 100 lines) open for a few days and afterwards delete it (and, at some point, closed the vim terminal holding it). Lo and behold, a few days later I run out of space and track down the issue to ~/.vim/file.py.swap eating up a whopping 298GBs of disk

1

There are 1 answers

0
Cireo On

My immediate suspicion on "pasted into buffer" was that it was not done in insert mode, which triggered some repeated commands to be executed.

I was able to reproduce this very quickly by opening a new file, and typing commands similar to

  • 100000iA<esc> (create a long line)
  • yy10000000p (paste it a lot of times) I did some other poking around with saving partial versions, so there might be more to the reproduction (which I don't plan to reproduce, see below).

The following behaviors were observed

  1. .swp file grew rather quickly (~1GB/sec)
  2. vim process that was unkillable, even by sudo kill -9 (osx)
    1. There was a plugin subprocess that was also unkillable
    2. Closing the terminal holding vi did nothing
    3. Tried with Full Disk Access enabled, didn't help
    4. Didn't disable System Integrity Protection
    5. Normal reboot resolved
  3. Removing the .swp file
    1. This only appeared to stop it
    2. The .swp file returned a few minutes later (still growing)

Version info

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 01 2022 15:00:53)
macOS version - x86_64
Included patches: 1-350