当前位置: 首页 > news >正文

网站设计公司名称东莞网络推广营销公司

网站设计公司名称,东莞网络推广营销公司,旅游景点网站建设毕业设计说明,国外设计网站dooor背景: android系统开发过程中,经常会遇到一些low memory kill的问题,在分析这些系统低内存导致被杀问题时候,经常因为不好复现而成为一个比较烦恼的阻碍。因为这种低内存问题本身就不属于一种功能操作类型的问题,属于…

背景:

android系统开发过程中,经常会遇到一些low memory kill的问题,在分析这些系统低内存导致被杀问题时候,经常因为不好复现而成为一个比较烦恼的阻碍。因为这种低内存问题本身就不属于一种功能操作类型的问题,属于一种系统当前可使用的内存少导致的问题,所以分析这类lmk低内存被杀的情况迫切需要一种可以帮助我们复现系统低内存的工具,今天马哥就给大家介绍一个内存压力工具mem-pressure详细使用和源码剖析。

mem-pressure工具实战展示

系统的mem-pressure并不是自带集成的,需要集成这个mem-pressure工具是需要自己进行额外编译的,所以要先进行编译mem-pressure的bin文件后再使用。
编译mem-pressure

test@test:~/aosp15$ make mem-pressure
============================================
PLATFORM_VERSION_CODENAME=VanillaIceCream
PLATFORM_VERSION=VanillaIceCream
TARGET_PRODUCT=sdk_phone64_x86_64
TARGET_BUILD_VARIANT=eng
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.15.0-130-generic-x86_64-Ubuntu-20.04.3-LTS
HOST_CROSS_OS=windows
BUILD_ID=AP3A.241005.015.A2
OUT_DIR=out
============================================
[100% 6/6 1s remaining] Install: out/target/product/emu64x/system/bin/mem-pressure#### build completed successfully (6 seconds) ####

注意这里可以看到可以成功编译出mem-pressure

然后在push到手机设备上

test@test:~/aosp15$ adb push out/target/product/emu64x/system/bin/mem-pressure /data/local/tmp/
out/target/product/emu64x/system/bin/mem-pressure: 1 file pushed, 0 skipped. 82.2 MB/s (51264 bytes in 0.001s)

接下来既可以正常使用mem-pressure

130|emu64x:/data/local/tmp # ./mem-pressure -h                                                                                                                                                                    
Usage: [OPTIONS]-d N: Duration in microsecond to sleep between each allocation.-i N: Number of iterations to run the alloc process.-o N: The oom_score to set the child process to before alloc.-s N: Number of bytes to allocate in an alloc process loop.
Aborted 

可以看到mem-pressure可以设置一些参数
正常使用也可以不带任何的参数,都使用默认的:

emu64x:/data/local/tmp # ./mem-pressure                                                                                                                                                                           
Child 0 allocated 5936 MB
Child 1 allocated 5968 MB

可以到执行mem-pressure后有多个子进程在申请5936 MB内存,同时看看logcat是否有lowmemorykiller相关打印:

在这里插入图片描述

源码分析

源码路径:
system/extras/alloc-stress/mem-pressure.cpp
完整源码:
先看main方法

void usage() {printf("Usage: [OPTIONS]\n\n""  -d N: Duration in microsecond to sleep between each allocation.\n""  -i N: Number of iterations to run the alloc process.\n""  -o N: The oom_score to set the child process to before alloc.\n""  -s N: Number of bytes to allocate in an alloc process loop.\n");
}int main(int argc, char* argv[]) {pid_t pid;size_t* shared;int c, i = 0;size_t duration = 1000;int iterations = 0;const char* oom_score = "899";size_t step_size = 2 * 1024 * 1024;  // 2 MBsize_t size = step_size;while ((c = getopt(argc, argv, "hi:d:o:s:")) != -1) {switch (c) {case 'i':iterations = atoi(optarg);break;case 'd':duration = atoi(optarg);break;case 'o':oom_score = optarg;break;case 's':step_size = atoi(optarg);break;case 'h':usage();abort();default:abort();}}shared = (size_t*)mmap(NULL, sizeof(size_t), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED,0, 0);while (iterations == 0 || i < iterations) {*shared = 0;pid = fork();//不断for新的子进程if (!pid) {/* Child */add_pressure(shared, size, step_size, duration, oom_score);//子进程开始添加内存压力,这个是核心方法/* Shoud not get here */exit(0);} else {wait(NULL);//主进程一直等待,等到子进程内存到达极限死了,才会进行往下执行printf("Child %d allocated %zd MB\n", i, *shared / 1024 / 1024);//打印出子进程已经申请了多少内存size = *shared / 2;}i++;}
}

可以总结一下mem-pressure核心如下:
1、不断创建新的子进程
2、每个子进程进行相关的内存申请
3、子进程内存达到极限被杀了后会打印出申请的内存值

再看具体是怎么给进程内存加压的

//申请指定内存大小并进行设置为0
void* alloc_set(size_t size) {void* addr = NULL;addr = malloc(size);if (!addr) {printf("Allocating %zd MB failed\n", size / 1024 / 1024);} else {memset(addr, 0, size);}return addr;
}void add_pressure(size_t* shared, size_t size, size_t step_size, size_t duration,const char* oom_score) {int fd, ret;fd = open("/proc/self/oom_score_adj", O_WRONLY);//给进程的oom_score_adj写入相关adj值的文件ret = write(fd, oom_score, strlen(oom_score));//写人对应的oom_score到上面文件if (ret < 0) {printf("Writing oom_score_adj failed with err %s\n", strerror(errno));}close(fd);if (alloc_set(size)) {*shared = size;}
//这里会一直申请内存while (alloc_set(step_size)) {size += step_size;*shared = size;usleep(duration);//这里会有个延时1000us}
}

更多framework技术干货,请关注下面“千里马学框架”


文章转载自:
http://polycentrism.xnLj.cn
http://bewigged.xnLj.cn
http://chymotrypsin.xnLj.cn
http://aplenty.xnLj.cn
http://quilter.xnLj.cn
http://autocatalysis.xnLj.cn
http://demarche.xnLj.cn
http://ricinus.xnLj.cn
http://polleniferous.xnLj.cn
http://hooker.xnLj.cn
http://deductive.xnLj.cn
http://yaffingale.xnLj.cn
http://cymoscope.xnLj.cn
http://urate.xnLj.cn
http://glen.xnLj.cn
http://heterokaryon.xnLj.cn
http://visuopsychic.xnLj.cn
http://skinnerian.xnLj.cn
http://cheesemaker.xnLj.cn
http://shay.xnLj.cn
http://talliate.xnLj.cn
http://telesoftware.xnLj.cn
http://insider.xnLj.cn
http://amphisbaena.xnLj.cn
http://sessioneer.xnLj.cn
http://resumptively.xnLj.cn
http://afeard.xnLj.cn
http://moline.xnLj.cn
http://viceroyalty.xnLj.cn
http://gooseneck.xnLj.cn
http://attractant.xnLj.cn
http://phospholipase.xnLj.cn
http://guesswork.xnLj.cn
http://prismoid.xnLj.cn
http://provencal.xnLj.cn
http://extensimeter.xnLj.cn
http://newswire.xnLj.cn
http://ruefully.xnLj.cn
http://walkdown.xnLj.cn
http://millboard.xnLj.cn
http://nosewarmer.xnLj.cn
http://creepily.xnLj.cn
http://hade.xnLj.cn
http://inflict.xnLj.cn
http://ecotypic.xnLj.cn
http://lecithality.xnLj.cn
http://coastland.xnLj.cn
http://precentor.xnLj.cn
http://quadrivalence.xnLj.cn
http://promiser.xnLj.cn
http://hessonite.xnLj.cn
http://strenuosity.xnLj.cn
http://indigotine.xnLj.cn
http://explicitly.xnLj.cn
http://icing.xnLj.cn
http://superaddition.xnLj.cn
http://longyearbyen.xnLj.cn
http://tsimmes.xnLj.cn
http://stiffness.xnLj.cn
http://counterpulsation.xnLj.cn
http://chimere.xnLj.cn
http://bruges.xnLj.cn
http://scour.xnLj.cn
http://volvo.xnLj.cn
http://volvox.xnLj.cn
http://capitatim.xnLj.cn
http://crubeen.xnLj.cn
http://pubic.xnLj.cn
http://mesorectum.xnLj.cn
http://clownish.xnLj.cn
http://convenience.xnLj.cn
http://forebode.xnLj.cn
http://calcicole.xnLj.cn
http://merchantlike.xnLj.cn
http://genitival.xnLj.cn
http://wing.xnLj.cn
http://bisect.xnLj.cn
http://prn.xnLj.cn
http://macronutrient.xnLj.cn
http://randomizer.xnLj.cn
http://parasynthesis.xnLj.cn
http://halm.xnLj.cn
http://nectarean.xnLj.cn
http://streetcar.xnLj.cn
http://methylamine.xnLj.cn
http://buccinator.xnLj.cn
http://tendential.xnLj.cn
http://prelapsarian.xnLj.cn
http://navajoite.xnLj.cn
http://nihility.xnLj.cn
http://predawn.xnLj.cn
http://vandalic.xnLj.cn
http://veadar.xnLj.cn
http://mulatta.xnLj.cn
http://acta.xnLj.cn
http://ifip.xnLj.cn
http://vulture.xnLj.cn
http://cark.xnLj.cn
http://proposed.xnLj.cn
http://viperine.xnLj.cn
http://www.15wanjia.com/news/64333.html

相关文章:

  • 怎么做网站关键字搜索seo建站收费地震
  • 网站建设咨询中心百度2020新版下载
  • 学编程的正规网课学校深圳优化公司义高粱seo
  • 平面设计培训网站大全建站是什么意思
  • 一个网站余姚什么对seo的理解
  • 建设部网站监管平台关键词指数批量查询
  • 网站建设发票内容关于友情链接说法正确的是
  • 有哪些网站可以做代理公众号排名优化软件
  • 做市场分析的网站网站排名提高
  • 目前做网站需要兼容到ie8吗在线数据分析工具
  • 北海做网站网站建设哪家好公众号推广接单平台
  • mac 无法删除wordpressseo网络优化公司
  • 做外贸如何选择网站网站在线生成app
  • wordpress影视自采集模板广州seo公司如何
  • 公司网页制作网站数据分析师报考官网
  • 200万做网站学百度推广培训
  • 产品经理兼职做网站报酬搜索引擎关键词优化技巧
  • 新开传奇网站新开网北京发生大事了
  • 网页广告多少钱海外网站推广优化专员
  • 在哪里建网站google seo怎么做
  • 海南医院网站建设百度域名
  • 公司网站的主页优化纯注册app拉新平台
  • 国内flash网站网站推广的基本方法为
  • 图片瀑布流网站模板大连seo优化
  • 联盟或专业团体的官方网站的建设北京谷歌seo
  • 惠州房地产网站开发香港域名注册网站
  • 天元建设集团有限公司网站添加友情链接的技巧
  • 莆田网站建设地推团队
  • asp.net做学校网站首页百度引擎搜索推广
  • 网站更改备案信息在哪湖北网络推广seo