1 // Copyright (c) 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "third_party/base/allocator/partition_allocator/partition_root_base.h"
6 
7 #include "build/build_config.h"
8 #include "third_party/base/allocator/partition_allocator/oom.h"
9 #include "third_party/base/allocator/partition_allocator/partition_oom.h"
10 #include "third_party/base/allocator/partition_allocator/partition_page.h"
11 
12 namespace pdfium {
13 namespace base {
14 namespace internal {
15 
OutOfMemory()16 NOINLINE void PartitionRootBase::OutOfMemory() {
17 #if !defined(ARCH_CPU_64_BITS)
18   // Check whether this OOM is due to a lot of super pages that are allocated
19   // but not committed, probably due to http://crbug.com/421387.
20   if (total_size_of_super_pages + total_size_of_direct_mapped_pages -
21           total_size_of_committed_pages >
22       kReasonableSizeOfUnusedPages) {
23     PartitionOutOfMemoryWithLotsOfUncommitedPages();
24   }
25 #endif
26   if (PartitionRootBase::gOomHandlingFunction)
27     (*PartitionRootBase::gOomHandlingFunction)();
28   OOM_CRASH();
29 }
30 
DecommitEmptyPages()31 void PartitionRootBase::DecommitEmptyPages() {
32   for (size_t i = 0; i < kMaxFreeableSpans; ++i) {
33     internal::PartitionPage* page = global_empty_page_ring[i];
34     if (page)
35       page->DecommitIfPossible(this);
36     global_empty_page_ring[i] = nullptr;
37   }
38 }
39 
40 }  // namespace internal
41 }  // namespace base
42 }  // namespace pdfium
43