ArticleslgStudy

computer science

Fragmentation (computing)

Fragmentation (computing) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Fragmentation (computing) rather than just read about it. In short: In computer storage, fragmentation is a phenomenon in the computer system which involves the distribution of data into smaller pieces so that storage space, such as computer memory or a hard drive, is used inefficiently, reducing capacity or performance and often both. The exact consequences of fragmentation depend on the specific system of storage allocation in use and the particular form of fragmentation.

Fragmentation (computing) — main illustration
Fragmentation (computing) — illustration

Key takeaways

  • Fragmentation (computing) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Fragmentation (computing) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Fragmentation (computing) from memory before moving on to harder problems.

Reference excerpt

In computer storage, fragmentation is a phenomenon in the computer system which involves the distribution of data into smaller pieces so that storage space, such as computer memory or a hard drive, is used inefficiently, reducing capacity or performance and often both. The exact consequences of fragmentation depend on the specific system of storage allocation in use and the particular form of fragmentation. In many cases, fragmentation leads to storage space being "wasted", and programs will tend to run inefficiently due to the shortage of memory.

Basic principle In main memory fragmentation, when a computer program requests blocks of memory from the computer system, the blocks are allocated in chunks. When the computer program is finished with a chunk, it can free it back to the system, making it available to later be allocated again to another or the same program. The size and the amount of time a chunk is held by a program vary. During its lifespan, a computer program can request and free many chunks of memory. Fragmentation can occur when a block of memory is requested by a program and is allocated to that program, but the program has not freed (uncommitted) it. This leads to theoretically "available", unused memory being marked as allocated - which reduces the amount of globally available memory, making it harder for programs to request and access memory. When a program is started, the free memory areas are long and contiguous. Over time and with use, the long contiguous regions become fragmented into smaller and smaller contiguous areas. Eventually, it may become impossible for the program to obtain large contiguous chunks of memory.

Types Fragmentation occurs whenever a piece of data or free space is broken into several pieces. Fragmentation is often accepted in return for improvements in speed or simplicity. Analogous phenomena occur for other resources such as processors; see below.

Memory Memory fragmentation can be internal and external. Internal fragmentation occurs when memory allocation provides more space than needed, causing waste of free space. External fragmentation occurs when free memory is fragmented, preventing newer, larger blocks from being allocated. In modern operating systems, the program receives fixed-size pages which it then allocates among different parts of itself (often by an allocator such as malloc). As a result, there are two layers of allocation that may each result in their own internal and external fragmentation: on the level of the memory allocator (e.g. malloc) and on the level of pages. (Older operating systems might not use pages, but programs still tend to use a two-level system to avoid excessive calls to the OS.)

Internal fragmentation

Due to the rules governing memory allocation, more computer memory is sometimes allocated than is needed. When this happens, the excess memory goes to waste. In this scenario, the unusable memory, known as slack space, is contained within an allocated region. This arrangement, termed fixed partitions, suffers from inefficient memory use - any process, no matter how small, occupies an entire partition. This waste is called internal fragmentation.

Memory paging creates internal fragmentation because an entire page frame (typically 4–64 KiB) will be allocated whether or not that much storage is needed. malloc and similar allocators tend to provide a degree of alignment, so that memory can only be provided to programs in chunks (usually a multiple of 4 bytes). As a result if a program requests perhaps 29 bytes, it will actually get a chunk of 32 bytes. Internal fragmentation on the allocator level is very difficult to reclaim after it has occurred; usually the best way to remove it is with a design change. For example, in dynamic memory allocation, memory pools drastically cut internal fragmentation by spreading the space overhead over a larger number of objects. Internal fragmentation on the page level (which is external fragmentation on the allocator level) can be reclaimed by moving allocated blocks. This requires editing pointers to reflect the moving of allocated blocks, which is difficult for non-garbage-collected languages. Compacting garbage collectors perform pointer fixups as it compacts the virtual address space.

External fragmentation External fragmentation arises when free memory is separated into small blocks and is interspersed by allocated memory. It is a weakness of certain storage allocation algorithms when they fail to order memory used by programs efficiently. The result is that, although free storage is available, it is effectively unusable because it is divided into pieces that are too small individually to satisfy the demands of the application. The term "external" refers to the fact that the unusable storage is outside the allocated regions. For example, consider a situation wherein a program allocates three continuous blocks of memory and then frees the middle block. The memory allocator can use this free block of memory for future allocations. However, it cannot use this block if the memory to be allocated is larger in size than this free block.

External fragmentation on the page level can be reclaimed by an application's own allocator or garbage collector as it frees up and hands back (uncommits) pages to the OS. External fragmentation on the page level can also be reclaimed by the operating system by moving pages in the physical address space and editing the page table to match. This is called page migration. The application is oblivious to the process because the virtual memory addresses remain unchanged.

File systems

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Fragmentation (computing)

Start with the simplest possible case. Write down what Fragmentation (computing) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Fragmentation (computing) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Fragmentation (computing) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Fragmentation (computing)

In research
Fragmentation (computing) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Fragmentation (computing) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Fragmentation (computing) is common in secondary-school and first-year university syllabi. It links to neighbouring topics File system management, Memory management, so understanding it makes those chapters shorter.
In everyday life
Look for Fragmentation (computing) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Fragmentation (computing)” →

How to study Fragmentation (computing) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Fragmentation (computing) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Fragmentation (computing) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Fragmentation (computing) in simple terms?

In computer storage, fragmentation is a phenomenon in the computer system which involves the distribution of data into smaller pieces so that storage space, such as computer memory or a hard drive, is used inefficiently, reducing capacity or performance and often both. The exact consequences of fra…

Why does Fragmentation (computing) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Fragmentation (computing)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Fragmentation (computing).

Tags

  • File system management
  • Memory management

Keep exploring