Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Another way to ask this would be:

"why Hard Drives, Pen Drives and SSD need a partition scheme and the RAM doesn't?"

Just trying to understand better how all memory thingies work.

share|improve this question
    
Most pendrives don’t actually have a partition scheme. They have a single FAT/FAT32/exFAT filesystem spanning the whole disk. –  kinokijuf Feb 25 '12 at 14:25
    
@kinokijuf that really has nothing to do with my question and, in the way I meant it, having a single filesystem is a partition scheme. –  Cawas Feb 26 '12 at 3:55
    
Except it does not have any partitions. The filesystem starts at sector 0 instead of the MBR. –  kinokijuf Feb 26 '12 at 10:18
    
@kinokijuf so you're telling me partitions, per definition, need to have a kind of boot record? that's also not what I meant, but then it would validate more your comment. :) –  Cawas Feb 27 '12 at 1:12
1  
Yup. Your HDD has the MBR in sector 0 and partition starting in sector 63. Pendrives have the FAT32 header in sector 0 instead of the MBR and partition table. Which means it is not possible to have more partitions on pendrive, at least under Windows. –  kinokijuf Feb 27 '12 at 12:32
add comment

4 Answers

up vote 19 down vote accepted

Well, the problem is a bit more complicated.

First, the assumption expressed in the question is false. Hard disks and flash memories do not actually need partitions at all! You can simply write raw data on a hard disk and then read it back and it will work fine. Some relatively simple computer systems aren't using partitions even today, because there's no need to use them. For example I have right here right now on my desk a computer which is based on ATmega 162 microcontroller and it uses flash fine with no partitions.

Basically, what partitions do is enable separation of labor responsibilities among system designers. On my 162, I need to know where each bit of data is stored and how many times is each flash cell accessed, so I can implement wear leveling. To do that, I don't even need files. The problem however is that my miniature computer has only 16 KiB of flash and that amount can be managed by hand and source code comments. It's like having a desk with a single drawer. I can put anything there and it will be easy to reach and access.

On a large computer system, such as today's desktop computers, software is a product of work of thousands of programmers working separately. They need to have some way of storing data and that's why we need files and partitions. When we have them, programmer can focus only on data he needs to work with and doesn't need to worry about damaging other data. He can let programmers working on filesystem programming worry about physical storage of data. To continue my drawer example, that's like having a system of warehouses and trying to find one single item if you have hundreds of thousands of items in stock. So while you could just reach into the simple drawer and get a pencil for example, in warehouse case, the pencil would be in warehouse 3, section P, shelf 273, level 3, box 5.

I hope I made it clearer why we use partitions even if we actually don't need them.

Now to move to RAM. It's also untrue that there are no partitions in RAM. The basic reason why we use partitions is organization and RAM is organized too. In RAM's case, however, it's system's kernel which decides where each bit of information is going to go and it keeps track of space usage.

Let's compare how a program on my simple ATmega 162 works and how a program on a modern operating system like Windows works. On 162, program is preprogrammed with addresses of memory locations which it is going to use to store data. Since 162 only has one program, I don't need to worry about overwriting data used by another program or about allocation of memory. I can just write whatever I want into each memory cell and it will remain there while the computer is running.

On the other hand, on Windows we can have large number of programs running at the same time and all of them would be writing and reading data into and from the memory. That is we we can't allow individual programs to directly access memory cells (and the fact that the programmer would have to know how to access memory on that particular computer and how much RAM that computer has and so on. At this point we get back to thousands vs. one programmer discussion.). Instead, when each program starts, kernel allocates memory for it and to the program, it looks as if it's the only program running on the computer. Kernel is there to make sure that our program doesn't try to read or write memory given out to other programs and that it doesn't try to execute memory marked as data and that it doesn't bring entire system into danger. So basically on Windows and many many other modern operating systems each program gets its own partition of RAM. It's also interesting o note that on 32bit systems, each program could take only up to 2 GiB of RAM, because that was the upper limit of the "partition"'s size.

I'd like to make a small digression here. There are some programs which are hurt by partitions in RAM. For example, there were programs called trainers which would allow cheating in computer games. They worked by finding memory location where game stores its data on for example number of lives or health and then they would directly access the data and change it. On the other hand we also had viruses which worked by trying to access memory used by important system services and corrupting it to enable them to do their nefarious deeds.

Another thing worth brining up is pagefile or swap partition. To a programmer writing an application, it's not important if the program is in pagefile or if it is in RAM, because kernel takes care of that. On my ATmega 162, situation is a bit more complicated. When I need to use more RAM than it is available, I must first detect by hand situation when I have used up all RAM, after that I need to manually copy data from RAM to flash, free up the RAM, use it for whatever I need to use it for, free it up again, move data from flash to RAM and then free up taken space in flash memory. On a desktop computer, program can't even see if it has been swapped onto disk and then moved back into RAM.

One more interesting thing is performance. Let's go back to the drawer and warehouse example. Let's take all items from our warehouses and dump them at one pile. So if we need to take one pencil from the drawer, we'll just open the drawer and take the pencil. If we need to take one particular pencil from a pile of thousands of other pencils, notebooks, rulers, candy bars, erasers and what not, we'll have to spend considerable time searching for it. That time (in average case) is much longer compared to time needed to find the same pencil in a well organized warehouse. On the other hand the time needed to find pencil in an organized warehouse is much longer than time needed to find pencil in a drawer. So some methods work well on small amounts of data and some work well on large amounts of data. Filesystems improve performance by storing data in a logical way on the disk in which each individual datum can be easily found. Some filesystems also provide other benefits. In case of JFFS2, a filesystem designed for flash memories, filesystem implements wear leveling so that user or hardware designed don't have to.

Yet another interesting thing is that we can use standard filesystems for RAM too! There are programs which will take up RAM and organize it just like a filesystem and allow programs to use it as if it was disk space.

Some interesting links: Wikipeda Memory management article describes how and why is data in RAM partitioned. Operating system article, memory secction explains why we need things like memory segmentation, virtual memory paging and so on.

share|improve this answer
    
I can only say: "Holy crap!" you could totally give no links in this. –  Cawas Mar 9 '11 at 3:41
    
@Cawas What is so strange in this post? –  AndrejaKo Mar 9 '11 at 3:42
1  
Other than being huge, it's very well explained. I was just trying to pay a compliment. –  Cawas Mar 9 '11 at 4:09
    
@Cawas Oh. OK. Thanks! –  AndrejaKo Mar 9 '11 at 4:15
1  
Commenting "Some relatively simple computer systems aren't using partitions even today, because there's no need to use them." and "They need to have some way of storing data and that's why we need files and partitions." Actually, there are also complex computer systems that aren't using partitions either. Multiple file systems do not require multiple partitions, as demonstrated by ZFS. –  jlliagre Mar 9 '11 at 16:56
add comment

To grossly oversimplify, RAM does have a layout scheme but it's abstracted away by the hardware.

Internally, RAM is arranged as a matrix of "memory cells" laid out in rows and columns, like a spreadsheet. Each memory cell is used to store a bit of data, which can be instantaneously retrieved by indicating the row and column location (or address) of the data.

This isn't much different from the basic concept of how long term storage works, the file system and partition maps are simply an abstraction to prevent you from having to directly access the raw disk.

share|improve this answer
    
so, partition schemes are attempts to make hard disks faster and RAM doesn't need them? as you can see, gross oversimplication is fine here! :) –  Cawas Mar 9 '11 at 1:49
2  
partition schemes don't really affect drive speed all that much, it is not their purpose. Partition schemes are more like a map layout on the drive for how the operating system will write and read data to the disk, and this can change based on the file system used. In the case of RAM, data is allocated based off of a built-in structure as indicated above, rows and columns, and retrieved the same way. So more simply put, RAM has the structure built in to the hardware and permanent storage devices acquire the structure based off the the file system they are formatted in. –  MaQleod Mar 9 '11 at 2:07
    
@MaQleod cool! and why don't the hard drives do it hardware wise as well? –  Cawas Mar 9 '11 at 2:23
1  
Hard drives need to change. You can have multiple partitions all formatted differently on a single hard drive, or you may have one partition. That needs to be able to change so it cannot have a built-in structure like RAM does. There is a built-in structure to hard disk drives, but that structure is what the partition scheme maps. –  MaQleod Mar 9 '11 at 2:32
1  
To add to MaQleod's comment, whenever we have something set in hardware, it causes problems later. For example let's take a look at master boot record. It's size is 512 bytes and it contains partition data. Back when it was agreed upon as a standard, everyone thought that 4 partitions would be enough for everyone, so you can't have more than 4 primary partitions and when that became too small, bad workarounds had to be invented. It also limits hard drive size to 2 TiB, a size which HDDs have already reached. –  AndrejaKo Mar 9 '11 at 2:49
add comment

A partitioning scheme was created for hard drives so that you can install multiple incompatible operating systems that can coexist on different parts of the same platter. Pen drives and SSD drives inherit the scheme from the hard drive, their older cousin.

For personal computers usually RAM is only used by one operating system at a time and thus there is no partitioning scheme for it. But even so in some large computers (mainframes), there is also a partitioning scheme for RAM.

share|improve this answer
    
w00t, so there IS a partitioning scheme for RAM... well, I still don't understand why they would need it. what makes those storage devices need a partition? are you sure it was created just so we can install multiple operating system? couldn't we install an OS without it, ever? I mean, it does seem to me like an unnecessary layer of complexity in the middle. –  Cawas Mar 9 '11 at 2:27
    
@Cawas yes, IBM call it LPAR - en.wikipedia.org/wiki/… –  adib Apr 26 '11 at 5:52
add comment

RAM doesn't need partitioning because it is organized in pages and these pages are dynamically (MMU) structured without the need of preallocating areas. However, there is some kind of ephemeral partitioning happening with RAM when hardware components, mostly some graphic cards but it can be anything, reserve a part of physical RAM before the OS boots.

Actually, hard-drives, pen-drives or SSDs do not really need a partition scheme either, or at least, they shouldn't. There are still unavoidable components like the BIOS (or equivalent firmwares) and boot loaders that demand a partition table to be there to properly work but otherwise partitions are only required because of operating systems (more precisely file systems and volume manager) design limitations.

The ZFS pool concept demonstrated partitions aren't required even if you want to boot multiple operating systems and if these OSes require multiple volumes and file systems.

Partitions are then only required if the drives are used by one or more OSes than do not support ZFS (or an hypothetical equivalent).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.