1 Star 0 Fork 87

zhangweimin24026 / resourceschedule_memmgr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

内存管理部件

简介

内存管理部件位于全局资源调度管控子系统中,基于应用的生命周期状态,更新进程回收优先级列表,通过内存回收、查杀等手段管理系统内存,保障内存供给。

目录

/foundation/resourceschedule/memmgr
├── common           						# 部件通用工具类
│   ├── include
│   │   ├── kernel_interface.h				# 封装了与Kernel交互的接口
│   │   ├── memmgr_log.h					# 封装了hilog,用于日志打印
│   │   └── single_instance.h				# 封装了单例模式的类模板
│   └── src
│       └── kernel_interface.cpp

|
├── sa_profile       						# 组件服务配置
|
├── services         						# 组件服务实现
|   └── memmgrservice    					# 对内接口目录
|       ├── include
|       |   ├── event						# 事件注册中心目录
|       |   ├── reclaim_priority_manager	# 进程回收优先级管理目录
|       |   ├── reclaim_strategy			# 回收策略目录
|       |   └── kill_strategy				# 查杀策略目录
|       └── src
|           ├── event
|           ├── reclaim_priority_manager
|           ├── reclaim_strategy
|           └── kill_strategry
|
└── test 									# 自测试用例目录

框架

内存管理部件主要基于事件触发回收优先级更新,并基于回收优先级管理内存回收和查杀,其框架如下所示(下图虚线右侧为本部件),主要分为如下几个模块:

1、事件管理模块:统筹管理本部件所要对外响应的事件。主要功能为调用其他子系统提供的接口注册事件监听,并将事件通知到回收优先级管理模块、回收策略模块和查杀策略模块。

2、回收优先级管理模块:基于事件管理模块的应用和用户的事件通知,给出进程的回收和查杀的先后顺序列表,并向回收策略和查杀策略提供查询此列表的接口。

3、回收策略模块:根据回收优先级列表,调整回收内存水线、文件页/匿名页回收比例、压缩/换出比例等回收参数,以及协调不同回收机制协同工作,保障内存中低负载下的供给性能。

4、查杀策略模块:作为回收的逻辑末端,根据回收优先级列表,保障内存重负载下的内存供给。

5、Kernel接口管控模块:负责将回收参数、查杀等管控命令下发到Kernel。

6、内存特性配置:读取回收策略模块、查杀策略模块等需要的配置文件。

7、磁盘寿命管控(规划中):控制磁盘写入量,以保障磁盘寿命。

进程回收优先级列表

进程回收优先级列表,提供了进程间回收和查杀的先后顺序列表。本部件定义的进程回收优先级及其对应的描述如下表所示:

优先级 描述
-1000 系统进程,属于该优先级的进程不会被查杀策略查杀,支持白名单配置。
0 前台应用。
100 正在进行后台短时任务的应用。
200 后台可感知应用,如正在执行导航、播放音乐等长时任务的应用。
600 被冻结的应用。
800 挂起应用。

回收策略/查杀策略

查杀作为回收的逻辑末端,与回收策略一脉相承,因此两者使用相同的进程回收优先级列表,同时也要协同管控,协调两者触发时机,共同保障不同内存负载下的内存供给功能和性能。

  • 回收策略:回收策略是垂直内存管理的重中之重。回收策略管控了多种不同的内存回收机制,需要协调好不同机制,例如Purgeable/Speculative内存(规划中)的回收要先于其他内存,再例如回收触发时机要先于低内存查杀。

    在内存低负载时,可以将热点文件cache在内存中以提升性能(规划中)。

    内存中负载时,配置kswapd/zswapd等回收进程的内存水线(阈值)以及相应的回收参数,指导kswapd/zswapd工作。

    对于如下单点关键事件,例如大内存需求的相机场景,可以通过“场景处理”模块单点配置,根据业务需求预回收(规划中);再例如查杀场景,要停止kswapd/zswapd的基本动作,避免无效回收。

  • 查杀策略:查杀主要负责内存重负载场景。由PSI( Pressure Stall Information )内存压力事件触发,根据查杀内存水线,从进程回收优先级列表中选择低优先级进程进行清理。

    默认的查杀内存水线与可杀进程回收优先级对应关系如下表所示。未来,系统开发者和产品开发者可以根据内存RAM(Random Access Memory)规格、屏幕尺寸等需求通过修改xml配置修改该对应关系(xml配置暂不支持,规划中)。

    查杀内存水线 进程回收优先级
    500 MB 800
    400 MB 600
    300 MB 200
    200 MB 100
    100 MB 0

使用说明

系统开发者可以通过配置productdefine/common/products下的产品定义json文件,增加或移除本部件,来启用或停用本部件。

"resourceschedule:memmgr":{}

参数配置说明

产品可通过memmgr_config.xml来配置本模块相关参数,路径为/etc/memmgr/memmgr_config.xml xml样例:

800 750 850 200 0 500 60 10 50 501 1000 70 20 60

功能参考: 详见Enhanced SWAP特性介绍 https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/kernel/kernel-standard-mm-eswap.md

节点介绍: Memmgr Memmgr相关配置 reclaimConfig 内存回收相关配置 availbufferSize 系统水线相关配置 节点功能:avail_buffers接口用于设置buffer区间[min_avail_buffers, high_avail_buffers],当检测到当前的buffer低于min_avail_buffers时则会唤醒zswapd进行匿名页回收,期望的回收量为high_avail_buffers与当前系统buffer值的差值,实际可能会因为无法回收等原因而未回收那么多内存。avail_buffers为期望的内存正常状态buffer值,free_swap_threshold则是设置交换分区空闲容量的阈值 默认值(未开启zram时): avail_buffers: 0 min_avail_buffers: 0 high_avail_buffers: 0 free_swap_threshold: 0 默认值: avail_buffers: 800 min_avail_buffers: 750 high_avail_buffers: 850 free_swap_threshold: 200

		限制:
			0<=min_avail_buffers<=avail_buffers<=high_avail_buffers<=memTotal
			0<=free_swap_threashold<=memTotal
	ZswapdParam:		memcg相关配置
		节点功能:设置memcg的相关配置。memcg的appScore发生变化时,根据新的appScore找到minScore和maxScore对应区间的ratio值,ub_mem2zram_ratio为内存压缩到ZRAM的比率,ub_zram2ufs_ratio为ZRAM换出到ESwap的比率,refault_threshold为refault的阈值,可通过调整比率来控制ZRAM压缩以及ESwap换出情况。
		默认值:
			minScore: 0
			maxScore: 1000
			mem2zramRatio: 60
			zran2ufsRation: 10
			refaultThreshold: 50
		限制:
			0<=minScore<=1000
			0<=maxScore<=1000
			0<=ub_mem2zram_ratio<=100
			0<=ub_zram2ufs_ratio<=100
			0<=refault_threshold<=100
killConfig:		内存查杀相关配置

相关仓

全局资源调度子系统

resource_schedule_service

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS

简介

管理进程回收优先级列表,以及根据该优先级进行进程回收和查杀策略管控。 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zhangweimin24026/resourceschedule_memmgr.git
git@gitee.com:zhangweimin24026/resourceschedule_memmgr.git
zhangweimin24026
resourceschedule_memmgr
resourceschedule_memmgr
master

搜索帮助