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_MEMCG_AVAIL_BUFFER_MANAGER_H 17 #define OHOS_MEMORY_MEMCG_AVAIL_BUFFER_MANAGER_H 18 19 #include "single_instance.h" 20 #include "event_handler.h" 21 #include "reclaim_strategy_constants.h" 22 #include "memmgr_config_manager.h" 23 24 namespace OHOS { 25 namespace Memory { 26 class AvailBufferManager { 27 DECLARE_SINGLE_INSTANCE_BASE(AvailBufferManager) 28 public: 29 bool LoadAvailBufferConfig(); 30 bool WriteAvailBufferToKernel(); 31 bool SetAvailBuffer(std::shared_ptr<AvailBufferConfig> availBuffer); 32 bool LoadAvailBufferFromConfig(); 33 void CloseZswapd(); 34 void InitAvailBuffer(); 35 bool Init(); 36 std::string NumsToString(); 37 initialized()38 inline bool initialized() 39 { 40 return initialized_; 41 }; 42 43 private: 44 bool initialized_ = false; 45 std::shared_ptr<AppExecFwk::EventHandler> handler_; 46 unsigned int availBuffer_ = AVAIL_BUFFER; // default availBuffer 800MB 47 unsigned int minAvailBuffer_ = MIN_AVAIL_BUFFER; // default minAvailBuffer 750MB 48 unsigned int highAvailBuffer_ = HIGH_AVAIL_BUFFER; // default highAvailBuffer 850MB 49 unsigned int swapReserve_ = SWAP_RESERVE; // default swapReserve 200MB 50 bool zramEnable_ = false; 51 unsigned int memTotal_ = 0; 52 AvailBufferManager(); 53 ~AvailBufferManager(); 54 bool GetEventHandler(); 55 void UpdateZramEnableFromKernel(); 56 bool CheckAvailBuffer(std::shared_ptr<AvailBufferConfig> availBuffer); 57 void UpdateMemTotalFromKernel(); 58 }; 59 } // namespace Memory 60 } // namespace OHOS 61 #endif 62