Commit 144069db authored by Matthew Cary's avatar Matthew Cary Committed by Commit Bot

Move GetHandleLimit from SharedMemory to process_metrics.h.

base::SharedMemory, which is being deprecated, exposes a utilty
method GetHandleLimit() which needs to be moved somewhere.
process_metrics.h seems to be a more appropriate place for this
anyway over base::SharedMemory.

Bug: 795291
Change-Id: I1562cca6445c362654ba4a52195c0ec4d53757ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695284
Commit-Queue: Matthew Cary (CET) <mattcary@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676546}
parent 3bae146b
......@@ -98,9 +98,6 @@ class BASE_EXPORT SharedMemory {
// Closes a shared memory handle.
static void CloseHandle(const SharedMemoryHandle& handle);
// Returns the maximum number of handles that can be open at once per process.
static size_t GetHandleLimit();
// Duplicates The underlying OS primitive. Returns an invalid handle on
// failure. The caller is responsible for destroying the duplicated OS
// primitive.
......
......@@ -38,13 +38,6 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) {
handle.Close();
}
// static
size_t SharedMemory::GetHandleLimit() {
// Duplicated from the internal Magenta kernel constant kMaxHandleCount
// (kernel/lib/zircon/zircon.cpp).
return 256 * 1024u;
}
bool SharedMemory::CreateAndMapAnonymous(size_t size) {
return CreateAnonymous(size) && Map(size);
}
......
......@@ -98,11 +98,6 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) {
handle.Close();
}
// static
size_t SharedMemory::GetHandleLimit() {
return GetMaxFds();
}
// static
SharedMemoryHandle SharedMemory::DuplicateHandle(
const SharedMemoryHandle& handle) {
......
......@@ -59,11 +59,6 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) {
handle.Close();
}
// static
size_t SharedMemory::GetHandleLimit() {
return GetMaxFds();
}
// static
SharedMemoryHandle SharedMemory::DuplicateHandle(
const SharedMemoryHandle& handle) {
......
......@@ -162,13 +162,6 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) {
handle.Close();
}
// static
size_t SharedMemory::GetHandleLimit() {
// Rounded down from value reported here:
// http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx
return static_cast<size_t>(1 << 23);
}
// static
SharedMemoryHandle SharedMemory::DuplicateHandle(
const SharedMemoryHandle& handle) {
......
......@@ -254,6 +254,9 @@ BASE_EXPORT size_t GetPageSize();
// at once. If the number is unavailable, a conservative best guess is returned.
BASE_EXPORT size_t GetMaxFds();
// Returns the maximum number of handles that can be open at once per process.
BASE_EXPORT size_t GetHandleLimit();
#if defined(OS_POSIX)
// Increases the file descriptor soft limit to |max_descriptors| or the OS hard
// limit, whichever is lower. If the limit is already higher than
......
......@@ -12,6 +12,12 @@ size_t GetMaxFds() {
return FDIO_MAX_FD;
}
size_t GetHandleLimit() {
// Duplicated from the internal Magenta kernel constant kMaxHandleCount
// (zircon/kernel/object/handle.cc).
return 256 * 1024u;
}
size_t GetSystemCommitCharge() {
// TODO(https://crbug.com/926581): Fuchsia does not support this.
return 0;
......
......@@ -71,6 +71,15 @@ size_t GetMaxFds() {
return static_cast<size_t>(max_fds);
}
size_t GetHandleLimit() {
#if defined(OS_MACOSX)
// Taken from a small test that allocated ports in a loop.
return static_cast<size_t>(1 << 18);
#else
return GetMaxFds();
#endif
}
void IncreaseFdLimitTo(unsigned int max_descriptors) {
struct rlimit limits;
if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
......
......@@ -129,6 +129,12 @@ size_t GetMaxFds() {
return std::numeric_limits<size_t>::max();
}
size_t GetHandleLimit() {
// Rounded down from value reported here:
// http://blogs.technet.com/b/markrussinovich/archive/2009/09/29/3283844.aspx
return static_cast<size_t>(1 << 23);
}
// static
std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
ProcessHandle process) {
......
......@@ -26,6 +26,7 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process_metrics.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
......@@ -362,7 +363,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl(
is_shutdown_(false),
enable_resource_scheduler_(enable_resource_scheduler),
num_in_flight_requests_(0),
max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()),
max_num_in_flight_requests_(base::GetHandleLimit()),
max_num_in_flight_requests_per_process_(static_cast<int>(
max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)),
max_outstanding_requests_cost_per_process_(
......
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