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_COMMON_INCLUDE_CONFIG_RECLAIM_CONFIG_H 17 #define OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_CONFIG_RECLAIM_CONFIG_H 18 19 #include <map> 20 #include <string> 21 #include <set> 22 #include <memory> 23 24 #include "libxml/parser.h" 25 #include "libxml/xpath.h" 26 #include "kernel_interface.h" 27 #include "reclaim_strategy_constants.h" 28 #include "reclaim_priority_constants.h" 29 #include "memory_level_constants.h" 30 31 namespace OHOS { 32 namespace Memory { 33 class ZswapdParam { 34 public: 35 int GetMinScore(); 36 void SetMinScore(int minScore); 37 int GetMaxScore(); 38 void SetMaxScore(int maxScore); 39 unsigned int GetMem2zramRatio(); 40 void SetMem2zramRatio(unsigned int mem2zramRatio); 41 unsigned int GetZram2ufsRatio(); 42 void SetZram2ufsRatio(unsigned int zram2ufsRatio); 43 unsigned int GetRefaultThreshold(); 44 void SetRefaultThreshold(unsigned int refaultThreshold); 45 ZswapdParam(); 46 ZswapdParam(int minScore, int maxScore, unsigned int mem2zramRatio, 47 unsigned int zram2ufsRatio, unsigned int refaultThreshold); 48 49 private: 50 int minScore_ = 0; 51 int maxScore_ = 0; 52 unsigned int mem2zramRatio_ = 0; 53 unsigned int zram2ufsRatio_ = 0; 54 unsigned int refaultThreshold_ = 0; 55 }; 56 57 struct ZswapdParamPtrCmp { operatorZswapdParamPtrCmp58 bool operator()(const std::shared_ptr<ZswapdParam> p1, const std::shared_ptr<ZswapdParam> p2) 59 { 60 if (p1->GetMinScore() <= p2->GetMinScore()) { 61 return true; 62 } else { 63 return false; 64 } 65 }; 66 }; 67 68 class ReclaimConfig { 69 public: 70 void ParseConfig(const xmlNodePtr &rootNodePtr); 71 void SetZswapdParamConfig(std::map<std::string, std::string> ¶m); 72 using ReclaimConfigSet = std::set<std::shared_ptr<ZswapdParam>, ZswapdParamPtrCmp>; 73 const ReclaimConfigSet& GetReclaimConfigSet(); 74 void AddReclaimConfigToSet(std::shared_ptr<ZswapdParam> reclaimConfig); 75 void ClearReclaimConfigSet(); 76 ReclaimConfig(); 77 void CheckZswapdParam(std::shared_ptr<ZswapdParam> zswapdParam); 78 void SetDefaultConfig(int minScore, int maxScore, unsigned int mem2zramRatio, 79 unsigned int zram2ufsRatio, unsigned int refaultThreshold); 80 void Dump(int fd); 81 private: 82 ReclaimConfigSet reclaimConfigSet_; 83 }; 84 } // namespace Memory 85 } // namespace OHOS 86 #endif // OHOS_MEMORY_MEMMGR_COMMON_INCLUDE_CONFIG_RECLAIM_CONFIG_H