Storage basic - how data stored?

Storage basic - how data stored?. This is very important topic if you in storage domain, Why? this is the bare bone concept of storage and crucial to learn.

INTERVIEW QUESTION

Luminari

8/14/20243 min read

In today's digital age, we rely heavily on storage devices like hard drives and solid-state drives (SSDs) to store our personal files, photos, videos, and applications. But have you ever wondered how data is actually stored on these disks?In this blog post, we'll delve into the world of disk storage and explore the fascinating process of how data is written and stored on a hard drive or SSD.

What is Disk Storage?

Disk storage refers to the method by which computers store data in non-volatile memory. Unlike RAM (Random Access Memory), which loses its contents when the power is turned off, disks retain their data even after the computer is shut down. Disks come in various forms, including hard disk drives (HDDs), solid-state drives (SSDs), and flash drives.

The Anatomy of a Disk

A typical disk consists of several key components:

1. Platters: These are the circular disks made of magnetic material that store data. In an HDD, there are one or more platters coated with a thin layer of magnetizable material.

2. Heads: Also known as read/write heads, these tiny mechanical arms float above the platters and read/write data from/to them.

3. Actuator: This is a mechanical system that moves the heads to specific locations on the platter.

4. Controller: The brain of the disk, responsible for managing data access, error correction, and other functions.

SSD Storage

In contrast to traditional HDDs, SSDs store data in flash memory chips:

1. Flash Memory Cells: These are the primary storage units on an SSD.

2. Controllers: Manage data access, garbage collection (cleaning up deleted files), and wear leveling (spreading writes across multiple cells).

3. Storage Process: The process is similar to HDDs, but with the added complexity of flash memory management.

The Disk Storage Process

When you save a file to your computer's hard drive, it undergoes several stages before being written onto the disk. Here's a step-by-step explanation:

1. File System: The operating system (OS) uses a file system, such as NTFS or HFS+, to manage the files and directories on the disk. The file system is responsible for allocating space, tracking metadata, and maintaining the structure

of the disk.

2. Block Allocation: When you save a file, the OS breaks it down into smaller blocks, typically 4KB or 8KB in size. These blocks are then allocated to specific locations on the disk using a technique called contiguous allocation.

3. Cluster Allocation: The disk is divided into clusters, which are groups of adjacent blocks that can be written together. The cluster allocation algorithm determines which cluster(s) will store the file's data.

4. Data Writing: Once the block and cluster allocation have been determined, the OS writes the file's data to the allocated location on the disk. This involves converting the digital data into a series of magnetic charges (for HDDs) or

electrical charges (for SSDs).

5. Metadata Creation: As the data is written to the disk, metadata is created to track the file's attributes, such as its name, size, creation date, and permissions.

The Role of Fragmentation

Fragmentation occurs when a file's data is scattered across multiple locations on the disk due to the way files are allocated and deallocated. This can lead to

1. Wasted Space: As files grow or shrink, they may leave behind unused space, which can become fragmented.

2. Slower Performance: When files are fragmented, it takes longer for the OS to locate and read their data, leading to slower performance.

3. Increased Disk Wear: Fragmentation can cause the disk head (for HDDs) or memory cells (for SSDs) to access multiple locations more frequently, increasing wear and tear.

Data Table Maintenance Process

To maintain efficient storage and prevent fragmentation, disks employ various mechanisms:

1. Cluster Checkpointing: The OS periodically checks for fragmented clusters and reorganizes them to contiguous blocks.

2. File System Defragmentation: Some file systems, like NTFS, offer built-in defragmentation tools to reorganize files and reduce fragmentation.

3. Garbage Collection: SSDs use garbage collection algorithms to periodically erase and reuse empty memory cells.

4. Trim Command: Modern SSDs support the TRIM command, which allows the OS to inform the SSD about blocks that are no longer in use.

Data Table Maintenance: How it Works

When a file is written or modified on a disk, the data table (also known as the File Allocation Table or FAT) is updated accordingly. Here's how:

1. Entry Creation: A new entry is created in the data table to represent the file.

2. Block Mapping: The data table maps each block of the file to its corresponding location on the disk.

3. Cluster Mapping: If the file spans multiple clusters, the data table maps these clusters as well.

The data table maintenance process involves periodically verifying and updating this mapping information to ensure accurate storage and retrieval of files.

Preparing for interview?