summaryrefslogtreecommitdiff
path: root/third_party/base/allocator/partition_allocator/partition_root_base.cc
blob: 313658419a96d1b1ac9897f2510ab8af8123beba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/base/allocator/partition_allocator/partition_root_base.h"

#include "build/build_config.h"
#include "third_party/base/allocator/partition_allocator/oom.h"
#include "third_party/base/allocator/partition_allocator/partition_oom.h"
#include "third_party/base/allocator/partition_allocator/partition_page.h"

namespace pdfium {
namespace base {
namespace internal {

NOINLINE void PartitionRootBase::OutOfMemory() {
#if !defined(ARCH_CPU_64_BITS)
  // Check whether this OOM is due to a lot of super pages that are allocated
  // but not committed, probably due to http://crbug.com/421387.
  if (total_size_of_super_pages + total_size_of_direct_mapped_pages -
          total_size_of_committed_pages >
      kReasonableSizeOfUnusedPages) {
    PartitionOutOfMemoryWithLotsOfUncommitedPages();
  }
#endif
  if (PartitionRootBase::gOomHandlingFunction)
    (*PartitionRootBase::gOomHandlingFunction)();
  OOM_CRASH();
}

void PartitionRootBase::DecommitEmptyPages() {
  for (size_t i = 0; i < kMaxFreeableSpans; ++i) {
    internal::PartitionPage* page = global_empty_page_ring[i];
    if (page)
      page->DecommitIfPossible(this);
    global_empty_page_ring[i] = nullptr;
  }
}

}  // namespace internal
}  // namespace base
}  // namespace pdfium