modify mallopt

Signed-off-by: nianyuu <zhouwenqiang12@huawei.com>
This commit is contained in:
nianyuu 2024-09-25 14:35:05 +08:00
parent fcd3f76e46
commit 8ee3ad79ef
6 changed files with 24 additions and 13 deletions

View File

@ -240,6 +240,7 @@ APPSPAWN_STATIC int RunChildByRenderCmd(const AppSpawnMgr *content, const AppSpa
static int RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)
{
EnableCache();
APPSPAWN_CHECK(client != NULL && content != NULL, return -1, "Invalid client");
AppSpawningCtx *property = reinterpret_cast<AppSpawningCtx *>(client);
int ret = 0;

View File

@ -375,15 +375,9 @@ static int SpawnSetAppEnv(AppSpawnMgr *content, AppSpawningCtx *property)
return 0;
}
static int SpawnEnableCache(AppSpawnMgr *content, AppSpawningCtx *property)
static int SpawnSetIntPermission(AppSpawnMgr *content, AppSpawningCtx *property)
{
APPSPAWN_LOGV("Spawning: enable cache for app process");
// enable cache for app process
mallopt(M_OHOS_CONFIG, M_TCACHE_PERFORMANCE_MODE);
mallopt(M_OHOS_CONFIG, M_ENABLE_OPT_TCACHE);
mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_ENABLE);
mallopt(M_DELAYED_FREE, M_DELAYED_FREE_ENABLE);
APPSPAWN_LOGV("Spawning: set Internet Permission for app process");
int ret = SetInternetPermission(property);
APPSPAWN_CHECK_ONLY_EXPER(ret == 0, return ret);
return ret;
@ -548,7 +542,7 @@ MODULE_CONSTRUCTOR(void)
AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_HIGHEST, SpawnGetSpawningFlag);
AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_HIGHEST, SpawnInitSpawningEnv);
AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_COMMON + 1, SpawnSetAppEnv);
AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_HIGHEST, SpawnEnableCache);
AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_HIGHEST, SpawnSetIntPermission);
AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_PROPERTY, SpawnSetProperties);
AddAppSpawnHook(STAGE_CHILD_POST_RELY, HOOK_PRIO_HIGHEST, SpawnComplete);
AddAppSpawnHook(STAGE_PARENT_POST_FORK, HOOK_PRIO_HIGHEST, CloseFdArgs);

View File

@ -20,11 +20,15 @@ ohos_shared_library("appspawn_nweb") {
".",
"${appspawn_path}/common",
"${appspawn_path}/standard",
"${appspawn_path}/util/include",
]
defines = []
cflags = []
deps = [ "${appspawn_path}/modules/module_engine:libappspawn_module_engine" ]
deps = [
"${appspawn_path}/modules/module_engine:libappspawn_module_engine",
"${appspawn_path}/util:libappspawn_util",
]
if (target_cpu == "arm64") {
defines += [ "webview_arm64" ]
}

View File

@ -29,6 +29,7 @@
#include "appspawn_hook.h"
#include "appspawn_manager.h"
#include "appspawn_utils.h"
#ifdef WITH_SECCOMP
#include "seccomp_policy.h"
@ -94,12 +95,11 @@ APPSPAWN_STATIC std::string GetArkWebRenderLibName()
APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)
{
EnableCache();
uint32_t len = 0;
char *renderCmd = reinterpret_cast<char *>(GetAppPropertyExt(
reinterpret_cast<AppSpawningCtx *>(client), MSG_EXT_NAME_RENDER_CMD, &len));
if (renderCmd == nullptr) {
return -1;
}
APPSPAWN_CHECK_ONLY_EXPER(renderCmd != nullptr, return -1);
std::string renderStr(renderCmd);
void *webEngineHandle = nullptr;
void *nwebRenderHandle = nullptr;

View File

@ -139,6 +139,7 @@ void InitCommonEnv(void);
int ConvertEnvValue(const char *srcEnv, char *dstEnv, int len);
int EnableNewNetNamespace(void);
void EnableCache(void);
#ifndef APP_FILE_NAME
#define APP_FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))

View File

@ -18,6 +18,7 @@
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -443,3 +444,13 @@ int EnableNewNetNamespace(void)
close(fd);
return (ret >= 0) ? 0 : APPSPAWN_SYSTEM_ERROR;
}
void EnableCache(void)
{
APPSPAWN_LOGV("enable cache for app process");
// enable cache for app process
mallopt(M_OHOS_CONFIG, M_TCACHE_PERFORMANCE_MODE);
mallopt(M_OHOS_CONFIG, M_ENABLE_OPT_TCACHE);
mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_ENABLE);
mallopt(M_DELAYED_FREE, M_DELAYED_FREE_ENABLE);
}