Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent open files leak fix #2

merged 4 commits into from Feb 22, 2015


Copy link

@plucid plucid commented Feb 13, 2015

This fixes a performance problem with (at least) incremental backups. My incr backups were slower the longer it was since the last reboot. Investigation showed the delay was proportional to the size of open_files.dat, with the indexing phase taking over an hour a week after a reboot instead of ~4 minutes seen immediately after a reboot. The problem is that open_files.dat, and the in-memory representation in 'open_write_files', contains references to many files which are no longer open. On my system, there should be around 300 open files, but after a week, we think there are about 90K open files.

Code in ChangeJournalWatcher.cpp failed to remove many files from open_write_files. Most of that was because USN_REASON_RENAME_OLD_NAME should be treated like USN_REASON_CLOSE when handling a normal file, removing the file from open_write_files.

The other leak was a timing problem - if multiple USN change journal records for a single file are split across multiple calls to ChangeJournalWatcher::update(), the file might get added to open_write_files after the first update() call, but the USN records for the file in the second update() could be handled completely with local_open_write_files, not noticing that the file had already been added to open_write_files and should be removed on a close journal record. Fix is, when adding a file to local_open_write_files, check whether the file is already in open_write_files, and if yes, remove it from both versions of the map when encountering a close journal record.

Including a compile minor changes. First, PrettyPrintTime was returning an empty string for times less than a second. Second, ChangeJournalWatcher::update_longliving should run its loops within a BeginTransaction/EndTransaction so the updates to the mfiles table are batched.

Fix leak of files in open_write_files when a reference in one batch of journal records causes a file to be added to open_write_files, but then a write reference followed by a close reference in the next batch needs to remove the file from both local_open_write_files and open_write_files.
uroni added a commit that referenced this pull request Feb 22, 2015
@uroni uroni merged commit 06d5a67 into uroni:next Feb 22, 2015
@plucid plucid deleted the PersistentOpenFiles_leak_fix branch February 22, 2015 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
2 participants