Wired Memory

https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html#//apple_ref/doc/uid/20001880-99714-TPXREF106

Wired memory (also called resident memory) stores kernel code and data structures that must never be paged out to disk. Applications, frameworks, and other user-level software cannot allocate wired memory. However, they can affect how much wired memory exists at any time. For example, an application that creates threads and ports implicitly allocates wired memory for the required kernel resources that are associated with them.

Table 2 lists some of the wired-memory costs for application-generated entities.

Table 2  Wired memory generated by user-level software

Resource


Wired Memory Used by Kernel


Process


16 kilobytes


Thread


blocked in a continuation—5 kilobytes; blocked—21 kilobytes


Mach port


116 bytes


Mapping


32 bytes


Library


2 kilobytes plus 200 bytes for each task that uses it


Memory region


160 bytes

Note: These measurements may change with each new release of the operating system. They are provided here to give you a rough estimate of the relative cost of system resource usage.

As you can see, every thread, process, and library contributes to the resident footprint of the system. In addition to your application using wired memory, however, the kernel itself requires wired memory for the following entities:

  • VM objects
  • the virtual memory buffer cache
  • I/O buffer caches
  • drivers

Wired data structures are also associated with the physical page and map tables used to store virtual-memory mapping information, Both of these entities scale with the amount of available physical memory. Consequently, when you add memory to a system, the amount of wired memory increases even if nothing else changes. When a computer is first booted into the Finder, with no other applications running, wired memory can consume approximately 14 megabytes of a 64 megabyte system and 17 megabytes of a 128 megabyte system.

Wired memory pages are not immediately moved back to the free list when they become invalid. Instead they are “garbage collected” when the free-page count falls below the threshold that triggers page out events.

Page Lists in the Kernel

The kernel maintains and queries three system-wide lists of physical memory pages:

  • The active list contains pages that are currently mapped into memory and have been recently accessed.
  • The inactive list contains pages that are currently resident in physical memory but have not been accessed recently. These pages contain valid data but may be removed from memory at any time.
  • The free list contains pages of physical memory that are not associated with any address space of VM object. These pages are available for immediate use by any process that needs them.

When the number of pages on the free list falls below a threshold (determined by the size of physical memory), the pager attempts to balance the queues. It does this by pulling pages from the inactive list. If a page has been accessed recently, it is reactivated and placed on the end of the active list. In OS X, if an inactive page contains data that has not been written to the backing store recently, its contents must be paged out to disk before it can be placed on the free list. (In iOS, modified but inactive pages must remain in memory and be cleaned up by the application that owns them.) If an inactive page has not been modified and is not permanently resident (wired), it is stolen (any current virtual mappings to it are destroyed) and added to the free list. Once the free list size exceeds the target threshold, the pager rests.

The kernel moves pages from the active list to the inactive list if they are not accessed; it moves pages from the inactive list to the active list on a soft fault (see Paging In Process). When virtual pages are swapped out, the associated physical pages are placed in the free list. Also, when processes explicitly free memory, the kernel moves the affected pages to the free list.

Paging Out Process

In OS X, when the number of pages in the free list dips below a computed threshold, the kernel reclaims physical pages for the free list by swapping inactive pages out of memory. To do this, the kernel iterates all resident pages in the active and inactive lists, performing the following steps:

  1. If a page in the active list is not recently touched, it is moved to the inactive list.
  2. If a page in the inactive list is not recently touched, the kernel finds the page’s VM object.
  3. If the VM object has never been paged before, the kernel calls an initialization routine that creates and assigns a default pager object.
  4. The VM object’s default pager attempts to write the page out to the backing store.
  5. If the pager succeeds, the kernel frees the physical memory occupied by the page and moves the page from the inactive to the free list.

Note: In iOS, the kernel does not write pages out to a backing store. When the amount of free memory dips below the computed threshold, the kernel flushes pages that are inactive and unmodified and may also ask the running application to free up memory directly. For more information on responding to these notifications, see Responding to Low-Memory Warnings in iOS.

时间: 2024-10-04 21:10:10

Wired Memory的相关文章

iOS多线程开发(二)---线程管理

线程管理 线程管理包括创建,配置,退出三部分.主要包括创建线程的成本,线程创建,线程属性配置,线程主体入口函数编写,线程中断等 一,线程创建成本 1,为辅助线程分配的堆栈空间大小,便于系统和进程管理,以及为函数参数和局部变量分配空间 A,内核数据结构(kernel data structures)---大约1KB,This memory is used to store the thread data structures and attributes, much of which is all

iOS多线程编程指南(二)线程管理

当应用程序生成一个新的线程的时候,该线程变成应用程序进程空间内的一个实体.每个线程都拥有它自己的执行堆栈,由内核调度独立的运行时间片.一个线程可以和其他线程或其他进程通信,执行I/O操作,甚至执行任何你想要它完成的任务.因为它们处于相同的进程空间,所以一个独立应用程序里面的所有线程共享相同的虚拟内存空间,并且具有和进程相同的访问权限. 一.线程成本 多线程会占用你应用程序(和系统的)的内存使用和性能方面的资源.每个线程都需要分配一定的内核内存和应用程序内存空间的内存.管理你的线程和协调其调度所需

ios多线程使用之细细细~解

在开发中经常会用到多线程来处理一些比较耗时的任务,比如下载的时候存储数据.当进入一个新页面的时候将网络请求放在后台,数据下来之后再到主线程来将数据展示出来等操作,以此来满足用户大老爷的体验,让他们开开心心的用我们开发出来的应用而不是用的时候一脸懵逼的等待响应T T.平常在开发的过程中,我们只需将耗时应用放在后台的子线程.任务结束之后回到主线程来刷新页面就好了.基本下面的几行代码是我们最常用到的: dispatch_async(dispatch_get_global_queue(0, 0), ^{

iOS开发者必备并发编程技巧

在iOS并发编程中经常会遇到一些问题,我们在这里并不探究 NSThread . GCD . NSOperation . NSOperationQueue 的具体用法,只探讨一些容易被遗忘的小点.希望对广大iOS开发者能够起到一定的帮助. 线程成本 维基百科上对线程的解释是: A thread of execution is the smallest sequence of programmed instructions that can be managed independently by a

dirty memory

关于各种内存的解释,来源于stackoverflow Wired : This refers to kernel code and such. Memory that should not   ever be moved out of the RAM. Also know as resident memory. Shared : Memory that is shared between two or more processes. Both   processes would show thi

Super Memory & Reading Skills

Super Memory & Reading Skills 341views Zaid Ali Alsagoff (91 SlideShares) , e-Learning Manager at IMU Keynote Author Follow 0 16 7 0 Published on Apr 15, 2015 In this workshop at IMU (16/04/2015), we will explore various techniques to stimulate and e

Linux 性能监控 : CPU 、Memory 、 IO 、Network

一.CPU 1.良好状态指标 CPU利用率:User Time <= 70%,System Time <= 35%,User Time + System Time <= 70% 上下文切换:与CPU利用率相关联,如果CPU利用率状态良好,大量的上下文切换也是可以接受的 可运行队列:每个处理器的可运行队列<=3个线程 2.监控工具 vmstat $ vmstat 1 procs -----------memory---------- ---swap-- -----io---- --s

Java系列: 如何在Eclipse中安装Memory Analyzer插件

一.找到eclipse的插件安装对话框: help->install new software ->work with 二.输入Memory Analyzer的安装路径 具体可以到http://www.eclipse.org/mat/downloads.php 去找 我安装的时候的版本是1.6.1,如下 三.开始安装     null

CSharp - Memory leaks problem detection and solution

/* By Dylan SUN*/ Out of memory exception happens when server doesn't have enough memory to run the application. This often happens when you are dealing with external resources, such as consuming Interop libraries, treating files, streams, etc. Memor