• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_PROFILING_MEMORY_PAGE_IDLE_CHECKER_H_
18 #define SRC_PROFILING_MEMORY_PAGE_IDLE_CHECKER_H_
19 
20 #include <set>
21 
22 #include <stddef.h>
23 #include <stdint.h>
24 
25 #include "perfetto/ext/base/scoped_file.h"
26 
27 namespace perfetto {
28 namespace profiling {
29 
30 uint64_t GetFirstPageShare(uint64_t addr, size_t size);
31 uint64_t GetLastPageShare(uint64_t addr, size_t size);
32 
33 class PageIdleChecker {
34  public:
PageIdleChecker(base::ScopedFile page_idle_fd)35   PageIdleChecker(base::ScopedFile page_idle_fd)
36       : page_idle_fd_(std::move(page_idle_fd)) {}
37 
38   // Return number of bytes of allocation of size bytes starting at alloc that
39   // are on unreferenced pages.
40   // Return -1 on error.
41   int64_t OnIdlePage(uint64_t addr, size_t size);
42 
43   void MarkPagesIdle();
44 
45  private:
46   void MarkPageIdle(uint64_t virt_page_nr);
47   // Return 1 if page is idle, 0 if it is not idle, or -1 on error.
48   int IsPageIdle(uint64_t virt_page_nr);
49 
50   std::set<uint64_t> touched_virt_page_nrs_;
51 
52   base::ScopedFile page_idle_fd_;
53 };
54 
55 }  // namespace profiling
56 }  // namespace perfetto
57 
58 #endif  // SRC_PROFILING_MEMORY_PAGE_IDLE_CHECKER_H_
59