• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_PURGEABLE_MEM_UTILS_H
17 #define OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_PURGEABLE_MEM_UTILS_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "single_instance.h"
23 
24 namespace OHOS {
25 namespace Memory {
26 struct PurgeableAshmInfo {
27     int sizeKB;
28     int minPriority;
29     std::string idWithTime;
30 };
31 
32 class PurgeableMemUtils {
33     DECLARE_SINGLE_INSTANCE(PurgeableMemUtils);
34 
35 public:
36     bool GetPurgeableHeapInfo(int &reclaimableKB);
37     bool GetProcPurgeableHeapInfo(const int pid, int &reclaimableKB);
38     bool PurgeHeapAll();
39     bool PurgeHeapMemcg(const std::string &memcgPath, const int sizeKB);
40     bool GetPurgeableAshmInfo(int &reclaimableKB, std::vector<PurgeableAshmInfo> &ashmInfoToReclaim);
41     bool PurgeAshmAll();
42     bool PurgeAshmByIdWithTime(const std::string &idWithTime);
43 
44     static const std::string PATH_PURGE_HEAP;
45     static const std::string PATH_PURGEABLE_ASHMEM;
46     static const std::string FILE_PURGE_MEMCG_HEAP;
47     static const std::string ACTIVE_PURGEABLE_HEAP;
48     static const std::string INACTIVE_PURGEABLE_HEAP;
49     static const std::string PINED_PURGEABLE_HEAP;
50     static const std::string PROC_PURGEABLE_HEAP;
51     static const std::string PROC_PINED_PURGEABLE_HEAP;
52     static const unsigned int ASHM_PARAM_SIZE_ONE_LINE;
53     static const unsigned int ASHM_ID_INDEX;
54     static const unsigned int ASHM_ADJ_INDEX;
55     static const unsigned int ASHM_REF_COUNT_INDEX;
56     static const unsigned int ASHM_PURGED_INDEX;
57     static const unsigned int ASHM_SIZE_INDEX;
58     static const unsigned int ASHM_TIME_INDEX;
59     static const unsigned int HEAPINFO_SIZE_ONE_LINE;
60 };
61 } // namespace Memory
62 } // namespace OHOS
63 #endif // OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_PURGEABLE_MEM_UTILS_H
64