Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Media store can leave many empty directories, leading to large disk space usage #7690

Open
Twi1ightSparkle opened this issue Jun 12, 2020 · 9 comments
Labels
A-Disk-Space things which fill up the disk S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. z-p3 (Deprecated Label)

Comments

@Twi1ightSparkle
Copy link

Description

On my server, the directory media_store/remote_content currently has 567 746 empty sub directories (takes about 2.5 GB of disk space)

Happy to share logs in a non-public channel or give access to my server for debugging.

Some homeservers seems more affected than others.

2020-06-12-16-07-16
2020-06-12-16-07-25
2020-06-12-16-07-31
2020-06-12-16-07-38

Steps to reproduce

  • uh, have a Synapse running for six months

Version information

  • Homeserver: twilightsparkle.dev

If not matrix.org:

  • Version: 1.15.0

  • Install method: pip

  • Platform: Ubuntu Server 18.04.4 LTS (4.15.0-106-generic x86_64)

VPS (running on KVM I believe)

@Twi1ightSparkle Twi1ightSparkle added the z-bug (Deprecated Label) label Jun 12, 2020
@Twi1ightSparkle Twi1ightSparkle changed the title Several hundred thousand empty sub directories in the media_store/remote_content Several hundred thousand empty sub directories in media_store/remote_content Jun 12, 2020
@clokep clokep added the A-Disk-Space things which fill up the disk label Jun 18, 2020
@clokep
Copy link
Member

clokep commented Jun 25, 2020

This is probably due to the media pruning script not trying to find empty directories to delete. Unfortunately, this is harder to fix than it seems due to race conditions with uploads. (As background the OS takes 4 KiB or something for each empty directory, so 4 KiB * 567,746 = 2.2 GiB or so.)

It should safe to manually delete directories that are empty if you're not uploading any media / have Synapse stopped.

@clokep clokep changed the title Several hundred thousand empty sub directories in media_store/remote_content Media store can leave many empty directories, leading to large disk space usage Jun 25, 2020
@clokep clokep added the z-p3 (Deprecated Label) label Jun 25, 2020
@clokep
Copy link
Member

clokep commented Jun 25, 2020

It could also be beneficial to have the media store create less directories in the future.

@richvdh
Copy link
Member

richvdh commented Sep 21, 2021

another cause for this is that we create directories for remote media before we check that the remote host is reachable (and then never have cause to delete them). This one should be relatively easy to fix - we can just (try to) delete the directory after a failed download.

@erikjohnston erikjohnston added S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. and removed z-bug (Deprecated Label) labels Sep 22, 2021
@skepticalwaves
Copy link

is a manual operation like

find /matrix/synapse/storage/media-store/ -empty -type d -delete

Safe to run to clean up?

@Twi1ightSparkle
Copy link
Author

is a manual operation like

find /matrix/synapse/storage/media-store/ -empty -type d -delete

Safe to run to clean up?

I did something similar to this back when I had this issue. Nothing exploded. But this was a long time ago so can't say how it would work today.
When I did it, I had Synapse stopped, and I made a backup of the media directory first just in case

@richvdh
Copy link
Member

richvdh commented Feb 3, 2022

in theory you could race with synapse creating a new directory, which could then cause a media request to fail. But that's not exactly the end of the world.

@skepticalwaves
Copy link

I'll use it the next time I'm down for maintenance. Thanks.

@clokep
Copy link
Member

clokep commented Feb 3, 2022

It looks like #10924 fixes this for URL cache directories, but those are a bit different since they are time based.

@marius851000
Copy link

marius851000 commented Jul 1, 2022

Another issue that this, in addition to leading to usage of disk space, is that it can make a filesystem run out of inode (like what happened on my homeserver).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Disk-Space things which fill up the disk S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. z-p3 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

6 participants