Computer memory stores information that a computer can retrieve while executing computer programs. A memory location holds a value, and a memory address selects a location under the machine's addressing rules. In a byte-addressed example, consecutive bytes have consecutive memory addresses; a four-byte value can occupy four locations. The interpretation of those stored bits as a number, an instruction or another representation belongs to the computer program and architecture.
Computer memory has different physical and logical roles. Non-volatile memory retains stored information without power, while other technologies require power to retain it. A memory cache holds selected information for faster reuse; virtual memory presents an operating-system process with its own address space. These describe different properties, so a cached value and its virtual address should not be confused with the physical storage holding it.
In the paging examples, resident memory pages occupy main computer memory, and address translation maps a virtual address to a physical address. The operating system can change a mapping while keeping an operating-system process's numerical virtual address unchanged. This separation makes controlled sharing and isolation possible.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. chapter 2, memory virtualization overview
Memory allocation reserves computer memory for a program’s data and makes that storage accessible through memory addresses. Allocation determines where data can live and how long the storage remains available; initialization determines the data’s initial value. A language can arrange storage automatically for local variables, retain storage for the duration of a program, or request storage dynamically while the program runs.
In the C programming language,
malloc(n) requests a block of bytes and returns a pointer to it, or a null pointer if allocation fails. Successful allocation does not initialize those bytes. The free operation releases a previously allocated block for subsequent allocation; accessing it through an old pointer is no longer valid.[ref][ref] Allocation and deallocation are therefore separate from reading and writing an object. Deallocation need not erase its former contents or immediately return its storage to the operating system.For a process using virtual memory, a contiguous interval of memory addresses does not require a contiguous interval of physical memory. The memory management unit can map successive virtual pages to different physical page frames. Conversely, a successful small allocation may be satisfied from an existing free block without asking the operating system for another page.
Two small bookkeeping examples explain why free capacity alone does not determine whether an allocation succeeds. If an allocator rounds a 17-byte request up to a 32-byte allocation unit, 15 bytes are unused inside that unit: internal fragmentation, before counting any allocator metadata. If two free 32-byte blocks are separated by an occupied block, a request for one contiguous 48-byte block cannot fit in either hole, even though 64 bytes are free. That is external memory fragmentation, under the assumption that the occupied block cannot be moved and no further storage is available. Adjacent free blocks can sometimes be combined; separated ones require a different placement or movement strategy.
Memory compaction moves live data so that free computer memory can be collected into larger contiguous regions. It changes data placement, while memory block coalescing combines intervals that are already free and adjacent. Compaction therefore needs a way to preserve the meaning of references to moved data. An ordinary allocator cannot freely move an arbitrary live C programming language allocation behind unchanged raw pointers.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, §17.1, live-allocation nonrelocation assumption and compaction discussion, printed pp.2–3
Consider the104-byte pool with free blocks of24,40 and16 bytes, separated by live blocks of16 and8 bytes. Its total free capacity is80 bytes, but its largest free memory block is40 bytes. If both live blocks are movable, placing the16-byte object at offset0 and the8-byte object at offset16 creates one free80-byte interval from24 to104. No additional capacity is created; its contiguity improves.
The references must follow each movable memory object. A reference to offset24 in the original first object becomes offset0; a reference five bytes inside that object changes from29 to5. A garbage collection system with accurate reference information or another suitable level of indirection can arrange such updates. Blindly replacing every integer equal to an old address would corrupt unrelated data.
Physical-page compaction is a different allocation-layer application. An operating system can move eligible pages while preserving a process's virtual memory addresses through updated mappings. Linux's documented compaction mechanism seeks contiguous free physical blocks, including for large-page allocation; moving pages also has execution costs and can affect latency.[ref]
Documentation for /proc/sys/vm/ in the Linux kernel documentation. Linux v6.12 documentation, compact_memory and compaction_proactiveness sections
Such physical rearrangement does not automatically combine separated virtual heap holes. The address space, movable objects and reference-preservation mechanism must accompany a compaction claim.A movable memory object is a live allocation that its memory-management system may relocate while preserving its identity and valid references. Moving the stored bytes is only part of the operation: references must be updated, or an indirection mechanism must continue to locate the object. This capability permits memory compaction. Microsoft's primary runtime documentation describes separate marking, reference-relocation and object-compaction phases of garbage collection.[ref]
Fundamentals of garbage collection by Microsoft. “What happens during a garbage collection”, marking, relocating and compacting phases
For an illustrative16-byte object initially starting at offset24, compaction may place its bytes at offset0. A reference to its beginning then changes from24 to0; a reference five bytes inside it changes from29 to5. In general, moving the base from to maps a tracked interior reference to . An unrelated integer with value29 must not be rewritten merely because it resembles the old address.
The memory manager therefore needs reliable knowledge of roots and references, including those held in other live objects. A garbage collection root can keep an object reachable while its address changes. If an external consumer requires the address to stay fixed, a pinned memory object imposes a relocation constraint instead. Movability is a property of the reference-management arrangement, not simply of whether the object contains bytes that can be copied.
A raw C programming language pointer returned by an ordinary allocator generally prevents arbitrary hidden movement, because the allocator does not control all copies of that address.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, §17.1, nonrelocation assumption and tracked-reference discussion, printed pp.2–3
Physical-page movement under virtual memory is another layer: an operating system may preserve virtual addresses while changing the underlying physical mapping. It need not make the application-level object movable in its own address space.A pinned memory object is a normally movable memory object whose address must remain unchanged during a specified operation. Pinning permits a pointer to remain usable when the code consuming it cannot participate in the runtime's relocation of references. The pinning lifetime is part of that guarantee: an address retained beyond the protected operation need not remain valid. Microsoft's language reference specifies that a
fixed statement prevents relocation during its body and restricts the declared pointer to that statement.[ref]Fixed statement in the C reference by Microsoft. Opening definition; array-element and object-field guarantees
For an original layout example, consider96 bytes with a pinned16-byte object at offsets and one other16-byte live object. The remaining64 bytes are free. Even if the other object can move anywhere, the pinned object divides the address range into regions of32 and48 bytes. A56-byte contiguous allocation cannot fit. Moving the other object into gives free intervals and , whose largest size is48 bytes. If both live objects could move, placing them in would instead leave a64-byte interval. Pinning can therefore limit memory compaction despite ample total free capacity.
The numerical layout omits allocation headers and memory alignment; a real allocator must include them. Pinning an object's address also does not by itself specify how its virtual memory pages are backed. The garbage collector's object-relocation guarantee and an operating system's physical-page residency rules concern different layers. Likewise, a pinned buffer in a storage cache may mean protection from eviction rather than this object-relocation guarantee.
Once the protected operation is finished, releasing its pin can restore the runtime's freedom to move the object during a later collection. The program still has to obey the language's reference-lifetime rules: releasing a pin does not convert an old unmanaged address into a relocatable reference. The general garbage collection process must update references when it moves surviving objects.[ref]
Fundamentals of garbage collection by Microsoft. “What happens during a garbage collection”, relocating and compacting phases
The pinning lifetime is the interval during which a pinned memory object must retain its address for all consumers entitled to use a non-relocatable pointer into it. The interval must cover actual memory access, rather than merely the act of handing out the address. Microsoft's
fixed statement guarantees address stability during its body and restricts its declared pointer to that statement; a pointer retained for later work needs a guarantee covering that later work too.[ref]Fixed statement in the C reference by Microsoft. Opening definition and array-element/object-field lifetime guarantees
For an original timing example, suppose a pin starts at0ms, an external operation receives the address at0.5ms, its submission function returns at1ms, and its final memory access finishes at5ms. Releasing the pin at the function's return leaves4ms of possible access after address stability has ended. Releasing it only after completion at5ms can cover the whole access interval. These times describe an illustrative protocol, not a timing claim about a particular runtime or device.
If the pin is active on , every access time must satisfy . With several users, the release point must follow the last access by all of them. A count of outstanding operations can enforce this rule: after two operations start, one completion changes the count from2 to1 and does not permit release; the last completion changes1 to0. Asynchronous pin release therefore depends on a completion guarantee. Requesting that unfinished work stop does not by itself demonstrate that its final access has ended.
The pinning lifetime and data synchronization solve different problems. Stable addresses do not prevent two users from changing the same bytes concurrently; a mutex or another synchronization mechanism may still be needed. Nor should a pin be held indefinitely just because longer protection seems convenient: pinning can obstruct memory compaction, as the pinned memory object layout example shows. The useful interval is long enough for the access contract and ends when that contract permits release.
Asynchronous pin release ends the address-stability guarantee for a pinned memory object after an operation that can continue beyond its submission call. Its central condition is that no unfinished consumer may still access the pinned address. Returning from submission is sufficient only when the operation's contract says that all access has ended. Microsoft's asynchronous native-call example stores the pin handle in callback state and disposes it during completion cleanup.[ref]
Memory and Span usage guidelines by Microsoft. Rule10, asynchronous native-call wrapper and completion callback
For an original event sequence, suppose an operation acquires a pin at0ms, submits at1ms, returns a pending result at2ms and finishes its last access at8ms. Completion cleanup at8ms can end the pinning lifetime; cleanup at2ms cannot. If a request to stop arrives at3ms but the operation acknowledges completion only at6ms, the request alone does not authorize release at3ms. The actual access contract, rather than the desired outcome, determines when the address may change.
An implementation needs a single owner for cleanup across all completion paths. Submission might fail before any callback is promised, complete immediately, or complete later. Each path must transfer or retain the cleanup responsibility consistently. The exactly-once pin cleanup requirement avoids both leaking a pin and releasing the same handle twice. The primary Microsoft example explicitly cleans up an exception before a callback can be invoked, and funnels immediate and deferred completion through a completion routine.[ref]
Memory and Span usage guidelines by Microsoft. Rule10, exception cleanup and non-pending completion branch
With overlapping users, releasing one operation's interest does not establish that every user has finished. A reference counting protocol can track outstanding access leases, provided starting new work and deciding that the last lease ended are synchronized. An observed zero count without protection against a simultaneous new user is not sufficient. A mutex or another appropriate synchronization mechanism can protect that transition.
The completion signal must itself describe the end of access. Microsoft's task-based buffer rule forbids a consumer from continuing to use the memory after the returned task reaches a terminal state.[ref]
Memory and Span usage guidelines by Microsoft. Rule4, consumer lifetime and task terminal state
An API that reports cancellation before its underlying user has stopped requires another completion guarantee before pin cleanup. Retaining the pin protects the address; it does not by itself prevent concurrent data races or determine who may reuse the buffer.Exactly-once pin cleanup gives one owner responsibility for ending a particular pinning lifetime, despite several possible completion paths. The resource must remain pinned until its consumers finish, and its cleanup must occur once after that condition is met. This combines the safety requirement of asynchronous pin release with a liveness requirement: a pin left permanently owned by nobody can obstruct later memory compaction.
A useful state machine has states “submission in progress”, “completion pending” and “released”. A submission error that guarantees no future consumer can access the address may take the first state directly to released. A pending result transfers cleanup responsibility to a completion path. Immediate completion must follow the API's stated rule about whether a callback will also arrive; it must not independently trigger two owners to dispose of the same handle. Microsoft's native-call example explicitly handles submission exceptions and funnels immediate or deferred completion into cleanup.[ref]
Memory and Span usage guidelines by Microsoft. Rule10, exception branch, non-pending result branch and completion routine
For an original race example, suppose a completion callback and an error-reporting path can both observe an operation as finished. A plain sequence “test flag; if clear, set flag; release pin” can race: both callers read clear before either writes set, and both release. A synchronized ownership claim, using a mutex or an appropriate compare-and-swap transition, can ensure that only one caller changes pending to released. The losing caller performs no cleanup. This is a schematic ownership protocol, not a claim that every pin API tolerates arbitrary racing callbacks.
For a count of releases on one acquired handle, the at-most-once condition is . The requirement that cleanup eventually occurs after all promised access has ended supplies at final completion, so together they give . A one-time flag alone establishes neither the end of access nor eventual execution of the winning path.
The operation's state must also stay alive while any callback can inspect it. Reference counting can protect that state independently of the pin being released. Marking a handle released does not permit another caller to access freed callback state. Keeping resource ownership, callback-state lifetime and data synchronization separate makes the protocol easier to verify. The primary task-based memory rule similarly requires all consumer access to finish by task termination.[ref]
Memory and Span usage guidelines by Microsoft. Rule4, consumer lifetime through terminal task state
Memory block coalescing merges adjacent free allocation blocks into a larger free block. It improves the allocator's representation and use of free space without moving intervening live objects. The mechanism is useful after deallocation, when a returned block may adjoin free neighbors. A free list records the resulting regions; it can be implemented using a list or another search structure.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, §17.2, “Splitting and Coalescing”, printed pp.3–4
Using half-open address intervals, two free blocks and can become . Their usable bookkeeping lengths add: . For an original example, suppose free intervals occupy offsets and while the intervening16-byte block is live. Releasing that middle block makes all of free, so merging its two neighbors produces an80-byte block. An occupied8-byte block after offset80 still separates this region from a later free interval.
An address-aware insertion can check the predecessor's end against the new block's start and the successor's start against its end. When both are adjacent, all three join. An implementation may delay merging, but a search that examines only unmerged entries can miss a sufficiently large contiguous region. Coalescing policy and allocation search therefore affect observed success as well as the physical occupancy pattern.
These examples omit block headers and other allocator metadata. A real merge must maintain those structures, preserve memory alignment guarantees and avoid treating an occupied or separately managed region as free. Coalescing does not cure a hole separated from its neighbor by a still-live allocation; that requires deallocation, a different placement strategy or a valid memory compaction mechanism.
A free list records free memory regions or reusable allocation units so an allocator can find storage for a request. In a variable-size pool, a record typically needs a block's location and length. A linked implementation also stores a link to another free record; these records can occupy the free blocks themselves. The term can also describe the allocator's logical inventory when its search structure is more elaborate than one linked chain.[ref]
For an illustrative inventory of free extents of16,32 and48 bytes, a24-byte request cannot use the first extent but can use either later one, before metadata and alignment are counted. Choosing the32-byte extent leaves an8-byte remainder if split exactly. Whether that remainder can become a free-list entry depends on the minimum free-block size.
Suppose an explicitly hypothetical in-block free record needs an8-byte length field and an8-byte next-link field. Its16-byte metadata cannot fit in that8-byte remainder. The allocator can instead give the request the entire32-byte block, leaving8 bytes of internal fragmentation, or choose another layout or block. Metadata placement is therefore part of allocation capacity, rather than an afterthought.
When a block is returned, memory block coalescing can combine it with adjacent free neighbors and update the inventory. Address order can make adjacency checks convenient; other orderings can favor allocation searches. A list that contains enough total free bytes may still lack one sufficiently large extent, producing external memory fragmentation. The search policy, split rule, metadata layout and coalescing policy jointly determine which requests succeed.
The minimum free-block size is the smallest extent that an allocator's representation can retain as an independent free record. It depends on where the allocator stores a region's size, links and other metadata, as well as memory alignment. A region may contain unused bytes yet be too short to enter the free list. OSTEP demonstrates why allocator metadata must be counted: free records can be embedded inside the free regions themselves.[ref]
For a hypothetical allocator, let a free record need an8-byte size field and two8-byte links. Its raw metadata requires24 bytes. If all block lengths are multiples of16 bytes, its minimum independently representable size isThe exact fields and sizes are illustrative. An allocator with separate metadata, a singly linked record or another block granularity can have another minimum.
Suppose the same allocator uses an8-byte allocated-block header. An8-byte payload plus that header would occupy16 bytes before enforcing the minimum. Reserving32 bytes ensures that this block can later become an independent free record. Extra allocation space of this kind contributes to internal fragmentation. The allocator might instead use a distinct representation for tiny blocks, so the formula is a design constraint for the stated representation rather than a universal allocation rule.
A proposed split also needs to respect the minimum. Taking80 bytes from a96-byte extent leaves16 bytes, an unsplittable free-block remainder under this layout. Giving the caller the full96-byte extent avoids making an invalid free record but consumes extra storage. Taking32 bytes would leave64, which can be retained. Memory block coalescing can later join adjacent returned extents, but the allocator must have a valid way to represent each extent until that happens.
An unsplittable free-block remainder is the positive suffix left by a proposed allocation that is too small to retain as a valid independent free list record. Its size is below the allocator's minimum free-block size. The region still contains unused bytes, but the chosen representation cannot manage it as a separate free extent. The issue arises because free-region metadata can occupy the regions themselves.[ref]
Let a chosen block have size , let the proposed allocated extent after header/alignment rounding be , and let the minimum free size be . With remainder , an allocator that absorbs an undersized suffix usesThis is one possible policy, not a mandatory allocator interface. The absorbed suffix adds bytes of internal fragmentation beyond the bookkeeping and rounding already included in .
For an original example, take bytes, an8-byte allocated header,16-byte block granularity and bytes. A56-byte payload gives , leaving a representable32-byte free block. A57-byte payload instead gives , leaving an unusable16-byte suffix. Absorbing it reserves all96 bytes. Increasing the request by just one byte has therefore increased this allocation's occupied extent by32 bytes.
If and all extents are multiples of a granularity , a positive absorbed suffix is at most bytes. Without that granularity condition, the general integer-byte bound is . Choosing another free block or another representation can change the tradeoff. Later memory block coalescing can recover adjacent space when allocations are returned, but it does not make an invalid intermediate free record representable.
External memory fragmentation occurs when free capacity is divided among separated blocks so that a request for one sufficiently large contiguous block cannot be satisfied. It concerns the layout available to a particular allocator, rather than only the total free computer memory. In a fixed nonmoving pool, occupied blocks can separate free intervals that would have been useful if adjacent.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, “Free-Space Management”, introduction and §17.1, variable-size allocation and nonrelocatable live blocks
For an original example, a104-byte pool contains free blocks of24,40 and16 bytes, separated by occupied blocks of16 and8 bytes. Total free capacity is80 bytes, but the largest free memory block is only40 bytes. A contiguous48-byte request therefore fails in this closed pool, assuming live blocks cannot move and ignoring metadata/alignment overhead.
Memory block coalescing merges adjacent free intervals. If the occupied16-byte block between the first two holes is released, the neighboring24,16 and40-byte intervals can form one80-byte free block. Coalescing does not merge across a still-occupied interval. Memory compaction instead moves live data to collect free space, which requires a way to preserve or update references. An allocator generally cannot relocate an arbitrary live block behind an unchanged C programming language pointer.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. §17.1, relocation assumption; §17.2, splitting and coalescing
The illustrative measure equals0.5 for the original layout, but it does not say that half the memory is universally unusable: requests no larger than16 bytes can still fit. Actual allocation success depends on request sizes and allocator policy. Internal fragmentation instead concerns unused space inside allocated units.
The contiguity requirement also needs its address space specified. A virtually contiguous block can use noncontiguous physical page frames through virtual memory. Physical page fragmentation and an application's heap holes are therefore different allocation-layer questions. Changing the physical mapping alone does not merge separated virtual holes around live objects.
The largest free memory block is the longest contiguous free region available within a specified allocation pool and address space. If free-block lengths are ,For an empty free-block set, take . The largest block and total free capacity answer different questions: a contiguous request can fail even when exceeds its size. This is the central layout issue in external memory fragmentation.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17 introduction, fragmented free capacity versus one contiguous allocation; §17.2, adjacent-block merging
For free lengths24,40 and16 bytes, bytes and bytes. A48-byte contiguous request fails in that fixed, nonmoving pool before metadata and memory alignment are considered. Coalescing an additional freed separator can increase without requiring the allocator to obtain another region from the operating system.
Raw extent length can overstate payload capacity. For a block , an illustrative header requirement and payload alignment , choose aligned payload startThe aligned free-block capacity in this simple layout is . A32-byte block starting at0 with an8-byte header and16-byte payload alignment has and only16 bytes of payload capacity. A24-byte payload therefore fails despite a raw32-byte extent. Actual allocator layouts can impose further constraints.
The quantity also depends on the allocation layer. A large virtually contiguous block need not occupy contiguous physical page frames. Comparing values without specifying virtual versus physical space, allocator pool and usable payload convention can therefore mix distinct fragmentation problems.
Aligned free-block capacity is the usable payload that a particular free extent can supply after meeting memory alignment and metadata requirements. It differs from the raw extent length and from the largest free memory block. For an illustrative block , header requirement and payload alignment , the first permissible payload start isIf the allocator reserves no trailer or additional rounding, usable payload capacity is . This formula belongs to the stated layout; it is not a universal allocator ABI.
For a free interval in byte offsets, an8-byte header and16-byte alignment give . The raw64-byte extent then has51 bytes after the aligned start. Allocation alignment padding is bytes, in addition to the8-byte header. A48-byte payload fits this model, whereas a52-byte payload does not.
If allocated payload size must also be rounded to a multiple , a requested size needs usable bytes. For in the same example, the largest such payload is48 bytes: a49-byte request rounds to56 and fails. Header information and allocation granularity can therefore change the answer even when the alignment condition itself is satisfied.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, §17.2, allocation headers and total-region bookkeeping, printed pp.5–6
For integer addresses, the padding before the payload lies between0 and bytes. Splitting a chosen block can introduce another constraint: a leftover interval may be too small to hold a free record. A capacity calculation must consequently identify the actual header, alignment, rounding and remainder conventions rather than treating every raw free byte as payload.
Allocation alignment padding is the unused space inserted before an allocated payload so its address meets memory alignment. If a free extent starts at integer byte address , an allocation header consumes bytes, and payload addresses must be multiples of positive integer , the earliest permitted address and its padding areEquivalently, is the least nonnegative residue of modulo . The alignment padding bound is . Already aligned payload starts have zero padding; adding a whole extra alignment unit in that case would waste space unnecessarily.
For an original example, let a free extent be , with and . Then , and bytes. A24-byte payload ends at40, so the used prefix occupies37 bytes:8 for the header,5 for padding and24 for data. The remaining interval has27 bytes before other block-rounding or minimum free-block size requirements are applied. This accounting distinguishes padding from header storage and from payload-size rounding.
The same header and alignment can produce different padding at another address: gives and . If the residues of were uniformly distributed over all16 possibilities, the mean padding would be7.5 bytes, obtained by averaging0 through15. An actual allocator can constrain its block starts, so that distribution is an explicit model assumption rather than a measured universal overhead.
Aligned free-block capacity must deduct this padding when testing whether a request fits. Allocation alignment padding can thus make two equally long free extents offer different usable capacities. OSTEP's separation of the allocated payload from its bookkeeping header is the basic layout issue behind this calculation; alignment adds the stated address constraint.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, §17.2, “Tracking The Size Of Allocated Regions”, printed pp.5–6
The alignment padding bound limits the extra bytes needed to move an integer payload address to the next permitted memory alignment. Let be the first address after an allocated header, and let alignment require a multiple of a positive integer . Withthe exact bound is . It applies to the earliest aligned start, not to arbitrary extra space an allocator may choose to reserve.
To prove the bound, write . The ceiling function gives , hence . Since is an integer number of bytes, . The endpoints can occur: an already aligned gives zero padding, while one byte beyond an aligned address gives . This is also the statement that is the least nonnegative residue of in modular arithmetic.
For an original example, , header size and block start give , and . The worst-case bound is attained. Starting at instead gives and . Identical header and payload sizes can therefore incur different allocation alignment padding at different addresses.
A sufficient address-independent reservation for a payload of bytes is , before any trailer, block rounding or minimum free-block size constraint. For , and ,47 bytes suffice under precisely that layout. A known starting address can require less: needs5 bytes of padding and a37-byte used prefix. Separating the payload from its metadata is the bookkeeping principle illustrated in OSTEP; the bound adds a worst-case alignment allowance.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. Chapter17, §17.2, allocation header versus payload, printed pp.5–6
These inequalities concern mathematical integers. An implementation using bounded address arithmetic must separately prevent integer overflow when adding the header, padding allowance or payload. A wrapped sum cannot be justified by a correct bound over unbounded integers.
A bit field assigns a selected group of bits within a stored value to a particular component or meaning. For a contiguous field, specify its width , starting position counted from the least significant bit, and interpretation. In a pixel format, separate bit fields can hold red, green and blue component codes. The Linux frame-buffer interface describes such fields with explicit offset and length members.[ref]
The Frame Buffer Device API in the Linux Kernel documentation. Section4, fb_bitfield and non-overlapping component fields
For a nonnegative integer word , the unsigned value of the field isIn a language with the usual unsigned bitwise operations, this corresponds to shifting right by and applying bitwise AND with .
For an original eight-bit example, let , written
0xB5 or binary 10110101. Select three bits beginning at position 4, so the field consists of bits 6–4. Extraction givesThe field's bits are 011. To replace them by value 6, clear the field with mask 0x70, then insert 6 << 4. Restricted to eight-bit words, the calculation isThe other five bits are unchanged. The range specifies what fits in an unsigned field.A language-level bit-field declaration is a related abstraction, but its physical placement follows that language and implementation. In the C programming language,
unsigned int code : 3; declares a three-bit field; C11 leaves allocation order within a storage unit implementation-defined and the storage unit's alignment unspecified.[ref] Such a declaration alone therefore does not specify a portable external byte sequence. An explicit layout must also state the relevant endianness and storage rules.A framebuffer is computer memory holding an image's pixel values in a representation usable by graphics hardware or software. A pixel format specifies how stored bits encode those values. The image's dimensions alone do not determine its complete memory layout: rows can include padding, and different layouts can organize components differently.[ref]
The Frame Buffer Device API in the Linux Kernel documentation. §2, Types and visuals; related Frame Buffer Device introduction, §§0–1
For a concrete packed-row model, let the image be three pixels wide and two rows high, using four bytes per pixel. A row's actual pixel data occupies bytes. If each row starts 16 bytes after the previous one, the framebuffer stride is 16 bytes and four padding bytes separate consecutive pixel rows. Reserving two complete row slots takes bytes, although the pixel values themselves occupy only 24 bytes.
With zero-based coordinates, base memory address , stride and bytes per pixel, the start of a pixel in this stipulated layout isThus starts at . Replacing by the packed width12 would instead address the wrong location. This formula assumes packed, byte-addressable rows; it is not a formula for every possible pixel format.
The Linux interface makes the distinction explicit:
line_length reports row length in bytes, separately from resolution and bits_per_pixel. A program should use the layout supplied by the interface when interpreting a framebuffer, rather than infer it from the visible dimensions alone.[ref]The Frame Buffer Device API in the Linux Kernel documentation. §3, Screen information, fixed line_length and variable resolution/depth fields
A framebuffer stride is the memory address increment between the starts of consecutive image rows in a specified framebuffer layout. For a row-based packed pixel format, it is commonly measured in bytes. It includes any padding between rows, so the image width and pixel format alone do not determine it. The Linux frame-buffer interface reports this byte count as
fb_fix_screeninfo.line_length.[ref]The Frame Buffer Device API in the Linux Kernel documentation. Section2, FB_TYPE_PACKED_PIXELS and end-of-line padding; section3, line_length
Assume each pixel occupies complete bytes, rows advance by a positive stride , and coordinates are zero-based. With base address ,This formula describes the stated packed-row layout. Formats with a different organization need their own addressing rule.
For an original example, choose an image width , height and per pixel. The pixel data in each row occupies 15 bytes. If the chosen allocator aligns each row to a multiple of eight bytes, it usesThere is one padding byte per row slot. The last pixel, at , starts at and occupies offsets 44, 45 and 46. Three complete row slots occupy 48 bytes, whereas the span through the last pixel ends at exclusive offset47:The allocation rule and the bytes actually containing pixels are distinct parts of the layout.
A cropped view need not become tightly packed. Starting a three-pixel-wide crop at original coordinate gives new base . Its next row still begins at , although each cropped row contains only nine pixel bytes. Substituting nine for the stride would instead start that row at .
Query the actual layout supplied by the interface before traversing memory. In the documented Linux interface, a successful format change can also update
line_length, so the stride belongs to the selected layout rather than being an immutable consequence of visible width.[ref]The Frame Buffer Device API in the Linux Kernel documentation. Section4, format configuration and updated type, visual and line_length fields
Memory alignment restricts the memory addresses at which an object may begin. An alignment of bytes means that its starting byte address satisfies . For example, address satisfies eight-byte memory alignment, whereas address does not. Alignment is a constraint on location, rather than another name for an object's size.
In the C programming language, object types have alignment requirements;
_Alignof queries a type's requirement and _Alignas can request a supported stronger requirement. The actual values depend on the implementation. The C11 draft distinguishes fundamental from implementation-supported extended alignments and requires valid alignment values to be powers of two.[ref]An application binary interface makes such choices concrete. Under the ordinary AAPCS64 layout, a C structure containing a
char tag followed by a double value has the character at offset , seven unused padding bytes, and the double at offset . Its total size is bytes and its alignment is bytes. The application binary interface aligns an aggregate as strictly as its most strictly aligned member and rounds the aggregate size up to a multiple of that alignment; this also keeps each element properly aligned in an array of these structures.[ref]This example is an explicit platform convention, rather than a universal promise that every C
double needs eight-byte memory alignment. Likewise, a processor's ability to execute an unaligned load does not by itself relax the C programming language's object-access requirements. Keeping the language rule, the application binary interface layout, and the machine instruction separate explains why a byte buffer cannot automatically be treated as a properly located object of any chosen type.Non-volatile memory programmed and erased electrically. Its program and erase granularities need not match the block size exported to a file system.
An individually addressable place in computer memory holding a value. An abstract memory interface can separate reading and updating existing memory locations from allocating a fresh memory location.
Storage for pending writes, usually with their memory addresses, data and status. A younger load instruction must account for older overlapping buffered store instructions, often by store-to-load forwarding.
An age-ordered structure tracking store instructions, their memory addresses and data, and their eligibility to become visible. An implementation may distinguish a speculative store queue from the committed store buffer.
Satisfying a load instruction from an older pending store instruction rather than stale backing computer memory. The youngest applicable older write supplies each requested byte; unresolved or partial overlaps require additional handling.
A memory access whose execution is observable under the source language or machine rules, so that replacing repeated accesses by a saved value can change behavior. The precise guarantees depend on the programming language; volatile access alone does not provide thread synchronization.
A memory read through an address whose contents are fixed during ordinary operation. Used as a Boolean function lookup table, address bits select one of words, each holding output bits, so the logical table capacity is bits. A finite-state machine can store its next-state function in such a table while separate flip-flops store the current state.
The ordering of the bytes of a multi-byte value in addressed memory. Little-endian storage puts the least significant byte at the lowest address; big-endian storage puts the most significant byte there. Logical shifts of a value already held in a processor register act on bit significance, independently of that storage convention.
A pointer is a value designating a location in a program's memory model, or a special value such as a null pointer that designates no object. A node in a pointer-linked binary tree stores pointers to its two children. Representation, size, alignment and the validity of dereferencing depend on the programming language and target; 32-bit AAPCS32 data pointers occupy four bytes.
Following a chain of stored pointers, as in a linked list. A later memory address may depend on the result of an earlier load instruction, limiting how far ahead cache prefetching can run.
A null pointer is a distinguished pointer value that designates no object or function. Pointer-linked binary trees commonly use it to represent an absent child. Dereferencing it is invalid; its representation is target dependent, although AAPCS32 specifies an all-zero null representation.
A numerical identifier for a location in computer memory. In a byte-addressed system, consecutive four-byte array elements have memory addresses differing by four.
An assembly language memory operand whose effective address is the sum of a base processor register and an offset processor register. A byte-load table lookup uses the index directly as a byte offset; wider entries require an appropriate scale. The effective address is formed from the old register values before the destination register is overwritten.
Storage used for heap allocation, with software object lifetimes not necessarily nested like procedure calls on a call stack. Garbage collection can reclaim unreachable software objects; keeping references to every allocated software object prevents that reclamation regardless of how little of each software object's data a program still needs.
Heap allocation creates a software object whose lifetime need not match one lexical procedure call. Other software objects can retain references to it after the constructing call returns. Automatic storage reclamation therefore follows reachability or another memory-management discipline, rather than simply returning from that call.
Making storage available for reuse after its object is no longer accessible to any legitimate user. Concurrent readers retaining old pointers make safe memory reclamation a separate problem from atomic pointer publication.
A published reader protection record used by a protocol that validates the protected pointer and delays memory reclamation while relevant readers may access the object. Merely copying an unprotected pointer does not supply this lifetime guarantee.
A family of concurrent access techniques that publishes replacement versions and postpones memory reclamation until a suitable grace period has passed. Correct reader tracking, publication ordering and lifetime rules are essential.
An interval sufficient to establish that every reader that might retain a preexisting reference has left its protected read-side region. Completion permits the corresponding old object to undergo memory reclamation.
An access through a pointer after its storage has been released. Reusing the same memory address for a different object can make this failure silently return unrelated data instead of immediately crashing.
Automatic reclamation of allocated storage no longer reachable by a program. Clearing a private linked structure can discard its root references in constant pointer work even though later reclamation may require additional collector work. Data-structure operation bounds should state whether they count deferred memory-management costs.
A tracing garbage collection implementation starts from garbage collection roots and follows software object references. Software objects outside that reachable set can be reclaimed, including cycles that have no path from a root. A decorator or adapter holding a component reference keeps that component reachable while the wrapper remains reachable. The number of allocated software objects alone does not establish how much storage can be reclaimed.
A garbage collection root is an initially accessible reference from which the collector traces reachable software objects. Depending on the runtime, roots include active stack or register references and static references. Software objects reached transitively through reference fields must remain live. Exact root sets and collection timing are implementation details.
Tracking how many references retain an object. For the copy-on-write model, the object is a page frame and each mapping retains it; removing the last reference permits reclamation. Real operating-system kernels can track other kinds of ownership too. [ref]
An access to a location in computer memory, such as an instruction fetch, a read or a write. A page-level reference sequence records the corresponding memory page for each access, retaining repetitions and order.
A null reference denotes the absence of an ordinary referenced software object. In null-terminated linked lists it marks the end of a chain. A search can return it to signal absence, but the caller must check before selecting data members. Short-circuit evaluation can make a combined nonnull-and-property guard safe.
Two program references designate the same mutable object or overlapping mutable state. Binary-update contracts must account for this possibility: an update intended to combine two old values should snapshot both operands before modifying the receiver. A frame condition preserving a distinct operand cannot literally preserve a second reference that aliases the modified receiver.
A copy that duplicates the relevant reachable mutable structure instead of sharing all original references. A Memento pattern snapshot containing mutable arrays must preserve their saved contents against subsequent mutation, whether by a suitable deep copy or by an immutable persistent representation. The intended ownership graph and any permitted sharing must be specified; blindly copying one outer object is only a shallow copy.
The identity of a particular allocated object, distinct from equality of its current fields. Two different linked list nodes can store identical payloads, while two references can designate the same node. Pointer algorithms must state whether they preserve identities, copy payloads or allocate replacements. Testing cycle completion by identity avoids confusing two equal-looking nodes.
An ordered sequence of memory references, recording repetitions as well as addresses. The example under memory cache records twelve reads in decimal physical addresses; the trace itself does not determine cache hits until cache line size, capacity, initial contents, placement and replacement are specified.
An address in the physical address system, obtained from a virtual address by address translation in the examples here. Physical address ranges can also identify devices, so not every physical address denotes ordinary computer memory.
A unit of information; throughout these examples, one byte contains eight bits and is the smallest independently addressed unit of computer memory.
A store of selected information kept for faster reuse. A translation lookaside buffer is a memory cache of address translations; a buffer cache instead holds device-block contents.
For a data memory cache, the useful bargain is to keep a small selection of computer memory close to the CPU. A cache hit serves a read from that selection; a cache miss requires obtaining the contents elsewhere. Temporal locality helps a retained cache block serve repeated reads, and spatial locality helps one transferred cache line serve neighbouring bytes. Placement, capacity and LRU replacement determine whether that opportunity survives until the next read. [ref]
The worked memory access trace below uses twelve single-byte reads at these decimal physical addresses, in this fixed order:Assume an initially empty fully associative cache, 16-byte aligned cache blocks, and capacity two cache slots: 32 bytes of cached data, excluding metadata. Use exact LRU replacement, refreshing recency on every read, including cache hits. Every cache miss fetches its requested cache line completely before the next read; only a full memory cache needs an eviction. There are no writes, fetching ahead of requests, external invalidations, or overlapping reads. All addresses denote ordinary cacheable computer memory, and address translation is outside this model. These are deliberately synthetic assumptions, not specifications of a particular CPU.
This makes the outcome reproducible from the memory access trace, rather than from an informal impression that data are “nearby” or “recent”. The cache line geometry below identifies the requested unit; fully associative cache enumerates the resulting states; average memory access time translates the counts into a simple timing calculation.
Consistency requirements for cached copies of the same memory location, including agreement on its writes. Cache coherence does not itself impose sequential consistency across different locations.
Independent data in the same cache line cause unnecessary ownership transfers or invalidations when different CPU cores access them. A frequently written lock beside stable reader data can invalidate those data despite no logical conflict.
Loss of useful cached data because less useful data occupy the limited memory cache. Excessive cache prefetching can increase later demand cache misses by evicting useful cache lines.
A memory cache policy that sends a write miss onward without allocating the missed cache line in that level. Different levels of a cache hierarchy may use different write policies.
A memory cache policy that allocates the relevant cache line on a write cache miss. Fetching that cache line can delay a store instruction unless other mechanisms hide the delay.
Several levels of memory cache, typically combining a small low-latency first level with larger later levels. Each level reduces traffic reaching the next; local and global cache miss rates must be distinguished.
Fetching a cache line before a demand access requires it, to overlap transfer latency with useful work. A software prefetch is one way to request this; unnecessary requests can cause cache pollution.
A program-directed hint to fetch a cache line early. A useful nonblocking hint produces no destination processor register value and allows execution to continue before the transfer completes. Fault and dropping behavior depend on the specified instruction contract.
Caching retains selected information in a cache so later requests can reuse it. A cache hit finds the requested item there; a cache miss requires obtaining it elsewhere. A limited-capacity cache also needs a rule for deciding which items remain, such as LRU replacement.
For a two-entry cache initially empty, requests
A,B,A,C,A produce misses for the first A, B and C, and hits for the repeated A values under LRU replacement. Inserting C evicts B, since A was used more recently. This example has cache hit rate and cache miss rate . A different request order or replacement rule can change the result.The useful saving depends on both reuse and validity. A cached result that depends on changed data may need invalidation or recomputation; retaining it indefinitely does not preserve correctness. For main-memory paging, cache-management decisions trade page faults against finite storage, and average memory access time includes the extra cost of misses.[ref]
Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others. chapter 22, §22.1, cache management
A fixed-sized, aligned block of consecutive bytes transferred and tracked as a unit by a data memory cache. Here cache line and cache block name that unit of data, including its identity in backing computer memory; a resident slot holds a copy. Reading one element can bring neighbouring elements into the same cache line, exploiting spatial locality.
For a nonnegative integer physical address and a cache line size bytes, Euclidean division gives the backing cache block number and offset :Here the brackets denote the floor function and gives the remainder. Cache line contains bytes at physical addresses through . With , read address 52 selects cache block 3, spanning addresses 48–63, and offset 4. Addresses 48 and 52 therefore request the same cache line; addresses 15 and 16 request different cache lines despite being adjacent.
For a cache line size , the low bits give the offset. In a fully associative cache, all remaining bits identify the backing cache block as its cache tag; there are no address bits selecting a particular cache slot. An eight-bit illustration gives : four bits
0011 for cache block 3 and four bits 0100 for offset 4 in the binary numeral system. The eight-bit width is illustrative; the trace does not assume an actual eight-bit machine. [ref]Distinguish this identity from a cache slot, which can hold different cache blocks over time. After read nine in the memory cache example, cache slot 0 contains cache line 3 and cache slot 1 contains cache line 0. Their cache tags identify 3 and 0; neither cache line number is its slot number. Some texts use “cache line” for the storage entry itself; this article reserves cache slot for that role.
A resident storage entry that can hold one cache block and metadata identifying its contents. Cache line identity belongs to backing computer memory; cache slot identity belongs to the consulted memory cache.
Metadata identifying which eligible backing cache block a valid cache slot currently holds. In the fully associative cache example, the cache tag is the full cache block number ; in the two-slot direct-mapped cache example, the slot supplies and the cache tag can store using the floor function.
A request whose required data are already available in the consulted memory cache. In the read-only model of spatial locality, a requested cache block being resident is sufficient for a cache hit.
The memory access trace under memory cache has cache hits at reads 2, 4, 9, 10 and 12. Read 2, at address 4, benefits from the cache line fetched by read 1 at address 0; read 9, at address 52, benefits from read 8 at address 48. These reads use different bytes of the same cache blocks, illustrating spatial locality. Read 4 returns to address 0 while its cache block remains resident, illustrating temporal locality.
A cache hit still takes time to identify the matching cache tag and obtain the requested byte. It is relative to the particular memory cache consulted: a cache miss in one level may be a cache hit in another. The model here has one consulted level and treats a valid matching resident copy as sufficient; it makes no prediction about writes or accesses whose permissions or contents change.
The fraction of memory references yielding cache hits, with their count: . The two-slot fully associative cache example has . Count the same reference unit and consulted level for both cache hit rate and cache miss rate.
A request whose required data are unavailable in the consulted memory cache. The model in spatial locality fetches the requested cache block and evicts a resident cache line only when capacity is full.
In the fixed memory access trace under memory cache, reads 1, 3, 5 and 8 first request cache blocks 0, 2, 1 and 3: four compulsory misses, also called cold misses. Reads 6, 7 and 11 revisit cache blocks that LRU replacement has evicted: three capacity misses. Read 5 is a compulsory miss even though it also causes an eviction; a full memory cache alone does not determine the classification. The fully associative cache permits every cache block in every cache slot, so this example has no conflict misses.
For a precise comparison, run the same memory access trace through an initially empty direct-mapped cache with the same 16-byte cache lines and two cache slots, placing cache block only in slot . Read 3 brings in cache block 2 and displaces cache block 0, leaving the other cache slot unused. Read 4 consequently misses at address 0, whereas the fully associative cache still has cache block 0. That read is a conflict miss: increasing placement freedom at the same capacity removes it. The complete direct-mapped cache trace has eight cache misses: four compulsory misses, three capacity misses and one conflict miss.
The convention here classifies each cache miss by first asking whether its cache block has ever been requested. If so, compare with an initially empty fully associative cache of the same capacity and cache line size using LRU replacement on the same memory access trace: a miss there is a capacity miss, while a hit there identifies a conflict miss in the restricted design. This makes the comparison policy explicit; “capacity” is not a claim that no other replacement choice could save that individual read. The three categories describe this read-only demand model; external invalidations or fetching ahead of requests require additional reasoning. [ref]
The fraction of memory references yielding cache misses, with their count: . When each reference is classified as exactly one cache hit or cache miss, ; the two-slot fully associative cache example has .
A repeated cache block access that misses even in the comparison fully associative cache of the same capacity and cache line size using LRU replacement. In the memory cache example these are reads 6, 7 and 11. The replacement assumption matters to this classification.
A repeated cache block access that misses in a restricted design but hits in the comparison fully associative cache of the same capacity and cache line size using LRU replacement. Read 4 of the direct-mapped cache comparison under cache miss isolates this effect while another cache slot is unused.
The additional memory access latency charged for a cache miss beyond a common lookup time in the average memory access time model. It includes obtaining the requested cache block and making the read complete; this model excludes extra costs from writes and overlapping requests.
A cache miss on the first access to a cache block in an initially empty memory cache with no fetching ahead of requests. Larger capacity cannot eliminate these first fetches; subsequent cache misses can have other causes.
A memory cache allowing any cache block to occupy any resident slot. When full, its replacement policy chooses a victim from all resident cache lines. The examples in temporal locality and spatial locality use LRU replacement, so no additional placement restriction causes eviction.
The diagram enumerates every read of the fixed memory access trace under memory cache. Keep cache slots fixed: fill the lowest-numbered unused slot first, and subsequently reuse the victim's slot. Separately list recency from least recently used to most recently used. A cache hit refreshes that recency without moving the resident data to another cache slot.
Every read, cache hit or cache miss, eviction, cache slot and recency state of the synthetic two-slot fully associative cache with LRU replacement
. Details. After read 3, cache block 0 is older than cache block 2. Read 4 hits cache block 0, making cache block 2 older; read 5 must therefore evict cache block 2 to load cache block 1. Omitting recency updates on cache hits would choose the wrong victim. Read 6 immediately needs the evicted cache block 2, showing that LRU replacement uses past demand rather than knowledge of future demand.
With capacity four cache slots and the same cache line size, the same memory access trace has just its four compulsory misses and eight cache hits, since all four distinct cache blocks fit. Greater capacity helps this trace, but full associativity alone does not make LRU replacement optimal. Its attraction is freedom from placement restrictions; a hardware implementation must still identify a matching cache tag among eligible entries, and exact recency tracking adds work. [ref]
A memory cache in which each backing cache block has exactly one eligible cache slot. The example under cache miss maps cache block to slot : cache blocks 0 and 2 compete for slot 0 despite free space in slot 1.
The time from a memory reference's request until the requested data become available. Average memory access time averages this delay in the stated serial model; it does not directly measure whole-program runtime.
The arithmetic mean of memory access latencies. Suppose each read completes before the next begins, every cache hit costs , and every cache miss costs , with the same additional cache miss penalty . If is cache hit rate and is cache miss rate, the weighted arithmetic mean isThe common lookup cost is paid on both outcomes. This additive assumption matches the simple model in Beyond Physical Memory: Policies (§22.1, equation 22.1, pp. 1–2), where main computer memory acts as a memory cache for memory pages backed by disk; here the same accounting is applied to a toy data memory cache.
Assign synthetic values and . The twelve-read, two-slot fully associative cache example has five cache hits and seven cache misses, givingWith four cache slots, its four compulsory misses instead give . This comparison holds the timing costs fixed as capacity changes, which is a model assumption rather than a hardware promise.
If a problem supplies a total miss time , use ; adding to again would count lookup twice. Variable cache miss penalties, multiple consulted levels, or overlapping requests require a richer timing model. Real CPU work can overlap a pending read, so this arithmetic mean cannot by itself predict program speed or stall time. [ref]
Articles by others on the same topic
There are currently no matching articles.


