Commit 6f2ff42c authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

android: Raise browser fd limit

Getting too many file open error reports relatively frequently.
Try raising the fd limit to see if things improve.

Changed base implementation to only increase the fd limit. In case
this is used in webview and app has already set the limit above
what we need.

Bug: 842271
Change-Id: I418ea96b4a51fd15e8166d111a191d00153a565c
Reviewed-on: https://chromium-review.googlesource.com/1056070Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558381}
parent 305201ae
...@@ -265,10 +265,11 @@ BASE_EXPORT size_t GetPageSize(); ...@@ -265,10 +265,11 @@ BASE_EXPORT size_t GetPageSize();
BASE_EXPORT size_t GetMaxFds(); BASE_EXPORT size_t GetMaxFds();
#if defined(OS_POSIX) && !defined(OS_FUCHSIA) #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
// Sets the file descriptor soft limit to |max_descriptors| or the OS hard // Increases the file descriptor soft limit to |max_descriptors| or the OS hard
// limit, whichever is lower. // limit, whichever is lower. If the limit is already higher than
BASE_EXPORT void SetFdLimit(unsigned int max_descriptors); // |max_descriptors|, then nothing happens.
#endif // defined(OS_POSIX) BASE_EXPORT void IncreaseFdLimitTo(unsigned int max_descriptors);
#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_ANDROID) || defined(OS_AIX) || defined(OS_FUCHSIA) defined(OS_ANDROID) || defined(OS_AIX) || defined(OS_FUCHSIA)
......
...@@ -47,7 +47,7 @@ size_t GetMaxFds() { ...@@ -47,7 +47,7 @@ size_t GetMaxFds() {
return static_cast<size_t>(max_fds); return static_cast<size_t>(max_fds);
} }
void SetFdLimit(unsigned int max_descriptors) { void IncreaseFdLimitTo(unsigned int max_descriptors) {
// Unimplemented. // Unimplemented.
} }
......
...@@ -71,11 +71,12 @@ size_t GetMaxFds() { ...@@ -71,11 +71,12 @@ size_t GetMaxFds() {
return static_cast<size_t>(max_fds); return static_cast<size_t>(max_fds);
} }
void IncreaseFdLimitTo(unsigned int max_descriptors) {
void SetFdLimit(unsigned int max_descriptors) {
struct rlimit limits; struct rlimit limits;
if (getrlimit(RLIMIT_NOFILE, &limits) == 0) { if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
unsigned int new_limit = max_descriptors; unsigned int new_limit = max_descriptors;
if (max_descriptors <= limits.rlim_cur)
return;
if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) { if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) {
new_limit = limits.rlim_max; new_limit = limits.rlim_max;
} }
......
...@@ -597,7 +597,8 @@ int BrowserMainLoop::EarlyInitialization() { ...@@ -597,7 +597,8 @@ int BrowserMainLoop::EarlyInitialization() {
command_line->GetSwitchValueASCII(switches::kDisableFeatures)); command_line->GetSwitchValueASCII(switches::kDisableFeatures));
} }
#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_CHROMEOS) || \
defined(OS_ANDROID)
// We use quite a few file descriptors for our IPC as well as disk the disk // We use quite a few file descriptors for our IPC as well as disk the disk
// cache,and the default limit on the Mac is low (256), so bump it up. // cache,and the default limit on the Mac is low (256), so bump it up.
...@@ -605,8 +606,9 @@ int BrowserMainLoop::EarlyInitialization() { ...@@ -605,8 +606,9 @@ int BrowserMainLoop::EarlyInitialization() {
// Low soft limits combined with liberal use of file descriptors means power // Low soft limits combined with liberal use of file descriptors means power
// users can easily hit this limit with many open tabs. Bump up the limit to // users can easily hit this limit with many open tabs. Bump up the limit to
// an arbitrarily high number. See https://crbug.com/539567 // an arbitrarily high number. See https://crbug.com/539567
base::SetFdLimit(8192); base::IncreaseFdLimitTo(8192);
#endif // defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_CHROMEOS) ||
// defined(OS_ANDROID)
#if defined(OS_WIN) #if defined(OS_WIN)
net::EnsureWinsockInit(); net::EnsureWinsockInit();
......
...@@ -52,9 +52,9 @@ const int kChunkSize = 32 * 1024; ...@@ -52,9 +52,9 @@ const int kChunkSize = 32 * 1024;
// As of 2017-01-12, this is a typical per-tab limit on HTTP connections. // As of 2017-01-12, this is a typical per-tab limit on HTTP connections.
const int kMaxParallelOperations = 10; const int kMaxParallelOperations = 10;
void MaybeSetFdLimit(unsigned int max_descriptors) { void MaybeIncreaseFdLimitTo(unsigned int max_descriptors) {
#if defined(OS_POSIX) && !defined(OS_FUCHSIA) #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
base::SetFdLimit(max_descriptors); base::IncreaseFdLimitTo(max_descriptors);
#endif #endif
} }
...@@ -70,20 +70,11 @@ enum class WhatToRead { ...@@ -70,20 +70,11 @@ enum class WhatToRead {
class DiskCachePerfTest : public DiskCacheTestWithCache { class DiskCachePerfTest : public DiskCacheTestWithCache {
public: public:
DiskCachePerfTest() : saved_fd_limit_(base::GetMaxFds()) { DiskCachePerfTest() { MaybeIncreaseFdLimitTo(kFdLimitForCacheTests); }
if (saved_fd_limit_ < kFdLimitForCacheTests)
MaybeSetFdLimit(kFdLimitForCacheTests);
}
~DiskCachePerfTest() override {
if (saved_fd_limit_ < kFdLimitForCacheTests)
MaybeSetFdLimit(saved_fd_limit_);
}
const std::vector<TestEntry>& entries() const { return entries_; } const std::vector<TestEntry>& entries() const { return entries_; }
protected: protected:
// Helper methods for constructing tests. // Helper methods for constructing tests.
bool TimeWrites(); bool TimeWrites();
bool TimeReads(WhatToRead what_to_read, const char* timer_message); bool TimeReads(WhatToRead what_to_read, const char* timer_message);
...@@ -104,9 +95,6 @@ class DiskCachePerfTest : public DiskCacheTestWithCache { ...@@ -104,9 +95,6 @@ class DiskCachePerfTest : public DiskCacheTestWithCache {
const size_t kFdLimitForCacheTests = 8192; const size_t kFdLimitForCacheTests = 8192;
std::vector<TestEntry> entries_; std::vector<TestEntry> entries_;
private:
const size_t saved_fd_limit_;
}; };
class WriteHandler { class WriteHandler {
......
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