!276 add the ability to perceive important proc

Merge pull request !276 from wonghiu45/adj_update
This commit is contained in:
openharmony_ci
2023-01-30 04:00:40 +00:00
committed by Gitee
8 changed files with 100 additions and 3 deletions
@@ -28,10 +28,14 @@ class ReclaimPriorityConfig {
public:
void ParseConfig(const xmlNodePtr &rootNodePtr);
void ParseReclaimPriorityKillableSystemAppsConfig(const xmlNodePtr &rootNodePtr);
void ParseReclaimPriorityImportantBgAppsConfig(const xmlNodePtr &rootNodePtr);
std::set<std::string> GetkillalbeSystemApps();
std::map<std::string, int> GetImportantBgApps();
void Dump(int fd);
private:
std::set<std::string> killalbeSystemApps_;
std::map<std::string, int> importantBgApps_;
};
} // namespace Memory
} // namespace OHOS
+2
View File
@@ -37,6 +37,8 @@ static void SetIntParam(std::map<std::string, std::string> &param,
std::string key, int &dst, int defaultValue);
static void SetUnsignedIntParam(std::map<std::string, std::string> &param,
std::string key, unsigned int &dst, unsigned int defaultValue);
static void SetStringParam(std::map<std::string, std::string> &param,
std::string key, std::string &dst, std::string defaultValue);
static bool GetModuleParam(const xmlNodePtr &rootNodePtr, std::map<std::string, std::string> &param);
static bool ParseUnsignedLongLongContent(const xmlNodePtr &rootNodePtr, unsigned long long &value);
};
@@ -42,6 +42,10 @@ void ReclaimPriorityConfig::ParseConfig(const xmlNodePtr &rootNodePtr)
ParseReclaimPriorityKillableSystemAppsConfig(currNode);
continue;
}
if (name.compare("importantBgApps") == 0) {
ParseReclaimPriorityImportantBgAppsConfig(currNode);
continue;
}
HILOGW("unknown node :<%{public}s>", name.c_str());
return;
}
@@ -81,9 +85,57 @@ void ReclaimPriorityConfig::ParseReclaimPriorityKillableSystemAppsConfig(const x
return;
}
void ReclaimPriorityConfig::ParseReclaimPriorityImportantBgAppsConfig(const xmlNodePtr &rootNodePtr)
{
HILOGI("called");
if (!XmlHelper::CheckNode(rootNodePtr) || !XmlHelper::HasChild(rootNodePtr)) {
HILOGD("Node exsist:%{public}d,has child node:%{public}d",
XmlHelper::CheckNode(rootNodePtr), XmlHelper::HasChild(rootNodePtr));
return;
}
for (xmlNodePtr currNode = rootNodePtr->xmlChildrenNode; currNode != nullptr; currNode = currNode->next) {
if (!XmlHelper::CheckNode(currNode)) {
return;
}
std::string name = std::string(reinterpret_cast<const char *>(currNode->name));
if (name.compare("importantBgApp") == 0) {
std::map<std::string, std::string> param;
std::string procName;
int minPriority;
XmlHelper::GetModuleParam(currNode, param);
XmlHelper::SetStringParam(param, "procName", procName, "");
XmlHelper::SetIntParam(param, "minPriority", minPriority, RECLAIM_PRIORITY_MAX + 1);
if (procName.size() == 0 || minPriority > RECLAIM_PRIORITY_MAX + 1) {
HILOGE("read fail, ignore it!");
continue;
}
importantBgApps_.insert(std::make_pair(procName, minPriority));
continue;
}
HILOGW("unknown node :<%{public}s>", name.c_str());
}
return;
}
std::set<std::string> ReclaimPriorityConfig::GetkillalbeSystemApps()
{
return killalbeSystemApps_;
}
std::map<std::string, int> ReclaimPriorityConfig::GetImportantBgApps()
{
return importantBgApps_;
}
void ReclaimPriorityConfig::Dump(int fd)
{
dprintf(fd, "ImportantBgApps: \n");
for (auto it = importantBgApps_.begin(); it != importantBgApps_.end(); it++) {
dprintf(fd, " procName:%s ----> prio:%d \n", it->first.c_str(), it->second);
}
}
} // namespace Memory
} // namespace OHOS
+1
View File
@@ -200,6 +200,7 @@ void MemmgrConfigManager::Dump(int fd)
nandLifeConfig_.Dump(fd);
systemMemoryLevelConfig_.Dump(fd);
switchConfig_.Dump(fd);
reclaimPriorityConfig_.Dump(fd);
}
} // namespace Memory
} // namespace OHOS
+13
View File
@@ -119,5 +119,18 @@ bool XmlHelper::ParseUnsignedLongLongContent(const xmlNodePtr &rootNodePtr, unsi
}
return false;
}
void XmlHelper::SetStringParam(std::map<std::string, std::string> &param,
std::string key, std::string &dst, std::string defaultValue)
{
HILOGI("called");
dst = defaultValue;
std::map<std::string, std::string>::iterator iter = param.find(key);
if (iter != param.end() && (iter->second).size() > 0) {
dst = iter->second;
return;
}
HILOGW("find param failed key:<%{public}s>", key.c_str());
}
} // namespace Memory
} // namespace OHOS
+6
View File
@@ -19,6 +19,12 @@
<killalbeSystemApps>
<killableSysApp></killableSysApp>
</killalbeSystemApps>
<importantBgApps>
<importantBgApp>
<procName>default</procName>
<minPriority>400</minPriority>
</importantBgApp>
</importantBgApps>
</reclaimPriorityConfig>
<systemMemoryLevelConfig>
<moderate>800</moderate>
@@ -156,6 +156,7 @@ private:
void AddOsAccountInfo(std::shared_ptr<AccountBundleInfo> account);
bool IsKillableSystemApp(std::shared_ptr<BundlePriorityInfo> bundle);
void NotifyKillableSystemAppsAdded(std::set<std::string> &newKillableApps);
bool IsImportantApp(std::shared_ptr<BundlePriorityInfo> bundle, int &dstPriority);
static inline int GetOsAccountLocalIdFromUid(int bundleUid)
{
@@ -643,6 +643,18 @@ bool ReclaimPriorityManager::UpdateReclaimPriorityInner(pid_t pid, int bundleUid
return ret;
}
bool ReclaimPriorityManager::IsImportantApp(std::shared_ptr<BundlePriorityInfo> bundle, int &dstPriority)
{
std::map<std::string, int> importantApps = config_.GetImportantBgApps();
std::string targetAppName = bundle->name_;
if (importantApps.count(targetAppName)) {
dstPriority = importantApps.at(targetAppName);
return true;
}
return false;
}
void ReclaimPriorityManager::UpdatePriorityByProcStatus(std::shared_ptr<BundlePriorityInfo> bundle,
ProcessPriorityInfo &proc)
{
@@ -658,9 +670,15 @@ void ReclaimPriorityManager::UpdatePriorityByProcStatus(std::shared_ptr<BundlePr
proc.SetPriority(RECLAIM_PRIORITY_FOREGROUND);
}
} else { // is a background process
HILOGD("%{public}d is a background process, set process priority to %{public}d first", proc.pid_,
RECLAIM_PRIORITY_BACKGROUND);
proc.SetPriority(RECLAIM_PRIORITY_BACKGROUND);
int bgPriority = RECLAIM_PRIORITY_BACKGROUND;
if(IsImportantApp(bundle, bgPriority)) {
HILOGD("%{public}d is a important background process, set process priority to %{public}d first",
proc.pid_, bgPriority);
} else {
HILOGD("%{public}d is a background process, set process priority to %{public}d first",
proc.pid_, bgPriority);
}
proc.SetPriority(bgPriority);
}
if (proc.isSuspendDelay) { // is a background process with transient task
HILOGD("%{public}d is a background process with transient task", proc.pid_);