xxoo是什么| 医学检验技术是什么| 手上起皮是什么原因| 嘴唇有黑斑是什么病| 糖尿病适合吃什么水果| 梦见大水牛是什么兆头| 胆红素高有什么症状| 为什么叫五十肩| 阳虚是什么意思| 77年属蛇的是什么命| 怀疑是什么意思| 女生的下体长什么样| 双眼屈光不正是什么意思| 胸口闷堵是什么原因| 窦骁父母是干什么的| 食物中毒拉肚子吃什么药| 刚怀孕吃什么对胎儿好| 久旱逢甘露是什么意思| 结婚唱什么歌送给新人| 阴茎不硬是什么原因| 无私的动物是什么生肖| 仓鼠怀孕有什么特征| 什么时候闰十月| 外阴白斑挂什么科| 异想天开是什么意思| 眼压是什么意思| 什么症状提示月经马上要来了| 猫头鹰喜欢吃什么| 割包皮是什么| 备孕检查挂什么科| 兔子拉稀是什么原因| 青海有什么湖| vip是什么意思| 血常规红细胞偏高是什么原因| 子宫腺肌症吃什么药最有效| 天天喝白酒对身体有什么危害| 生孩子送什么花| 荔枝为什么上火| 北上广深是什么意思| 金不换是什么意思| 腿长身子短有什么说法| 早上八点是什么时辰| 什么叫痛风| 什么病会引起皮肤瘙痒| 无拘无束的意思是什么| 分销是什么意思| 乳糖酶是什么| 宝宝惊跳反射什么时候消失| 肚脐叫什么穴位| 吃空饷什么意思| 待业什么意思| 感冒有黄痰是什么原因| 十二月十四日是什么星座| 什么旺土| 财神是什么生肖| 蜈蚣咬了擦什么药最好| 什么是脉冲| 做梦梦见打架是什么意思| 三险一金是什么| 为什么尿有点偏红色| 笑靥什么意思| 剁椒是什么辣椒| 77年属什么生肖| 女人手心痒是什么征兆| 甲减和甲亢有什么区别| 哈库呐玛塔塔什么意思| 老人走之前有什么预兆| 男人艾灸什么地方壮阳| 眼睛充血用什么眼药水好| 大便带绿色是什么原因| 平菇不能和什么一起吃| chick是什么意思| 痛风能吃什么水果| 凌晨一点多是什么时辰| 苹果煮水有什么功效| 人间正道是沧桑是什么意思| 甘油三酯指什么| 牙龈肿痛吃什么水果| 脚发胀是什么前兆| 细菌性阴道炎用什么药效果好| daily什么意思| 孕妇手麻是什么原因引起的| 吃止疼药有什么副作用| 警备区是干什么的| 世界八大奇迹分别是什么| 胃不好可以吃什么水果| 梦到牛是什么意思| 山楂可以和什么一起泡水喝| 咳嗽痰中带血是什么原因| 袖珍人是什么意思| 吃什么容易怀孕| 什么是阿尔兹海默症| 脑多普勒检查什么| 射手座和什么座最配对| 技师是干什么的| 不为良相便为良医是什么意思| 苏麻为什么不嫁给康熙| 草字头加个弓念什么| 周易和易经有什么区别| 息肉是什么原因引起的| 去医院打耳洞挂什么科| 体育生能报什么专业| skirt什么意思| 怀孕吃什么药可以流掉| 氟哌酸又叫什么名字| 株连九族是什么意思| 过房养是什么意思| 治便秘什么药最好| 三月八号是什么星座| 敛财是什么意思| 茭头是什么| 马后炮是什么意思| annie英文名什么意思| 九月十二号是什么星座| 养狗有什么好处| 镜面人是什么意思| 右眼跳是什么意思| 7月份有什么节日吗| 维生素e有什么作用| 伤寒现在叫什么病| 五月天主唱叫什么名字| 字字珠玑是什么意思| 土黄色裤子配什么颜色上衣| 检查妇科清洁度三是什么意思| 乙肝看什么指标| amh是什么检查项目| 早孕反应最早什么时候出现| 血管鼓起来是什么原因| 什么汤| 麻风疫苗什么时候打| 什么是hr| 0元购是什么意思| 湿气到底是什么| 脾胃虚弱有什么症状| 单立人加吉念什么| 天珠是什么材质| 免疫球蛋白适合什么人| 业障什么意思| 动一下就出汗是什么原因| 牛黄安宫丸什么时候吃最好| 威士忌属于什么酒| 天麻长什么样子图片| 路痴是什么原因造成的| 扩词是什么| 妹妹是什么意思| 特警是干什么的| 青津果的功效是什么| 心源性哮喘首选什么药| 踮脚有什么好处| 为什么突然头晕| 肩膀疼去医院挂什么科| 突然头晕想吐是什么原因| 什么蚌相争| 阿玛尼是什么意思| 富是什么生肖| 家里停电了打什么电话| 哈密瓜苦是什么原因| 册封是什么意思| 为什么家里有蟑螂| 节制什么意思| 角瓜念什么| 芽轴发育成什么| 不完全性右束支阻滞是什么意思| 为什么手指会发麻| 胰腺做什么检查| 左胸上方隐痛什么原因| 尿路感染吃什么| 浸润性是什么意思| ala是什么| 白蛇是什么蛇| 子时是什么时间| 蔓越莓对女性妇科有什么好处| 麒麟是什么| 仙是什么意思| 婴儿胀气是什么原因| 抗心磷脂抗体是什么| 四五天不排便是什么原因| 11.5是什么星座| 什么食物对眼睛视力好| 骑马野战指什么生肖| 什么是义眼| 今天立冬吃什么| AT代表什么| 夏枯草是什么样子| 婆婆过生日送什么礼物好| 红红的太阳像什么| 滴虫性阴道炎用什么药效果最好| 为什么会有牙结石| 什么是快捷支付| 蜂蜜水什么时间喝最好| 低血糖有什么症状| ige是什么意思| 临盆是什么意思| 登高望远是什么生肖| hpv42阳性是什么意思| 4月份是什么星座| 男朋友过生日送什么礼物最有意义| 冷暴力什么意思| 内蒙古有什么特产| 台阶是什么意思| 为什么会得人乳头瘤病毒| 道地药材是什么意思| 榴莲是什么季节的| 百合什么时候开花| 孜字五行属什么| 猫在风水上代表什么| 1944年属什么生肖| 獭尾肝是什么意思| 查肾结石挂什么科| 下午17点是什么时辰| 气血不足吃什么中药| 茱萸什么意思| 什么是碳水食物有哪些| 十一月一号是什么星座| 你是电你是光是什么歌| 做梦数钱是什么意思啊| 沉甸甸的爱是什么意思| 腰椎间盘突出吃什么药| 65年出生属什么| 房水是什么| 力不到不为财是什么意思| 脂肪肝看什么指标| 1893年属什么| 占有欲是什么意思| 空孕囊是什么原因造成的| 什么葡萄品种最好吃| 红枣为什么要去核煮| 燃气泄露是什么味道| negative是什么意思| 月字旁与什么有关| 左腿麻木是什么征兆| 槐花什么时候开花| 心可舒治什么病| 什么的森林| 什么鱼最好养不容易死| 狗狗身上有皮肤病用什么药| 蔬菜沙拉都放什么菜| 七月4号是什么星座| 杯弓蛇影是什么物理现象| 双鱼座什么性格| 大仙为什么知道你的事| 肺五行属什么| 五月十四号是什么情人节| 比宇宙还大的是什么| 1942年属什么生肖| 魔芋爽是什么做的| borel手表是什么牌子| 罗马布是什么面料| 什么叫撤退性出血| 少田宅痣是什么意思| 高尿酸血症是什么意思| 02属什么| 血糖高是什么引起的| 孕妇抽筋是什么原因引起的| 乐什么什么什么成语| 明知故犯的故是什么意思| 舍本逐末是什么意思| 食品科学与工程学什么| 零四年属什么| 脑部缺氧有什么症状| 年岁是什么意思| 退烧吃什么药| 一厢情愿什么意思| 冰镇情人果是什么水果| 百度Jump to content

高通骁龙835平台亚洲首秀,携千兆级LTE连接未来

From Wikipedia, the free encyclopedia
(Redirected from Dynamic memory)
百度 中国平安新闻稿称,陆金所致力于利用科技赋能的金融DNA来提供个性化金融服务。

Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when no longer needed. This is critical to any advanced computer system where more than a single process might be underway at any time.[1]

Several methods have been devised that increase the effectiveness of memory management. Virtual memory systems separate the memory addresses used by a process from actual physical addresses, allowing separation of processes and increasing the size of the virtual address space beyond the available amount of RAM using paging or swapping to secondary storage. The quality of the virtual memory manager can have an extensive effect on overall system performance. The system allows a computer to appear as if it may have more memory available than physically present, thereby allowing multiple processes to share it.

In some operating systems, e.g. Burroughs/Unisys MCP,[2] and OS/360 and successors,[3] memory is managed by the operating system.[note 1] In other operating systems, e.g. Unix-like operating systems, memory is managed at the application level.

Memory management within an address space is generally categorized as either manual memory management or automatic memory management.

Manual memory management

[edit]
An example of external fragmentation

The task of fulfilling an allocation request consists of locating a block of unused memory of sufficient size. Memory requests are satisfied by allocating portions from a large pool[note 2] of memory called the heap[note 3] or free store. At any given time, some parts of the heap are in use, while some are "free" (unused) and thus available for future allocations. In the C language, the function which allocates memory from the heap is called malloc and the function which takes previously allocated memory and marks it as "free" (to be used by future allocations) is called free. [note 4]

Several issues complicate the implementation, such as external fragmentation, which arises when there are many small gaps between allocated memory blocks, which invalidates their use for an allocation request. The allocator's metadata can also inflate the size of (individually) small allocations. This is often managed by chunking. The memory management system must track outstanding allocations to ensure that they do not overlap and that no memory is ever "lost" (i.e. that there are no "memory leaks").

Efficiency

[edit]

The specific dynamic memory allocation algorithm implemented can impact performance significantly. A study conducted in 1994 by Digital Equipment Corporation illustrates the overheads involved for a variety of allocators. The lowest average instruction path length required to allocate a single memory slot was 52 (as measured with an instruction level profiler on a variety of software).[1]

Implementations

[edit]

Since the precise location of the allocation is not known in advance, the memory is accessed indirectly, usually through a pointer reference. The specific algorithm used to organize the memory area and allocate and deallocate chunks is interlinked with the kernel, and may use any of the following methods:

Fixed-size blocks allocation

[edit]

Fixed-size blocks allocation, also called memory pool allocation, uses a free list of fixed-size blocks of memory (often all of the same size). This works well for simple embedded systems where no large objects need to be allocated but suffers from fragmentation especially with long memory addresses. However, due to the significantly reduced overhead, this method can substantially improve performance for objects that need frequent allocation and deallocation, and so it is often used in video games.

Buddy blocks

[edit]

In this system, memory is allocated into several pools of memory instead of just one, where each pool represents blocks of memory of a certain power of two in size, or blocks of some other convenient size progression. All blocks of a particular size are kept in a sorted linked list or tree and all new blocks that are formed during allocation are added to their respective memory pools for later use. If a smaller size is requested than is available, the smallest available size is selected and split. One of the resulting parts is selected, and the process repeats until the request is complete. When a block is allocated, the allocator will start with the smallest sufficiently large block to avoid needlessly breaking blocks. When a block is freed, it is compared to its buddy. If they are both free, they are combined and placed in the correspondingly larger-sized buddy-block list.

Slab allocation

[edit]

This memory allocation mechanism preallocates memory chunks suitable to fit objects of a certain type or size.[5] These chunks are called caches and the allocator only has to keep track of a list of free cache slots. Constructing an object will use any one of the free cache slots and destructing an object will add a slot back to the free cache slot list. This technique alleviates memory fragmentation and is efficient as there is no need to search for a suitable portion of memory, as any open slot will suffice.

Stack allocation

[edit]

Many Unix-like systems as well as Microsoft Windows implement a function called alloca for dynamically allocating stack memory in a way similar to the heap-based malloc. A compiler typically translates it to inlined instructions manipulating the stack pointer.[6] Although there is no need of manually freeing memory allocated this way as it is automatically freed when the function that called alloca returns, there exists a risk of overflow. And since alloca is an ad hoc expansion seen in many systems but never in POSIX or the C standard, its behavior in case of a stack overflow is undefined.

A safer version of alloca called _malloca, which reports errors, exists on Microsoft Windows. It requires the use of _freea.[7] gnulib provides an equivalent interface, albeit instead of throwing an SEH exception on overflow, it delegates to malloc when an overlarge size is detected.[8] A similar feature can be emulated using manual accounting and size-checking, such as in the uses of alloca_account in glibc.[9]

Automated memory management

[edit]

The proper management of memory in an application is a difficult problem, and several different strategies for handling memory management have been devised.

Automatic management of call stack variables

[edit]

In many programming language implementations, the runtime environment for the program automatically allocates memory in the call stack for non-static local variables of a subroutine, called automatic variables, when the subroutine is called, and automatically releases that memory when the subroutine is exited. Special declarations may allow local variables to retain values between invocations of the procedure, or may allow local variables to be accessed by other subroutines. The automatic allocation of local variables makes recursion possible, to a depth limited by available memory.

Garbage collection

[edit]

Garbage collection is a strategy for automatically detecting memory allocated to objects that are no longer usable in a program, and returning that allocated memory to a pool of free memory locations. This method is in contrast to "manual" memory management where a programmer explicitly codes memory requests and memory releases in the program. While automatic garbage collection has the advantages of reducing programmer workload and preventing certain kinds of memory allocation bugs, garbage collection does require memory resources of its own, and can compete with the application program for processor time.

Reference counting

[edit]

Reference counting is a strategy for detecting that memory is no longer usable by a program by maintaining a counter for how many independent pointers point to the memory. Whenever a new pointer points to a piece of memory, the programmer is supposed to increase the counter. When the pointer changes where it points, or when the pointer is no longer pointing to any area or has itself been freed, the counter should decrease. When the counter drops to zero, the memory should be considered unused and freed. Some reference counting systems require programmer involvement and some are implemented automatically by the compiler. A disadvantage of reference counting is that circular references can develop which cause a memory leak to occur. This can be mitigated by either adding the concept of a "weak reference" (a reference that does not participate in reference counting, but is notified when the area it is pointing to is no longer valid) or by combining reference counting and garbage collection together.

Memory pools

[edit]

A memory pool is a technique of automatically deallocating memory based on the state of the application, such as the lifecycle of a request or transaction. The idea is that many applications execute large chunks of code which may generate memory allocations, but that there is a point in execution where all of those chunks are known to be no longer valid. For example, in a web service, after each request the web service no longer needs any of the memory allocated during the execution of the request. Therefore, rather than keeping track of whether or not memory is currently being referenced, the memory is allocated according to the request or lifecycle stage with which it is associated. When that request or stage has passed, all associated memory is deallocated simultaneously.

Systems with virtual memory

[edit]

Virtual memory is a method of decoupling the memory organization from the physical hardware. The applications operate on memory via virtual addresses. Each attempt by the application to access a particular virtual memory address results in the virtual memory address being translated to an actual physical address.[10] In this way the addition of virtual memory enables granular control over memory systems and methods of access.

In virtual memory systems the operating system limits how a process can access the memory. This feature, called memory protection, can be used to disallow a process to read or write to memory that is not allocated to it, preventing malicious or malfunctioning code in one program from interfering with the operation of another.

Even though the memory allocated for specific processes is normally isolated, processes sometimes need to be able to share information. Shared memory is one of the fastest techniques for inter-process communication.

Memory is usually classified by access rate into primary storage and secondary storage. Memory management systems, among other operations, also handle the moving of information between these two levels of memory.

Memory management in Burroughs/Unisys MCP systems[2]

[edit]

An operating system manages various resources in the computing system. The memory subsystem is the system element for managing memory. The memory subsystem combines the hardware memory resource and the MCP OS software that manages the resource.

The memory subsystem manages the physical memory and the virtual memory of the system (both part of the hardware resource). The virtual memory extends physical memory by using extra space on a peripheral device, usually disk. The memory subsystem is responsible for moving code and data between main and virtual memory in a process known as overlaying. Burroughs was the first commercial implementation of virtual memory (although developed at Manchester University for the Ferranti Atlas computer) and integrated virtual memory with the system design of the B5000 from the start (in 1961) needing no external memory management unit (MMU).[11]:?48?

The memory subsystem is responsible for mapping logical requests for memory blocks to physical portions of memory (segments) which are found in the list of free segments. Each allocated block is managed by means of a segment descriptor,[12] a special control word containing relevant metadata about the segment including address, length, machine type, and the p-bit or ‘presence’ bit which indicates whether the block is in main memory or needs to be loaded from the address given in the descriptor.

Descriptors are essential in providing memory safety and security so that operations cannot overflow or underflow the referenced block (commonly known as buffer overflow). Descriptors themselves are protected control words that cannot be manipulated except for specific elements of the MCP OS (enabled by the UNSAFE block directive in NEWP).

Donald Knuth describes a similar system in Section 2.5 ‘Dynamic Storage Allocation’ of ‘Fundamental Algorithms’.[disputeddiscuss]

Memory management in OS/360 and successors

[edit]

IBM System/360 does not support virtual memory.[note 5] Memory isolation of jobs is optionally accomplished using protection keys, assigning storage for each job a different key, 0 for the supervisor or 1–15. Memory management in OS/360 is a supervisor function. Storage is requested using the GETMAIN macro and freed using the FREEMAIN macro, which result in a call to the supervisor (SVC) to perform the operation.

In OS/360 the details vary depending on how the system is generated, e.g., for PCP, MFT, MVT.

In OS/360 MVT, suballocation within a job's region or the shared System Queue Area (SQA) is based on subpools, areas a multiple of 2 KB in size—the size of an area protected by a protection key. Subpools are numbered 0–255.[13] Within a region subpools are assigned either the job's storage protection or the supervisor's key, key 0. Subpools 0–127 receive the job's key. Initially only subpool zero is created, and all user storage requests are satisfied from subpool 0, unless another is specified in the memory request. Subpools 250–255 are created by memory requests by the supervisor on behalf of the job. Most of these are assigned key 0, although a few get the key of the job. Subpool numbers are also relevant in MFT, although the details are much simpler.[14] MFT uses fixed partitions redefinable by the operator instead of dynamic regions and PCP has only a single partition.

Each subpool is mapped by a list of control blocks identifying allocated and free memory blocks within the subpool. Memory is allocated by finding a free area of sufficient size, or by allocating additional blocks in the subpool, up to the region size of the job. It is possible to free all or part of an allocated memory area.[15]

The details for OS/VS1 are similar[16] to those for MFT and for MVT; the details for OS/VS2 are similar to those for MVT, except that the page size is 4 KiB. For both OS/VS1 and OS/VS2 the shared System Queue Area (SQA) is nonpageable.

In MVS the address space[17] includes an additional pageable shared area, the Common Storage Area (CSA), and two additional private areas, the nonpageable local system queue area (LSQA) and the pageable System Work area (SWA). Also, the storage keys 0–7 are all reserved for use by privileged code.

See also

[edit]

Notes

[edit]
  1. ^ However, the run-time environment for a language processor may subdivide the memory dynamically acquired from the operating system, e.g., to implement a stack.
  2. ^ In some operating systems, e.g., OS/360, the free storage may be subdivided in various ways, e.g., subpools in OS/360, below the line, above the line and above the bar in z/OS.
  3. ^ Not to be confused with the unrelated heap data structure.
  4. ^ A simplistic implementation of these two functions can be found in the article "Inside Memory Management".[4]
  5. ^ Except on the Model 67

References

[edit]
  1. ^ a b Detlefs, D.; Dosser, A.; Zorn, B. (June 1994). "Memory allocation costs in large C and C++ programs" (PDF). Software: Practice and Experience. 24 (6): 527–542. CiteSeerX 10.1.1.30.3073. doi:10.1002/spe.4380240602. S2CID 14214110.
  2. ^ a b "Unisys MCP Managing Memory". System Operations Guid. Unisys.
  3. ^ "Main Storage Allocation" (PDF). IBM Operating System/360 Concepts and Facilities (PDF). IBM Systems Reference Library (First ed.). IBM Corporation. 1965. p. 74. Retrieved Apr 3, 2019.
  4. ^ Jonathan Bartlett. "Inside Memory Management". IBM DeveloperWorks.
  5. ^ Silberschatz, Abraham; Galvin, Peter B. (2004). Operating system concepts. Wiley. ISBN 0-471-69466-5.
  6. ^ alloca(3) – Linux Programmer's Manual – Library Functions
  7. ^ "_malloca". Microsoft CRT Documentation. 26 October 2022.
  8. ^ "gnulib/malloca.h". GitHub. Retrieved 24 November 2019.
  9. ^ "glibc/include/alloca.h". Beren Minor's Mirrors. 23 November 2019.
  10. ^ Tanenbaum, Andrew S. (1992). Modern Operating Systems. Englewood Cliffs, N.J.: Prentice-Hall. p. 90. ISBN 0-13-588187-0.
  11. ^ Waychoff, Richard. "Stories About the B5000 and People Who Were There" (PDF). Computer History Museum.
  12. ^ The Descriptor (PDF). Burroughs Corporation. February 1961.
  13. ^ OS360Sup, pp. 82–85.
  14. ^ OS360Sup, pp. 82.
  15. ^ Program Logic: IBM System/360 Operating System MVT Supervisor (PDF). IBM Corporation. May 1973. pp. 107–137. Retrieved Apr 3, 2019.
  16. ^ OSVS1Dig, p. 2.37-2.39.
  17. ^ "Virtual Storage Layout" (PDF). Introduction to OS/VS2 Release 2 (PDF). Systems (first ed.). IBM. March 1973. p. 37. GC28-0661-1. Retrieved July 15, 2024.

Bibliography

[edit]
OS360Sup
OS Release 21 IBM System/360 Operating System Supervisor Services and Macro Instructions (PDF). IBM Systems Reference Library (Eighth ed.). IBM. September 1974. GC28-6646-7.
OSVS1Dig
OS/VS1 Programmer's Reference Digest Release 6 (PDF). Systems (Sixth ed.). IBM. September 15, 1976. GC24-5091-5 with TNLs.
[edit]
10万个为什么 空心菜又叫什么菜 三叶香是什么菜 慷慨什么意思 tp代表什么
睾丸疼痛吃什么药最好 毕业是什么意思 至夏什么意思 穿刺是什么检查 肺结节手术后吃什么好
跟腱炎吃什么药效果好 胰腺炎不能吃什么食物 抽血为什么要空腹 包袱什么意思 2008年是属什么
湿气重是什么原因引起的 回应是什么意思 氨基比林是什么药 lin是什么意思 石钟乳是什么意思
妄语是什么意思hcv8jop6ns0r.cn 年轻人血压高是什么原因引起的hcv8jop5ns0r.cn 支气管发炎是什么原因引起的yanzhenzixun.com 日本樱花什么时候开hcv8jop6ns8r.cn 入港是什么意思hcv9jop4ns9r.cn
8月7日什么星座hcv8jop0ns8r.cn 尿酸偏高是什么意思hkuteam.com i.t品牌什么档次hanqikai.com sheep是什么意思hcv9jop2ns4r.cn 泡脚时间长了有什么坏处hcv7jop6ns7r.cn
北方的木瓜叫什么hcv8jop8ns8r.cn 异丙醇是什么东西hcv9jop2ns2r.cn 霉菌反复发作是什么原因hcv8jop3ns6r.cn 痣挂什么科hcv8jop5ns5r.cn 什么食物维生素A含量高hcv8jop8ns3r.cn
2036年是什么年hcv8jop0ns1r.cn 什么是向量hcv9jop7ns2r.cn 尿液红细胞高是什么原因hcv8jop3ns2r.cn 养囊是什么意思hcv7jop7ns1r.cn 皂矾是什么hcv9jop1ns2r.cn
百度