The technical scheme of the invention includes a method to reduce the system memory for the realization of conflict: A. server startup, created by a plurality of equivalent memory pool group size memory pool composition, initialization index number and set the next time the requested memory pool number; according to the request of B. thread, memory pool allocation sequence number the steps set by A, and modify the index number; C. will be allocated to the storage pool number memory block header reserved field; D. when the allocated memory pool is released, get the reserved field in memory pool number and send to the corresponding memory pool. The invention has the advantages that the memory allocation at the same time the request is distributed to a plurality of memory cell, reduce the multithread memory allocation request lock contention; because the allocated memory spread across multiple memory pool, can lock release operation leads to reduced competition, can significantly reduce the memory allocation and the waiting time lock release operation.
【技术实现步骤摘要】
一种降低系统内存分配释放冲突的方法
本专利技术涉及一种降低系统内存分配释放冲突的方法,属于计算机服务器数据处理领域。
技术介绍
服务器需要处理大量用户的请求,大部分服务器都会使用多线程技术来提升多核CPU的利用率,而内存作为一个进程中多个线程的共享资源,当多个线程同时请求内存分配或释放时,为了保持内存的正确性,操作系统会使用线程锁,每次只能执行一个线程的请求,其他线程则需要等待线程锁,待前一个分配请求完成后再继续执行,因而降低了系统并发度。一般来说,服务器会通过设置内存池,避免每次内存的申请与释放都通过调用系统提供的相关API接口,部分服务器也会根据分配的内存大小,对内存池的设计进行相关优化,尽可能提升内存分配与释放的速度,进而提升系统性能。随着服务器硬件水平的不断提升,操作系统可用的内存越来越大,因此服务器可用内存也越大,通过在服务器启动时,分配多个内存池(每个内存池预先分配一定数量的内存),组成内存池组,每次请求内存分配时,依据一定的算法,从内存池组中挑选一个内存池,然后从该内存池中分配内存,并在分配的内存的头部保留一个字段用来记录内存池编号,当该内存被释放时 ...
【技术保护点】
一种降低系统内存分配释放冲突的方法,其特征在于,该方法包括:A.服务器启动时,创建由多个等同大小内存池组成的内存池组,初始化索引编号并设置下次被请求的内存池序号;B.根据线程请求,分配所述步骤A设置的内存池序列号,并同时修改索引编号;C.将已分配的内存池编号存储至内存块头部保留字段;D.当已分配内存池释放时,获取保留字段中的内存池编号并发送至对应的内存池。
【技术特征摘要】
1.一种降低系统内存分配释放冲突的方法,其特征在于,该方法包括:A.服务器启动时,创建由多个等同大小内存池组成的内存池组,初始化索引编号并设置下次被请求的内存池序号;B.根据线程请求,分配所述步骤A设置的内存池序列号,并同时修改索引编号;C.将已分配的内存池编号存储至内存块头部保留字段;D.当已分配内存池释放时,获取保留字段中的内存池编号并发送至对应的内存池。2.根据权利要求1所述的降低系统内存分配释放冲突的方法,其特征在于,所述的步骤A还包括:启动服务器进程,创建多个内存池,其内存池编号依次为[0,1,2...(N-1)],内存池编号为[0,1,2...(N-1)]中所有内存池组成一个内存池组,并为每个内存池组分配等同大小的内存空间;创建与内存池对应的索引编号Index,使用Ind...
【专利技术属性】
技术研发人员:刘马良,张强,李邦戈,潘亚楠,李星,刘鼎三,
申请(专利权)人:珠海金山网络游戏科技有限公司,珠海西山居移动游戏科技有限公司,
类型:发明
国别省市:广东,44
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。