Continuous reinvention: Volumes that fit

• 2936 words

Many builders who have provisioned storage have sized a volume for expected growth, and then paid for empty gigabytes while waiting for that growth to arrive. Ask whether you can shrink the volume later, and the answer has been that you’d probably lose data, because the block device has no idea which blocks the filesystem still uses.

In this follow-up post to Continuous reinvention: A brief history of block storage at AWS, Marc Olson explains how the question “Can you help me reduce the cost of storage?” led to Amazon EBS Adaptive Volumes, which we launched at re:Invent a few days ago.

The pieces came from a decade of systems built for entirely different reasons, and it took stepping back to see what they made possible. I hope you enjoy reading this as much as I did.

–W


Continuous reinvention: Volumes that fit

Software systems are funny. You can spend a bunch of time building a thing, and then a whole lot more time fixing all of the problems. Sometimes these problems are due to poor design, but more likely, if your system is successful, the choices you made before are simply no longer valid as you increase the scale by an order (or more) of magnitude. As you grow you change some components and you may create new ones, and sometimes what you build creates options you didn’t plan for.

When I joined EBS in 2011, EBS already had nearly 60PB of storage worldwide–at least one order of magnitude beyond its initial launch footprint. Today I estimate that we add that in about a week, and EBS is used as primary storage by customers in nearly every industry on Earth. Along the way we’ve crossed a few scaling boundaries that have led us to build new systems and technology to ensure the reliable delivery of over 313 trillion I/O operations and 52EB of data to customer applications every day.

Our customers are constantly challenging us to improve performance, durability, and storage economics, all while demanding higher scale to support their growing workloads. This constant push is one of the things that keeps me excited about the things we’re working on.

Over the past couple of years, the question I get most frequently is: “Hey Marc, when can I shrink my volume?” It’s at this point where I have to break the bad news. Filesystems are living things. Files are added and deleted leaving holes behind. That video or document that looks like it’s all in one place may actually be broken up into multiple pieces, depending on where there is available space. When a document is added to, there may not be space next to where it was. Sometimes the filesystem may allocate some extra space near a file just in case it grows. Other times, especially as the disk is filling up, it has to put pieces anywhere and everywhere. All this leads to a very scattered disk that likely has data at the very end of it. To top it all off, the block device has no idea which blocks are still live.

Blocks

“If I shrink your volume, you’ll probably lose data” is the sad finale to my explanation. We all leave the room understanding the challenge, but there’s also this nagging question: Couldn’t we do something? The answer turned out to be EBS Adaptive Volumes. But we didn’t set out to build it. It came out of a decade of systems we built for entirely different reasons.

The building blocks we didn’t plan

One of the things that I love about AWS is that we listen to what our customers ask for and try to understand the question behind the question and build what they really want. Along the way these discussions have led us to rethink the way we have designed or operated our service, and usually result in a bit of new technology. Let’s take a look at a few systems that we’ve built in response to customer feedback.

Early in EBS’s life we had a single database per region that stored all information about every volume. Physalia went the opposite direction and instead created a database for every single volume. We built Physalia because we were hitting scaling limits that impacted availability for our customers, and having this system has become a central piece to making EBS a service that our customers trust.

Similarly, customer workloads demanded an increasing amount of storage per volume, but at the time EBS volumes were wholly contained on a pair of servers. The largest EBS volume size we allowed occupied more than 10% of a single server! The more of a server a volume occupies, the longer it takes to repair that volume in the event of a node failure (MTTR), and the longer the surviving copy is the only copy. A simple Markov model demonstrates that a longer MTTR directly lowers the mean time to data loss (MTTDL). To bring MTTR down, we split volumes into partitions across multiple storage servers.

MTTR

As a very simple example, if a 100 GiB volume is mirrored across two servers and server A fails, the remaining server (B) must transfer 100 GiB of data to a new server (C) before B fails. If we split that same volume into two partitions, each on its own pair, a single failure now only requires copying 50 GiB of data. That helps, but the real win comes at availability zone scale. Spread thousands of volume partitions across thousands of servers with randomly selected peers. Now when a server holding 10 TiB of volume data fails, it’s not just one server copying 10 TiB. There are a hundred peers each able to copy 100 GiB or less, all at the same time, to a hundred new destinations. Repair time is now set by the size of the partition, not the size of the volume, allowing us to offer larger volumes without trading away durability. Tracking the state of all of these partitions would have been difficult with a single monolithic database, but with Physalia it was trivial to have a cell that tracked all partitions of a volume.

Customers want to maximize the amount of data they can transfer or the number of transactions their database can do. We took a hard look at latency. What started as availability zones with a small number of data centers is now a world where we have 10s of data centers in an availability zone. These data centers may be a few kilometers apart, and physics limits how fast we can get data between them–approximately 10µs per kilometer round-trip time, not including the latency of switch gear. We built a placement system that chooses the best location for your volume based on where its instance is, while keeping the fleet’s heat (how busy each server is) balanced. Placement isn’t just a static system. It constantly moves data as workloads shift or a volume is attached to a different instance, always looking for a better spot for your volume.

A few years ago we began to rethink how we stored data. We knew that our then-current storage format was becoming more inefficient and unable to take advantage of the performance of newer and faster SSDs that were available. We took a look at our entire data plane, and applied our decade of operational learning in an environment where nothing was off the table. This led to our Block Express architecture, where we are able to lower not just the p50 and average latency of IO, but also improve the tail latency to provide a much more consistent experience. We built an entirely new data format and indirection layer within EBS storage servers. We launched this with io2 volumes, and over the past few years have migrated every volume onto the new architecture.

All of these things solved a specific customer pain point, and then we moved on to the next one.

Reflecting on our architecture

Every once in a while you have to step back and look at what you’ve built, not to admire it and congratulate yourself, but to look for new opportunities that you may not have realized you created along the way. When we did that, we realized that we had built many of the building blocks that would allow us to change the way that our builders and customers consumed storage. We now had an answer to the question behind “when can I shrink my volume?” The real question was, “how can you help me reduce the cost of storage?”

Our partitioning strategy could be adapted to compose volumes out of smaller extents of physical media. Physalia already tracked every partition of a volume and tracking more extents was trivial. Placement already decided where data should live and moved it around as demand shifted, which is exactly what you need when a volume’s footprint keeps changing. And the indirection layer that we built with Block Express decoupled logical volume addresses from physical storage, so an unwritten address needs no media. Together these systems made it possible to create Adaptive Volumes, a new volume type that charges by the bytes you’ve written rather than the size you provisioned, so you no longer have to right-size your volumes.

But there was a problem. EBS sees every write, but it has no idea what that data means to your application and filesystem. Those deleted files still look real to us. Fortunately, SSDs had already solved this problem.

SSDs are very complex devices. Their firmware manages raw NAND, which has an awkward property. You can write (program) individual pages, but you can only erase whole blocks of hundreds of pages at a time, and each block only survives a limited number of program/erase cycles. Under the covers SSDs never write in place. When you write to an address, even one your operating system thinks it’s overwriting, the firmware writes to a fresh page, updates its mapping table, and marks the old page as stale. Eventually a garbage collector picks a block with a lot of stale pages, copies the remaining active pages somewhere else, erases the block, and returns it to the free list. As the drive fills up, the free list shrinks, and the firmware has to work harder to find a place to write. If the operating system could tell the device which addresses no longer mattered, the garbage collector could skip copying them, and not do extra work. This is what is often referred to as TRIM, but it also goes by other names: UNMAP in SCSI, Deallocate in NVMe, and discard in Linux.

How a delete becomes a TRIM

To understand how this all works, let’s start at the top of the stack when you delete a file. The filesystem, itself an indirection layer, will mark those blocks as free in its bookkeeping data structures. What happens next depends on the filesystem and the configuration options. The filesystem can choose to immediately issue the TRIM command, it may batch it up for later during a less busy time, or there may be some asynchronous process (such as fstrim on Linux) that triggers the filesystem to issue the TRIM commands to the block device. These options trade off how quickly space is reclaimed and performance. The more work the device has to do processing TRIM, the less time it can spend doing other useful work. It’s also more efficient for devices to process larger contiguous segments.

A TRIM is effectively a write, which means that ordering matters. If a TRIM and a write to the same address are reordered, a device could throw away data that was written after the TRIM. Filesystems are careful about the order in which they issue these commands, and the device must preserve this ordering. Erasing a block in an SSD is slow, so TRIM also doesn’t erase anything right away. The SSD just updates the mapping table, and the slow erase happens later during garbage collection.

There are a couple of different options for what a storage device returns for a READ after a TRIM command, but the most important property is that the data that is returned is consistent, so reading the same address twice returns the same thing. The most common is that a device will return zeroes, but a device can also return the data that was previously there (which can happen if a TRIM is below the device’s granularity), and some devices, like EBS, will return pseudorandom noise, often the result of decrypting a fixed value like zero.

How it applies to EBS

There’s a nice symmetry here. The SSD solved its problem with an indirection layer that creates a mapping from logical addresses to physical pages and lets the device commit media only when something is actually written. That’s exactly what we ended up building, just spread across many storage servers instead of one controller. TRIM is how the filesystem and the device share information, and it works the same way whether the device is a flash chip or a distributed system.

Like an SSD, when a write lands on an address with no media behind it, Block Express allocates a new extent. Unlike an SSD, that extent can come from either local or remote servers. This allocation is removed from the performance-critical path by keeping a pool of preallocated but unassigned extents, much like an SSD’s free list.

Instances talk to EBS over NVMe, so a TRIM arrives as an NVMe Deallocate, and we had to carry it through every layer of our stack. A single Deallocate can cover a large range of LBAs that may map to many storage servers. When we split the TRIM and send it to each server, each piece has to stay ordered against every other write in flight to that range. This splitting and ordering is all orchestrated by the same Nitro card that presents an EBS volume to your instance.

EBS snapshots presented us with a different challenge. To take a snapshot we split data into even smaller segments, called chunks, and then each server is responsible for uploading only the chunks that have changed since the last snapshot. The size of a chunk is a balance between system efficiency (larger is better) and achieving the smallest amount of changed data (smaller is better). Once all chunks have been uploaded, our snapshot systems create a manifest that includes a reference to a parent manifest and a list of all new chunks. Conceptually, when a volume is hydrated from a snapshot, we start at the top manifest and load all chunks, then follow down through the parents until all chunks that are in a manifest have been loaded.

This design was very simple when we built it and most of the processing needed very little bookkeeping on the servers. But it breaks when a TRIM removes an entire chunk. A removed chunk never gets uploaded, so it looks like an unchanged chunk. The new manifest says nothing about it, and hydration keeps walking down the chain until it finds an older version of that chunk. A volume restored from that snapshot would bring the deleted data back, even though a restored volume is supposed to match its source volume. We created a tombstone chunk that tells hydration to stop looking further down the chain, and for chunks that have a partial TRIM, we can encode the gaps in the chunk itself. It wasn’t technically complex, but it’s a reminder that every layer in the system matters.

Cross-server ordering and snapshot tombstones are details that nobody sees, but they’re what make deallocation trustworthy all the way from your filesystem down to S3. We made TRIM available for all volumes, not just Adaptive Volumes, so that every volume can benefit from the snapshot savings.

So when someone asks me “when can I shrink my volume?”, I no longer have to give the sad finale. The answer is that you don’t have to on EBS Adaptive Volumes. As long as your operating system issues TRIM, EBS will deallocate the space and give you the savings back. There’s one caveat, however. TRIM can only free what your application frees. Databases that preallocate their files won’t release space when you delete rows.

I’ve had the chance to follow up with some of our customers this week while at AWS re:Invent and a couple of things are worth noting. When storage interfaces were designed, the standards bodies never expected something like EBS to come along and change its personality, so you will need to reattach your volumes to your instance in order for your operating system to recognize TRIM support. Many of our customers are used to the SAN provisioning model where they would purchase a pool of storage and allocate volumes in that pool, having to carefully manage the free capacity so their workloads didn’t run out of space. EBS manages that for you. Our placement, ordering, and capacity management work together to ensure that your volume has enough physical space for all of its writes.

None of the pieces that made this possible were originally built for it. Physalia was built for availability, partitioning was built for size and repair time, placement was built for latency and heat management, and Block Express for performance. Adaptive Volumes add new building blocks of their own. I overheard someone say that “EBS made block storage cool again,” but storage still has many opportunities for innovation, and that’s what makes it cool. I can’t wait to see what volumes composed from extents and deallocation honored through every layer make possible next.