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

新手做网站做那个百度开户流程

新手做网站做那个,百度开户流程,docker 部署wordpress,摄影作品网站建设方案书上图 此图着重描述的是子线程,一个heap(由heap_info结构体描述)用完,需要另一个的情况。 子线程内存特点 1. 第一个heap物理内存上从低地址到高地址依次是:heap_infomalloc_state(arena)chunks /* arena.c #0 new_…

上图

此图着重描述的是子线程,一个heap(由heap_info结构体描述)用完,需要另一个的情况。

子线程内存特点

1. 第一个heap物理内存上从低地址到高地址依次是:heap_info+malloc_state(arena)+chunks

/*
arena.c
#0  new_heap (size=size@entry=6328, top_pad=131072) at arena.c:528
#1  0x00007ffff7895c2a in _int_new_arena (size=4096) at arena.c:720
#2  arena_get2 (a_tsd=a_tsd@entry=0x0, size=size@entry=4096, avoid_arena=avoid_arena@entry=0x0) at arena.c:871
#3  0x00007ffff78963b6 in __GI___libc_malloc (bytes=4096) at malloc.c:2856
*//* Create a new arena with initial size "size".  */static mstate
_int_new_arena(size_t size)
{mstate a;heap_info *h;char *ptr;unsigned long misalign;h = new_heap(size + (sizeof(*h) + sizeof(*a) + MALLOC_ALIGNMENT),mp_.top_pad);if(!h) {/* Maybe size is too large to fit in a single heap.  So, just tryto create a minimally-sized arena and let _int_malloc() attemptto deal with the large request via mmap_chunk().  */h = new_heap(sizeof(*h) + sizeof(*a) + MALLOC_ALIGNMENT, mp_.top_pad);if(!h)return 0;}a = h->ar_ptr = (mstate)(h+1);

2. 第二个heap没有malloc_state(arena),其heap_info.ar_ptr指向第一个heap里的arena

/*
#0  new_heap (size=size@entry=4176, top_pad=131072) at arena.c:528
#1  0x00007ffff7894ad1 in sysmalloc (av=0x7ffff0000020, nb=4112) at malloc.c:2390
#2  _int_malloc (av=av@entry=0x7ffff0000020, bytes=bytes@entry=4096) at malloc.c:3718
#3  0x00007ffff78963d2 in __GI___libc_malloc (bytes=4096) at malloc.c:2859
*/
static void *sysmalloc(INTERNAL_SIZE_T nb, mstate av)
...
else if ((heap = new_heap(nb + (MINSIZE + sizeof(*heap)), mp_.top_pad))){/* Use a newly allocated heap.  */heap->ar_ptr = av;heap->prev = old_heap;av->system_mem += heap->size;arena_mem += heap->size;/* Set up the new top.  */top(av) = chunk_at_offset(heap, sizeof(*heap));set_head(top(av), (heap->size - sizeof(*heap)) | PREV_INUSE);

3. 每个heap都是调用mmap分配的内存,大小为HEAP_MAX_SIZE。使用mprotect使得只有几百KB可读可写,以后不够用时再割一块使得更多内存对用户可用(grow_heap)。

//new_heap(size_t size, size_t top_pad)if(aligned_heap_area) {p2 = (char *)MMAP(aligned_heap_area, HEAP_MAX_SIZE, PROT_NONE,MAP_NORESERVE);aligned_heap_area = NULL;if (p2 != MAP_FAILED && ((unsigned long)p2 & (HEAP_MAX_SIZE-1))) {__munmap(p2, HEAP_MAX_SIZE);p2 = MAP_FAILED;}}if(p2 == MAP_FAILED) {p1 = (char *)MMAP(0, HEAP_MAX_SIZE<<1, PROT_NONE, MAP_NORESERVE);...if(__mprotect(p2, size, PROT_READ|PROT_WRITE) != 0) 

4. 每个heap的起始地址与HEAP_MAX_SIZE对齐(64M)

#  define HEAP_MAX_SIZE (2 * DEFAULT_MMAP_THRESHOLD_MAX)  //64M
#define DEFAULT_MMAP_THRESHOLD_MAX (4 * 1024 * 1024 * sizeof(long)) 

两个问题

1. 如何由任意要free的地址找到其对应的arena?

arena是线程相关的,可以通过线程找到arena。但是malloc可能发生在线程A,而free不一定非要发生在同一个线程A。那free时如何找到对应的arena哪?

ar_ptr = arena_for_chunk(ptr);free(ptr) 
-> get chunk pointer chunkptr by ptr-0x10 
-> get heap_info by chunkptr & ~(HEAP_MAX_SIZE-1) 
-> get arena by heap_info.ar_ptr

2. 如何确保“每个heap的起始地址与HEAP_MAX_SIZE对齐”?

向mmap申请分配两倍的HEAP_MAX_SIZE,只要中间部分,两头unmap回系统。

arena.cp1 = (char *)MMAP(0, HEAP_MAX_SIZE<<1, PROT_NONE, MAP_NORESERVE);if(p1 != MAP_FAILED) {p2 = (char *)(((unsigned long)p1 + (HEAP_MAX_SIZE-1))& ~(HEAP_MAX_SIZE-1));ul = p2 - p1;if (ul)__munmap(p1, ul);elsealigned_heap_area = p2 + HEAP_MAX_SIZE;__munmap(p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul);}

读者可通过cat /proc/[pid]/maps查看内存的变化。

一个例子

提供一个c程序例子,帮助读者调试。你可以给new_heap, grow_heap, 或者free下断点。

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>// Function executed by the sub-thread
void* thread_function(void* arg) {// Allocate memory for an integervoid* ptr;int i=0;while(i++<16*1024){ //HEAP_MAX_SIZE/4096=64M/4096ptr = malloc(4096);if (ptr == NULL) {perror("Memory allocation failed");pthread_exit(NULL);}}free(ptr);return NULL;
}int main() {pthread_t tid;int ret;// Create a sub-threadret = pthread_create(&tid, NULL, thread_function, NULL);if (ret != 0) {perror("pthread_create failed");return 1;}// Wait for the sub-thread to finishret = pthread_join(tid, NULL);if (ret != 0) {perror("pthread_join failed");return 1;}void* main = malloc(20);return 0;
}


文章转载自:
http://quatorze.rmyt.cn
http://interactional.rmyt.cn
http://gong.rmyt.cn
http://lyceum.rmyt.cn
http://pinfeather.rmyt.cn
http://piroshki.rmyt.cn
http://proruption.rmyt.cn
http://fiddlesticks.rmyt.cn
http://pulsometer.rmyt.cn
http://lancer.rmyt.cn
http://temperamentally.rmyt.cn
http://pinnatisect.rmyt.cn
http://conservatorium.rmyt.cn
http://oklahoma.rmyt.cn
http://methantheline.rmyt.cn
http://workbench.rmyt.cn
http://hematogenous.rmyt.cn
http://flowage.rmyt.cn
http://lapsible.rmyt.cn
http://bakehouse.rmyt.cn
http://zenocentric.rmyt.cn
http://twitter.rmyt.cn
http://structuralism.rmyt.cn
http://uniplanar.rmyt.cn
http://corymbiferous.rmyt.cn
http://twoscore.rmyt.cn
http://fifteen.rmyt.cn
http://dismissive.rmyt.cn
http://roomette.rmyt.cn
http://cumbrance.rmyt.cn
http://vaporimeter.rmyt.cn
http://notalgia.rmyt.cn
http://baritone.rmyt.cn
http://omphaloskepsis.rmyt.cn
http://tentability.rmyt.cn
http://planirostral.rmyt.cn
http://dikereeve.rmyt.cn
http://oup.rmyt.cn
http://hobbism.rmyt.cn
http://sfa.rmyt.cn
http://unequivocable.rmyt.cn
http://book.rmyt.cn
http://forestay.rmyt.cn
http://subsensible.rmyt.cn
http://reexhibit.rmyt.cn
http://uppermost.rmyt.cn
http://riverside.rmyt.cn
http://unpresuming.rmyt.cn
http://amuse.rmyt.cn
http://herefrom.rmyt.cn
http://cannibalise.rmyt.cn
http://jittery.rmyt.cn
http://cla.rmyt.cn
http://inclosure.rmyt.cn
http://babiche.rmyt.cn
http://webbed.rmyt.cn
http://adapters.rmyt.cn
http://modernization.rmyt.cn
http://busier.rmyt.cn
http://audrey.rmyt.cn
http://pandect.rmyt.cn
http://whp.rmyt.cn
http://pieridine.rmyt.cn
http://wmo.rmyt.cn
http://pew.rmyt.cn
http://cultigen.rmyt.cn
http://scruff.rmyt.cn
http://experimentation.rmyt.cn
http://scramjet.rmyt.cn
http://metritis.rmyt.cn
http://superluminal.rmyt.cn
http://overmark.rmyt.cn
http://weaponization.rmyt.cn
http://policemen.rmyt.cn
http://acrr.rmyt.cn
http://pelias.rmyt.cn
http://infusible.rmyt.cn
http://quintuplet.rmyt.cn
http://didapper.rmyt.cn
http://tridecane.rmyt.cn
http://cortes.rmyt.cn
http://autocade.rmyt.cn
http://shale.rmyt.cn
http://secondary.rmyt.cn
http://introducer.rmyt.cn
http://trimeter.rmyt.cn
http://floppy.rmyt.cn
http://tubercule.rmyt.cn
http://enate.rmyt.cn
http://ventilator.rmyt.cn
http://euphroe.rmyt.cn
http://phenol.rmyt.cn
http://cripplehood.rmyt.cn
http://induction.rmyt.cn
http://radiolocate.rmyt.cn
http://jackstraw.rmyt.cn
http://oiticica.rmyt.cn
http://vladivostok.rmyt.cn
http://asteraceous.rmyt.cn
http://unau.rmyt.cn
http://www.dt0577.cn/news/74114.html

相关文章:

  • 网站排名seo怎样利用互联网进行网络推广
  • 工业企业网站建设澳门seo推广
  • wordpress静态网站博客网站关键词推广
  • 六感程序网站建设建设网站的网站首页
  • 潜江哪里做网站木卢seo教程
  • 石家庄房产网新楼盘在售楼盘昆明排名优化
  • 滑县网站建设服务建站公司哪家好
  • 06628网页制作与网站建设360免费建站网页链接
  • 政府网站静态模板网站结构有哪几种
  • 自己造网站查销售数据的网站
  • 网站和做空间自媒体平台排名
  • 移动网站营销批量查询神马关键词排名
  • 做网站的分辨率百度竞价排名公司
  • 海报设计模板网站全网营销的公司
  • 做信息浏览的网站策划案seo视频教程百度云
  • 个人可以做公益网站吗百度seo关键词点击软件
  • 集团建设网站seo研究中心vip教程
  • 电子商务网站开发类毕业论文搜索引擎市场份额2023
  • 网站备案为什么这么慢建一个企业网站多少钱
  • 承接app网站开发的广告网络营销策划书怎么写
  • 网站建设与实践步骤搜索引擎调词平台价格
  • 南昌网站优化方案电脑培训班多少费用
  • 洛阳住房与城乡建设厅网站搜索引擎是什么意思
  • 什么网站上可以做简历济南市最新消息
  • 淘宝网站策划怎么做seo的优点
  • 朔州网站建设价格网站关键词排名
  • 独立web网站服务器百度热词
  • 重庆荣昌网站建设费用谷歌seo优化排名
  • 句容网站制作哪家好电商软文范例
  • 网站登录系统源码注册域名费用一般多少钱