CN107766158A - 一种基于gperftools的内存管理方法 - Google Patents
一种基于gperftools的内存管理方法 Download PDFInfo
- Publication number
- CN107766158A CN107766158A CN201711071210.XA CN201711071210A CN107766158A CN 107766158 A CN107766158 A CN 107766158A CN 201711071210 A CN201711071210 A CN 201711071210A CN 107766158 A CN107766158 A CN 107766158A
- Authority
- CN
- China
- Prior art keywords
- memory
- internal memory
- thread
- gperftools
- management process
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
本申请发明一种基于gperftools的内存管理方法,通过本发明所述的内存管理方法,可以改进并实现在内存申请时将线程缓存机制与内存的大页机制相结合,即减少了多线程环境中线程申请内存对锁的竞争,同时提升了访存时的TLB命中率,从而提升了访存性能。
Description
技术领域
本发明涉及服务器内存管理领域,具体涉及一种基于gperftools的内存管理方法。
背景技术
glibc是GNU发布的libc库,即c运行库。glibc是linux***中最底层的api,几乎其它任何运行库都会依赖于glibc。glibc除了封装linux操作***所提供的***服务外,它本身也提供了许多其它一些必要功能服务的实现。由于glibc囊括了几乎所有的UNIX通行的标准,可以想见其内容包罗万象。而就像其他的UNIX***一样,其内含的档案群分散于***的树状目录结构中,像一个支架一般撑起整个操作***。在GNU/Linux***中,其C函式库发展史点出了GNU/Linux演进的几个重要里程碑,用glibc作为***的C函式库,是GNU/Linux演进的一个重要里程碑。
在Linux操作***中,目前使用的glibc库中的内存管理在多线程环境中申请内存时会有大量的锁的竞争,内存的申请与释放的效率比较低,而gperftools提供了一种基于线程缓存的内存管理库,提升多线程并发环境下访存性能,通过基于gperftools改进后的内存管理库可以结合内存大页机制进一步提升多线程并发环境下的访存性能。gperftools是***开发的一款非常实用的工具集,主要包括mallocfree内存分配器tcmalloc;基于tcmalloc的堆内存检测和内存泄漏分析工具heap-profiler,heap-checker;基于tcmalloc实现的程序CPU性能监测工具cpu-profiler。上述所说的三种工具在服务器进程的性能分析监控,定位内存泄漏,寻找性能热点,提高mallocfree内存分配性能的各个方面上都非常成功。
在Linux操作***中,使用的是gperftools提供的内存管理方法,使用线程缓存减少内存申请时的锁的竞争,通过替换当前环境中使用的malloc及free函数,使用新的malloc及free函数。Linux***下使用gperftools虽然能够利用线程缓存很好的解决内存申请时的锁的竞争问题,但该库在向***申请内存页时没有使用大页机制,在内存量比较大的环境中访存的性能会由于TLB的大量miss而下降。
针对这种情况,本申请发明一种基于gperftools的内存管理方法,通过本发明所述的内存管理方法,可以改进并实现在内存申请时将线程缓存机制与内存的大页机制相结合。
发明内容
本发明的主要实现方式为将基于线程缓存的内存管理与***的大页机制相结合,即减少了多线程环境中线程申请内存对锁的竞争,同时提升了访存时的TLB命中率,从而提升了访存性能。
具体地,本申请请求保护一种基于gperftools的内存管理方法,其特征在于,该方法具体包括如下步骤:
在***中预先设置一定数量的大页;
在运行程序时,预先为每个线程缓存一部分内存;
如果线程申请内存,则直接从本线程的缓存中获取内存;
当线程缓存中的内存不足时向***申请内存时使用预先设置的内存大页机制,并将内存放入线程缓存中。
如上所述的基于gperftools的内存管理方法,其特征还在于,在***中预先设置一定数量的大页是通过/proc/sys/vm/nr_hugepages在***中设置一定数量的大页。
如上所述的基于gperftools的内存管理方法,其特征还在于,该内存管理方法还可以扩展到smp环境下的多线程运行环境。
附图说明
图1、本发明所述内存管理方法的流程示意图
具体实施方式
本方法的具体实现是由多线程内存分配管理模块、***内存申请模块两个模块实现。其中多线程内存分配管理模块用于基于线程缓存的内存分配管理,***内存申请模块用于当线程缓存中的内存不足时向***申请内存。
多线程内存分配管理模块的主要功能是,先为每个线程缓存一部分内存,当线程申请内存时直接从本线程的缓存中获取内存,避免了锁的竞争,加快内存分配效率;当线程缓存中的内存不足时向***申请内存并将内存放入线程缓存中。
***内存申请模块的主要功能是,首先通过/proc/sys/vm/nr_hugepages在***中设置一定数量的大页,然后当向***申请内存时使用内存大页机制,提升访存时的TLB命中率,从而提升***的访存性能。下面通过一个实施例对本发明所述的具体实现步骤进行说明。
具体流程如图1所示。
在***中预先设置一定数量的大页;
在运行程序时,预先为每个线程缓存一部分内存;
如果线程申请内存,则直接从本线程的缓存中获取内存;
当线程缓存中的内存不足时向***申请内存时使用预先设置的内存大页机制,并将内存放入线程缓存中。
显而易见地,上面所示的仅仅是本发明的一个具体实施方式,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据上述实施例获得其他的技术方案,以及在本发明保护的范围内做出的等同变化均应落入本发明的保护范围内,都属于本发明保护的范围。
综上所述,本发明所述的方法还可以扩展到smp环境下的多线程运行环境,使用该方法后也可以提升***的访存性能。
Claims (3)
1.一种基于gperftools的内存管理方法,其特征在于,该方法具体包括如下步骤:
在***中预先设置一定数量的大页;
在运行程序时,预先为每个线程缓存一部分内存;
如果线程申请内存,则直接从本线程的缓存中获取内存;
当线程缓存中的内存不足时向***申请内存时使用预先设置的内存大页机制,并将内存放入线程缓存中。
2.如权利要求1所述的基于gperftools的内存管理方法,其特征还在于,在***中预先设置一定数量的大页是通过/proc/sys/vm/nr_hugepages在***中设置一定数量的大页。
3.如权利要求2所述的基于gperftools的内存管理方法,其特征还在于,该内存管理方法还可以扩展到smp环境下的多线程运行环境。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711071210.XA CN107766158A (zh) | 2017-11-03 | 2017-11-03 | 一种基于gperftools的内存管理方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711071210.XA CN107766158A (zh) | 2017-11-03 | 2017-11-03 | 一种基于gperftools的内存管理方法 |
Publications (1)
Publication Number | Publication Date |
---|---|
CN107766158A true CN107766158A (zh) | 2018-03-06 |
Family
ID=61272634
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201711071210.XA Pending CN107766158A (zh) | 2017-11-03 | 2017-11-03 | 一种基于gperftools的内存管理方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107766158A (zh) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108664419A (zh) * | 2018-04-03 | 2018-10-16 | 郑州云海信息技术有限公司 | 一种确定内存大页数目的方法及其装置 |
CN110727517A (zh) * | 2019-10-12 | 2020-01-24 | 福建顶点软件股份有限公司 | 一种基于分区设计的内存分配方法和装置 |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105893269A (zh) * | 2016-03-31 | 2016-08-24 | 武汉虹信技术服务有限责任公司 | 一种Linux***下内存管理方法 |
US20170163538A1 (en) * | 2015-12-02 | 2017-06-08 | Macau University Of Science And Technology | PacketUsher: Accelerating Computer-Intensive Packet Processing |
CN106970882A (zh) * | 2017-03-10 | 2017-07-21 | 浙江大学 | 一种基于Linux大页内存的易扩展页面架构 |
-
2017
- 2017-11-03 CN CN201711071210.XA patent/CN107766158A/zh active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20170163538A1 (en) * | 2015-12-02 | 2017-06-08 | Macau University Of Science And Technology | PacketUsher: Accelerating Computer-Intensive Packet Processing |
CN105893269A (zh) * | 2016-03-31 | 2016-08-24 | 武汉虹信技术服务有限责任公司 | 一种Linux***下内存管理方法 |
CN106970882A (zh) * | 2017-03-10 | 2017-07-21 | 浙江大学 | 一种基于Linux大页内存的易扩展页面架构 |
Non-Patent Citations (1)
Title |
---|
DZQABC: ""大页内存(HugePages)"", 《HTTP://WWW.CNBLOGS.COM/DONGZHIQUAN/P/5043912.HTML》 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108664419A (zh) * | 2018-04-03 | 2018-10-16 | 郑州云海信息技术有限公司 | 一种确定内存大页数目的方法及其装置 |
CN110727517A (zh) * | 2019-10-12 | 2020-01-24 | 福建顶点软件股份有限公司 | 一种基于分区设计的内存分配方法和装置 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8949295B2 (en) | Cooperative memory resource management via application-level balloon | |
US7472249B2 (en) | Kernel memory free algorithm | |
US7124251B2 (en) | Stack allocation system and method | |
EP1966703B1 (en) | Method and apparatus for hardware-based dynamic escape detection in managed run-time environments | |
US7882505B2 (en) | Method and apparatus for switching between per-thread and per-processor resource pools in multi-threaded programs | |
US10949342B2 (en) | Persistent memory garbage collection | |
US20180129255A1 (en) | Off-line affinity-aware parallel zeroing of memory in non-uniform memory access (numa) servers | |
CN106354543B (zh) | 一种基于虚拟机和宿主机内存地址转换的numa内存迁页方法 | |
US9424082B2 (en) | Application startup page fault management in a hardware multithreading environment | |
KR20140131089A (ko) | 자원 할당 장치 및 그 방법 | |
CN107766158A (zh) | 一种基于gperftools的内存管理方法 | |
US9189399B2 (en) | Stack cache management and coherence techniques | |
US10318198B2 (en) | Optimizable heap for embedded and similar systems with enhanced debugging and self-healing | |
US8103849B2 (en) | Reducing memory usage of kernel memory management structures | |
EP1971922B1 (en) | Memory architecture and access method | |
US9274946B2 (en) | Pre-leak detection scan to identify non-pointer data to be excluded from a leak detection scan | |
US8725974B2 (en) | Page-protection based memory access barrier traps | |
US7500074B2 (en) | Identifying relocatable kernel mappings | |
US20240193079A1 (en) | Method and device for deallocating dynamically allocated memory area | |
CN102521079A (zh) | 软件栈缓冲区溢出的容错方法 | |
US8375194B2 (en) | System and method for freeing memory | |
KR20080054324A (ko) | 멀티 쓰레드 기반 센서 운영체제 환경에서의 스택 할당방법 | |
Norlinder et al. | Compressed Forwarding Tables Reconsidered | |
US20230029331A1 (en) | Dynamically allocatable physically addressed metadata storage | |
CN101853206A (zh) | 一种软件性能的检测方法及装置 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20180306 |
|
RJ01 | Rejection of invention patent application after publication |