Skip to contentSkip to conversation

Compressed Filesystem

DISCUSSION Lee Trager 4 participants 8 messages Oct 27, 2008 – Nov 4, 2008 1 message not in the archive Btrfs file system

lore
Share & tools
lore

Lee Trager

author
#0 lore raw

I have read on the mailing list that there has been some interest in implementing transparent compression on btrfs and I too am thinking about trying to implement it. Before I start from scratch I am wondering if anyone else has started to work on this and if so how far along have they gotten? I would be happy to work on this alone or with someone else but currently I am doing some preliminary research.

Thanks,

Lee

#1 lore raw
Quoted 6 lines · Lee Trager

I have read on the mailing list that there has been some interest in implementing transparent compression on btrfs and I too am thinking about trying to implement it. Before I start from scratch I am wondering if anyone else has started to work on this and if so how far along have they gotten? I would be happy to work on this alone or with someone else but currently I am doing some preliminary research.

Compression is working on my machine, I'm just running some long tests before I push it out to the unstable repo. The current code uses the in-kernel zlib implementation.

-chris

author
#2 lore raw
Quoted 8 lines · Chris Mason
Quoted 6 lines · Lee Trager

I have read on the mailing list that there has been some interest in implementing transparent compression on btrfs and I too am thinking about trying to implement it. Before I start from scratch I am wondering if anyone else has started to work on this and if so how far along have they gotten? I would be happy to work on this alone or with someone else but currently I am doing some preliminary research.

Quoted 6 lines

Compression is working on my machine, I'm just running some long tests before I push it out to the unstable repo. The current code uses the in-kernel zlib implementation.

-chris

Thats great I am eager to try it. How long will these tests take? I would love to look at the code. Is compression done for every file by default or does a user space program have to set a compression flag on the file?

Thanks,

Lee

#3 lore raw
Quoted 13 lines · Lee Trager
Quoted 12 lines · Chris Mason
Quoted 6 lines · Lee Trager

I have read on the mailing list that there has been some interest in implementing transparent compression on btrfs and I too am thinking about trying to implement it. Before I start from scratch I am wondering if anyone else has started to work on this and if so how far along have they gotten? I would be happy to work on this alone or with someone else but currently I am doing some preliminary research.

Compression is working on my machine, I'm just running some long tests before I push it out to the unstable repo. The current code uses the in-kernel zlib implementation.

Quoted 7 lines
Quoted 2 lines

-chris

Thats great I am eager to try it. How long will these tests take? I would love to look at the code. Is compression done for every file by default or does a user space program have to set a compression flag on the file?

This is a fairly large change, I plan on running it overnight.

Compression is optional and off by default (mount -o compress to enable it). When enabled, every file is compressed.

-chris

#4 lore raw
Quoted 3 lines

Compression is optional and off by default (mount -o compress to enable it). When enabled, every file is compressed.

Compression is attempted as files are written when the mount option is enabled, right?

There isn't a background scrubber that tries to compress files which are already written?

- z

#5 lore raw
Quoted 5 lines · Zach Brown
Quoted 2 lines

Compression is optional and off by default (mount -o compress to enable it). When enabled, every file is compressed.

Compression is attempted as files are written when the mount option is enabled, right?

Yes, and if the compression doesn't make a given set of pages smaller it quickly backs off and goes back to writing it straight through.

Quoted 3 lines

There isn't a background scrubber that tries to compress files which are already written?

No, but if you mount with compression on and use the single file defrag ioctl (btrfsctl -d some_file) it'll compress it.

-chris

A message that is not in the archive (sent off-list or not yet received): 53696.2001:470:e828:1::2:[email protected]

#7 lore raw
Quoted 6 lines · Anthony Roberts

Hi, I have a few questions about this:

Quoted 2 lines

Compression is optional and off by default (mount -o compress to enable it). When enabled, every file is compressed.

Do you know what the CPU load is like with this enabled?

Now that I've finally pushed the code out, you can try it ;) One part of the implementation I need to revisit is the place in the code where I do compression means that most of the time the single threaded pdflush is the one compressing.

This doesn't spread the load very well across the cpus. It can be fixed, but I wanted to get the code out there.

The decompression does spread across cpus, and I've gotten about 800MB/s doing decompress and checksumming on a zero filled compressed file. At the time, the disk was reading 14MB/s.

Quoted 3 lines

Do you know whether data can be compressed at a sufficient rate to still saturate the disk on recent-ish AMD/Intel CPUs?

My recentish intel cpu can compress and checksum at about 120MB/s.

Quoted 4 lines

If no, is the effective pre-compression I/O rate still comparable to the disk without compression?

It depends on your disks...

Quoted 7 lines

I'm pretty sure that won't even matter in many cases (eg you're seeking too much to care, or you're on a VM with lots of cores but congested disks, or you're dealing with media files that it doesn't bother compressing, etc), but I'm curious what sort of overhead this adds. :)

Mostly it seems like a good tradeoff, it trades plentiful cores for scarce disk resources.

This varies quite a bit from workload to workload, in some places it'll make a big difference, but many workloads are seek bound and not bandwidth bound.

-chris

#8 lore raw
Quoted 3 lines · Chris Mason

The decompression does spread across cpus, and I've gotten about 800MB/s doing decompress and checksumming on a zero filled compressed file.  At the time, the disk was reading 14MB/s.

FWIW I've got a pretty ugly patch to Bonnie++ that makes it use data from /dev/urandom for writes rather than just blocks of zero's which give, um, optomistic values for throughput on filesystems that do compression.

Still not particularly realistic in terms of an actual workload, but maybe just a tad less unrealistic. :-)

Caveat emptor - I've not tried this since I sent it to Russell Coker in January '07.

cheers,
Chris

Signature · 4 lines
 Chris Samuel  :  http://www.csamuel.org/  :  Melbourne, VIC

This email may come with a PGP signature as a file. Do not panic.
For more info see: http://en.wikipedia.org/wiki/OpenPGP
bonnie++.cpp +27 -1
diff -ur bonnie++-1.03a/bonnie++.cpp bonnie++-1.03a-urand/bonnie++.cpp
@@ -41,6 +41,9 @@
 #include <string.h>
 #include <sys/utsname.h>
 #include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #ifdef AIX_MEM_SIZE
 #include <cf.h>
@@ -148,6 +151,28 @@
   }
 }
 
+void load_random_data(char *temp_buffer,int length)
+{
+	int filedes, numbytes;
+
+	filedes=open("/dev/urandom",O_RDONLY);
+	if(filedes<0)
+	{
+		perror("Open of /dev/urandom failed, falling back to 0's");
+		memset(temp_buffer, 0, length);
+	}
+	else
+	{
+		numbytes=read(filedes,temp_buffer,length);
+		if(numbytes!=length)
+			{
+				perror("Read from /dev/urandom failed, falling back to 0's");
+				memset(temp_buffer, 0, length);
+			}
+		close(filedes);
+	}
+}
+
 int main(int argc, char *argv[])
 {
   int    file_size = DefaultFileSize;
@@ -477,7 +502,8 @@
       return 1;
     globals.decrement_and_wait(FastWrite);
     if(!globals.quiet) fprintf(stderr, "Writing intelligently...");
-    memset(buf, 0, globals.chunk_size());
+    // memset(buf, 0, globals.chunk_size());
+    load_random_data(buf, globals.chunk_size());
     globals.timer.timestamp();
     bufindex = 0;
     // for the number of chunks of file data