• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_RECLAIM_STRATEGY_MEMCG_MGR_H
17 #define OHOS_MEMORY_MEMMGR_RECLAIM_STRATEGY_MEMCG_MGR_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "single_instance.h"
23 #include "memcg.h"
24 
25 namespace OHOS {
26 namespace Memory {
27 class MemcgMgr final {
28     DECLARE_SINGLE_INSTANCE_BASE(MemcgMgr);
29 public:
30     ~MemcgMgr();
31 
32     // root memcg operations
33     Memcg* GetRootMemcg() const;
34     bool SetRootMemcgPara();
35 
36     // user memcg operations
37     UserMemcg* GetUserMemcg(unsigned int userId);
38     UserMemcg* AddUserMemcg(unsigned int userId);
39     bool RemoveUserMemcg(unsigned int userId);
40     bool UpdateMemcgScoreAndReclaimRatios(unsigned int userId, int score, const ReclaimRatios& ratios);
41     bool AddProcToMemcg(unsigned int pid, unsigned int userId);
42     bool SwapInMemcg(unsigned int userId); // load memcg data 100% to mem
43     SwapInfo* GetMemcgSwapInfo(unsigned int userId);
44     MemInfo* GetMemcgMemInfo(unsigned int userId);
45 private:
46     MemcgMgr();
47     Memcg* rootMemcg_;
48     std::map<int, UserMemcg*> userMemcgsMap_; // map<userId, UserMemcg*>
49 }; // end class MemcgMgr
50 } // namespace Memory
51 } // namespace OHOS
52 #endif // OHOS_MEMORY_MEMMGR_RECLAIM_STRATEGY_MEMCG_MGR_H
53