CuriouSTEM

View Original

Memory Fragmentation

There are so many programs to run and there is so little memory. People don’t often think about memory management because the operating system handles it. However, memory management is an old and multifaceted problem to tackle. There are different types of memory, but RAM is the current focus.

RAM is the main memory and the main memory is where all the programs are executed. RAM is limited and expensive. More often than not, multiple programs are running for different amounts of time, and use different amounts of memory. It is difficult to calculate where, when, and how much memory to allocate each program, even with the operating system’s help. When programs and files are modified, opened, and closed, memory availability also changes. It would make sense if the entire program must go in a single block of memory. However, if we wait for a continuous amount of memory for a certain program, then random bits of memory are idle for an indefinite amount of time. To maximize the use of memory, programs are broken down into chunks and moved into a slot of memory that is available. With all the constant changes, the chunks can become very small and scattered. This is called fragmentation. Efficient use of RAM comes at a cost. That cost is more overhead time.

To better understand overhead, imagine your best friends are siblings and you need to see every day. They live next door. Travel time is minimal. However, their parents get a divorce. One friend moves across town. The other moves to another part of town. You still need to see them daily. But it takes significantly more time to get to their homes. Additionally, there is now more than one location to visit. If you forgot something from your own home for best friend things, then it would take much longer to get it and come back than it would if they lived together and next door. Programs that are divided into different memory locations are the same. Computers process things faster than people, but all this jumping around in memory will cause the program to slow down by a lot.

The solution is defragmentation (defrag)! Many systems defrag memory automatically, but it is a good idea to watch your files and take action when you see fit. There are internal and external tools to defrag memory manually. Learning to use these tools is a good maintenance practice, and it allows you to become familiar with your files and how memory is used.

Picture Source: researchgate.net