diff --git a/frameworks/native/backup_ext/src/tar_file.cpp b/frameworks/native/backup_ext/src/tar_file.cpp index 8595d911d712ef0c618a9f0e5a8ee7b2bc336f0b..80de4451ca0aedf17a65bc47a7298cfefdb2a24e 100644 --- a/frameworks/native/backup_ext/src/tar_file.cpp +++ b/frameworks/native/backup_ext/src/tar_file.cpp @@ -37,6 +37,8 @@ const uint64_t MAX_FILE_SIZE = 0777777777777L; const uint32_t OCTSTR_LEN = sizeof(off_t) * 3 + 1; const uint32_t DEFAULT_SLICE_SIZE = 100 * MB_TO_BYTE; // 分片文件大小为100M const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件 +const uint32_t WAIT_INDEX = 100000; +const uint32_t WAIT_TIME = 5; const string VERSION = "1.0"; const string LONG_LINK_SYMBOL = "longLinkSymbol"; } // namespace @@ -65,11 +67,18 @@ bool TarFile::Packet(const vector &srcFiles, const string &tarFileName, return false; } + size_t index = 0; for (auto &filePath : srcFiles) { rootPath_ = filePath; if (!TraversalFile(rootPath_)) { HILOGE("Failed to traversal file"); } + index++; + if (index >= WAIT_INDEX) { + HILOGD("Sleep to wait"); + sleep(WAIT_TIME); + index = 0; + } } if (!FillSplitTailBlocks()) { diff --git a/services/backup_sa/include/module_external/sms_adapter.h b/services/backup_sa/include/module_external/sms_adapter.h index 5dd16545bc8c2cde2bf7bb00d7e1574e2adaaf89..0e3b51e78ee2ba325b4ed9491637116ccc78fb21 100644 --- a/services/backup_sa/include/module_external/sms_adapter.h +++ b/services/backup_sa/include/module_external/sms_adapter.h @@ -37,6 +37,13 @@ public: * @param userId user id */ static int64_t GetUserStorageStats(const std::string &bundleName, int32_t userId); + + /** + * @brief update memory para + * + * @param size para data + */ + static int32_t UpdateMemPara(int32_t size); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_STORAGE_MGR_ADAPTER_H \ No newline at end of file diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 46671ac84031d1128b7ca1235a8ad72f4cec321d..fbf1614ac24c2a7a13fad392ef6d031f49413b7e 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -377,6 +377,19 @@ public: */ void ClearSessionData(); + /** + * @brief 获取备份前内存参数 + * + */ + int32_t GetMemParaCurSize(); + + /** + * @brief 记录备份前内存参数 + * + * @param size + */ + void SetMemParaCurSize(int32_t size); + private: /** * @brief 获取backup extension ability @@ -431,6 +444,7 @@ private: uint32_t extConnectNum_ {0}; Utils::Timer extBundleTimer {"backupBundleExtTimer"}; std::atomic sessionCnt_ {0}; + int32_t memoryParaCurSize_ {100}; }; } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_external/sms_adapter.cpp b/services/backup_sa/src/module_external/sms_adapter.cpp index e6613ed2cb8cdd575d5e52129d938f80a1d5cb15..7055d0d3fd0cfee86e9246fe261eabdfc99a562e 100644 --- a/services/backup_sa/src/module_external/sms_adapter.cpp +++ b/services/backup_sa/src/module_external/sms_adapter.cpp @@ -18,6 +18,7 @@ #include #include "b_error/b_error.h" +#include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -69,4 +70,14 @@ int64_t StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, in } return 0; } + +int32_t StorageMgrAdapter::UpdateMemPara(int32_t size) +{ + auto storageMgr = GetStorageManager(); + int32_t oldSize = BConstants::DEF_VFS_CACHE_PRESSURE; + if (storageMgr->UpdateMemoryPara(size, oldSize)) { + HILOGE("An error occured StorageMgrAdapter UpdateMemPara"); + } + return oldSize; +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 2f90faa05de4fa6ae4a438aed15803864aa85681..01f1625da34aa74cfafdc2cd5766057617d77f2f 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -50,6 +50,7 @@ #include "ipc_skeleton.h" #include "module_app_gallery/app_gallery_dispose_proxy.h" #include "module_external/bms_adapter.h" +#include "module_external/sms_adapter.h" #include "module_ipc/svc_backup_connection.h" #include "module_ipc/svc_restore_deps_manager.h" #include "parameter.h" @@ -89,6 +90,11 @@ void Service::OnStart() void Service::OnStop() { HILOGI("Called"); + int32_t oldMemoryParaSize = BConstants::DEF_VFS_CACHE_PRESSURE; + if (session_ != nullptr) { + oldMemoryParaSize = session_->GetMemParaCurSize(); + } + StorageMgrAdapter::UpdateMemPara(oldMemoryParaSize); sched_ = nullptr; session_ = nullptr; } diff --git a/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index 1b245feaa0bb9ec95cf36cdccc303fc20e1bc1fd..c2898a340a28ba4707543b41611c28c93911f6fe 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -628,4 +628,14 @@ void SvcSessionManager::ClearSessionData() } impl_.backupExtNameMap.clear(); } + +int32_t SvcSessionManager::GetMemParaCurSize() +{ + return memoryParaCurSize_; +} + +void SvcSessionManager::SetMemParaCurSize(int32_t size) +{ + memoryParaCurSize_ = size; +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_external/sms_adapter_mock.cpp b/tests/mock/module_external/sms_adapter_mock.cpp index 1ef1c8f2074a9d6ead83a57f3f73afd37dbe4c36..cafd6c62164e2c2edd3541e35b5b0b610a416864 100644 --- a/tests/mock/module_external/sms_adapter_mock.cpp +++ b/tests/mock/module_external/sms_adapter_mock.cpp @@ -24,4 +24,9 @@ StorageManager::BundleStats StorageMgrAdapter::GetBundleStats(const std::string StorageManager::BundleStats bundleStats; return bundleStats; } + +int32_t StorageMgrAdapter::UpdateMemPara(int32_t size) +{ + return 0; +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 8c9ff7ab977323922c647336271be59c1c1e3936..580b034bb779d11764b48ebfc2a1d49a882490f7 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -313,5 +313,12 @@ void SvcSessionManager::IncreaseSessionCnt() {} void SvcSessionManager::DecreaseSessionCnt() {} +int32_t SvcSessionManager::GetMemParaCurSize() +{ + return 0; +} + +void SvcSessionManager::SetMemParaCurSize(int32_t size) {} + void SvcSessionManager::ClearSessionData() {} } // namespace OHOS::FileManagement::Backup diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index da3ab5d0d7147f00f64da49fe73961b3c91880cb..077c21b9e3f4449e45a77411f7089cebc6b96b32 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -63,6 +63,9 @@ constexpr int EXT_CONNECT_MAX_TIME = 15000; // SA 启动 extension 等待连 constexpr int IPC_MAX_WAIT_TIME = 3000; // IPC通讯最大等待时间(s) +constexpr int DEF_VFS_CACHE_PRESSURE = 100; // 默认内存回收参数 +constexpr int BACKUP_VFS_CACHE_PRESSURE = 5000; // 备份过程修改参数 + // backup.para内配置项的名称,该配置项值为true时可在不更新hap包的情况下,可以读取包管理元数据配置文件的内容 static inline std::string BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_KEY = "backup.debug.overrideExtensionConfig";