mirror of
https://github.com/openharmony/resourceschedule_memmgr.git
synced 2026-07-01 03:23:18 -04:00
TicketNo:#IA8SK9 Description:新增hyperhold特性开关。 Signed-off-by: xuqibin <935159042@qq.com>
This commit is contained in:
+2
-1
@@ -66,7 +66,8 @@
|
||||
]
|
||||
},
|
||||
"features": [
|
||||
"memmgr_purgeable_memory"
|
||||
"memmgr_purgeable_memory",
|
||||
"memmgr_hyperhold_memory"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -32,4 +32,5 @@ declare_args() {
|
||||
}
|
||||
|
||||
memmgr_purgeable_memory = false
|
||||
memmgr_hyperhold_memory = false
|
||||
}
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<int> &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;
|
||||
}
|
||||
|
||||
@@ -1151,7 +1151,9 @@ bool ReclaimPriorityManager::ApplyReclaimPriority(std::shared_ptr<BundlePriority
|
||||
DECLARE_SHARED_POINTER(ReclaimParam, para);
|
||||
MAKE_POINTER(para, shared, ReclaimParam, "make ReclaimParam failed", return false,
|
||||
pid, bundle->uid_, bundle->name_, bundle->accountId_, bundle->priority_, action);
|
||||
#ifdef USE_HYPERHOLD_MEMORY
|
||||
ReclaimStrategyManager::GetInstance().NotifyAppStateChanged(para);
|
||||
#endif
|
||||
return OomScoreAdjUtils::WriteOomScoreAdjToKernel(bundle);
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -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"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ReclaimParam> para = std::make_shared<ReclaimParam>(pid, appId, appName, userId, score,
|
||||
AppAction::OTHERS);
|
||||
ReclaimStrategyManager::GetInstance().NotifyAppStateChanged(para);
|
||||
#endif
|
||||
int minPrio = 10;
|
||||
int ret = 1;
|
||||
ret = LowMemoryKiller::GetInstance().KillOneBundleByPrio(minPrio);
|
||||
|
||||
Reference in New Issue
Block a user