Commit a45df32d authored by Risan's avatar Risan Committed by Commit Bot

Limit timestamp map size in ArcFileSystemWatcher

The unlimited map size is potentially causing OOM (and there are
evidence that it might caused OOM).

Here, the size of the map is limited to the max size of inotify event
queue since it we are degrading our support for when we have too files
more than the inotify events anyway.

BUG=1134755
TEST=Decrease the limit and print the map size to see the capping
work.

Change-Id: Ifcaecde655afaf2d44ab48cef5701b9ee7fca8eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2456726Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Risan <risan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815010}
parent af82ff26
......@@ -69,6 +69,12 @@ constexpr base::FilePath::CharType kAndroidMyFilesDownloadsDir[] =
const base::TimeDelta kBuildTimestampMapDelay =
base::TimeDelta::FromMilliseconds(1000);
// Providing the similar guarantee as
// /proc/sys/fs/inotify/max_queued_events
// It probably does not make sense to store more than the max queued limit in
// inotify, since the inotify system degrades when that happens anyway.
const size_t kMaxTimestampMapSize = 16384;
// Compares two TimestampMaps and returns the list of file paths added/removed
// or whose timestamp have changed.
std::vector<base::FilePath> CollectChangedPaths(
......@@ -118,6 +124,8 @@ TimestampMap BuildTimestampMap(base::FilePath cros_dir,
base::FileEnumerator::FILES);
for (base::FilePath cros_path = enumerator.Next(); !cros_path.empty();
cros_path = enumerator.Next()) {
if (timestamp_map.size() >= kMaxTimestampMapSize)
break;
// Skip non-media files for efficiency.
if (!HasAndroidSupportedMediaExtension(cros_path))
continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment