diff --git a/bundle.json b/bundle.json index 274dd3e..f1fa9e0 100644 --- a/bundle.json +++ b/bundle.json @@ -66,7 +66,8 @@ ] }, "features": [ - "memmgr_purgeable_memory" + "memmgr_purgeable_memory", + "memmgr_hyperhold_memory" ] } } diff --git a/common/src/kernel_interface.cpp b/common/src/kernel_interface.cpp index 9bac802..cb8297e 100644 --- a/common/src/kernel_interface.cpp +++ b/common/src/kernel_interface.cpp @@ -41,8 +41,13 @@ const std::string KernelInterface::ROOT_PROC_PATH = "/proc"; const std::string KernelInterface::MEMCG_BASE_PATH = "/dev/memcg"; const std::string KernelInterface::FILE_MEMCG_PROCS = "cgroup.procs"; +#ifdef USE_HYPERHOLD_MEMORY const std::string KernelInterface::ZWAPD_PRESSURE_SHOW_PATH = "/dev/memcg/memory.zswapd_pressure_show"; const std::string KernelInterface::ZWAPD_PRESSURE_SHOW_BUFFER_SIZE = "buffer_size"; +#else +const std::string KernelInterface::ZWAPD_PRESSURE_SHOW_PATH = "/proc/meminfo"; +const std::string KernelInterface::ZWAPD_PRESSURE_SHOW_BUFFER_SIZE = "MemAvailable"; +#endif const std::string KernelInterface::MEMINFO_PATH = "/proc/meminfo"; const std::string KernelInterface::FILE_PROC_STATUS = "status"; const std::string KernelInterface::TOTAL_MEMORY = "MemTotal"; @@ -356,8 +361,13 @@ int KernelInterface::GetCurrentBuffer() ReadZswapdPressureShow(result); auto value = result.find(ZWAPD_PRESSURE_SHOW_BUFFER_SIZE); if (value != result.end()) { +#ifdef USE_HYPERHOLD_MEMORY HILOGD("buffer_size=%{public}s MB", result[ZWAPD_PRESSURE_SHOW_BUFFER_SIZE].c_str()); return atoi(result[ZWAPD_PRESSURE_SHOW_BUFFER_SIZE].c_str()) * KB_PER_MB; +#else + HILOGD("buffer_size=%{public}s KB", result[ZWAPD_PRESSURE_SHOW_BUFFER_SIZE].c_str()); + return atoi(result[ZWAPD_PRESSURE_SHOW_BUFFER_SIZE].c_str()); +#endif } return MAX_BUFFER_KB; } diff --git a/memmgr.gni b/memmgr.gni index c478c9a..35b9a4f 100644 --- a/memmgr.gni +++ b/memmgr.gni @@ -32,4 +32,5 @@ declare_args() { } memmgr_purgeable_memory = false + memmgr_hyperhold_memory = false } diff --git a/services/memmgrservice/BUILD.gn b/services/memmgrservice/BUILD.gn index 96ab0b2..1429941 100644 --- a/services/memmgrservice/BUILD.gn +++ b/services/memmgrservice/BUILD.gn @@ -54,6 +54,9 @@ config("memory_memmgr_config") { defines += [ "USE_PURGEABLE_MEMORY" ] include_dirs += [ "include/purgeable_mem_manager/" ] } + if (memmgr_hyperhold_memory) { + defines += [ "USE_HYPERHOLD_MEMORY" ] + } } ohos_shared_library("memmgrservice") { diff --git a/services/memmgrservice/src/mem_mgr_service.cpp b/services/memmgrservice/src/mem_mgr_service.cpp index 2029307..80d0632 100644 --- a/services/memmgrservice/src/mem_mgr_service.cpp +++ b/services/memmgrservice/src/mem_mgr_service.cpp @@ -60,11 +60,13 @@ bool MemMgrService::Init() // init multiple account manager MultiAccountManager::GetInstance().Init(); +#ifdef USE_HYPERHOLD_MEMORY // init reclaim strategy manager if (!ReclaimStrategyManager::GetInstance().Init()) { HILOGE("ReclaimStrategyManager init failed"); return false; } +#endif // init event center, then managers above can work by event trigger if (!MemMgrEventCenter::GetInstance().Init()) { @@ -72,8 +74,11 @@ bool MemMgrService::Init() return false; } +#ifdef USE_HYPERHOLD_MEMORY // init nandlife controller NandLifeController::GetInstance().Init(); +#endif + HILOGI("init successed"); return true; } diff --git a/services/memmgrservice/src/purgeable_mem_manager/purgeable_mem_manager.cpp b/services/memmgrservice/src/purgeable_mem_manager/purgeable_mem_manager.cpp index 425bab5..4dc8077 100644 --- a/services/memmgrservice/src/purgeable_mem_manager/purgeable_mem_manager.cpp +++ b/services/memmgrservice/src/purgeable_mem_manager/purgeable_mem_manager.cpp @@ -51,9 +51,11 @@ PurgeableMemManager::PurgeableMemManager() bool PurgeableMemManager::GetEventHandler() { +#ifdef USE_HYPERHOLD_MEMORY if (!handler_) { handler_ = ReclaimStrategyManager::GetInstance().GetEventHandler(); } +#endif if (!handler_) { MAKE_POINTER(handler_, shared, AppExecFwk::EventHandler, "failed to create event handler", return false, AppExecFwk::EventRunner::Create()); diff --git a/services/memmgrservice/src/reclaim_priority_manager/multi_account_manager.cpp b/services/memmgrservice/src/reclaim_priority_manager/multi_account_manager.cpp index 74f7cfb..9ce5654 100644 --- a/services/memmgrservice/src/reclaim_priority_manager/multi_account_manager.cpp +++ b/services/memmgrservice/src/reclaim_priority_manager/multi_account_manager.cpp @@ -109,7 +109,9 @@ bool MultiAccountManager::SetAccountPriority(int accountId, std::string accountN HILOGI("Set acccount priority succeed, accountId = %{public}d, old = %{public}d, new = %{public}d.", accountId, oldPriority, accountInfo->GetPriority()); +#ifdef USE_HYPERHOLD_MEMORY ReclaimStrategyManager::GetInstance().NotifyAccountPriorityChanged(accountId, accountInfo->GetPriority()); +#endif return true; } @@ -244,7 +246,9 @@ bool MultiAccountManager::HandleAccountColdSwitch(std::vector &switchedAcco for (int accountId : switchedAccountIds) { HILOGI("Account cold switch account = %{public}d.", accountId); KillProcessesOfAccount(accountId, osAccountsInfoMap_); +#ifdef USE_HYPERHOLD_MEMORY ReclaimStrategyManager::GetInstance().NotifyAccountDied(accountId); +#endif } return true; } diff --git a/services/memmgrservice/src/reclaim_priority_manager/reclaim_priority_manager.cpp b/services/memmgrservice/src/reclaim_priority_manager/reclaim_priority_manager.cpp index f4a4ca7..91ae0c9 100644 --- a/services/memmgrservice/src/reclaim_priority_manager/reclaim_priority_manager.cpp +++ b/services/memmgrservice/src/reclaim_priority_manager/reclaim_priority_manager.cpp @@ -1151,7 +1151,9 @@ bool ReclaimPriorityManager::ApplyReclaimPriority(std::shared_ptruid_, bundle->name_, bundle->accountId_, bundle->priority_, action); +#ifdef USE_HYPERHOLD_MEMORY ReclaimStrategyManager::GetInstance().NotifyAppStateChanged(para); +#endif return OomScoreAdjUtils::WriteOomScoreAdjToKernel(bundle); } diff --git a/test/BUILD.gn b/test/BUILD.gn index 08faf98..27538e2 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -293,7 +293,10 @@ ohos_unittest("memory_level_manager_test") { ohos_unittest("low_memory_killer_test") { module_out_path = module_output_path configs = memmgr_service_configs - + defines = [] + if (memmgr_hyperhold_memory) { + defines += [ "USE_HYPERHOLD_MEMORY" ] + } sources = [ "unittest/phone/low_memory_killer_test.cpp" ] deps = memmgr_deps @@ -339,9 +342,11 @@ group("memmgr_unittest") { ":oom_score_adj_utils_test", ":purgeable_memory_manager_test", ":reclaim_priority_manager_test", - ":reclaim_strategy_manager_test", ":system_memory_level_config_test", ":user_memcg_test", ":xml_helper_test", ] + if (memmgr_hyperhold_memory) { + deps += [":reclaim_strategy_manager_test"] + } } diff --git a/test/unittest/phone/low_memory_killer_test.cpp b/test/unittest/phone/low_memory_killer_test.cpp index 52cb4fc..393bb1b 100644 --- a/test/unittest/phone/low_memory_killer_test.cpp +++ b/test/unittest/phone/low_memory_killer_test.cpp @@ -79,14 +79,16 @@ HWTEST_F(LowMemoryKillerTest, PsiHandlerInnerTest, TestSize.Level1) HWTEST_F(LowMemoryKillerTest, KillOneBundleByPrioTest, TestSize.Level1) { + int userId = 234; +#ifdef USE_HYPERHOLD_MEMORY int pid = 123; int appId = 111; std::string appName = "com.test"; - int userId = 234; int score = 100; std::shared_ptr para = std::make_shared(pid, appId, appName, userId, score, AppAction::OTHERS); ReclaimStrategyManager::GetInstance().NotifyAppStateChanged(para); +#endif int minPrio = 10; int ret = 1; ret = LowMemoryKiller::GetInstance().KillOneBundleByPrio(minPrio);