linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Swap Compression
@ 2003-04-29 20:07 Timothy Miller
  2003-04-29 20:40 ` rmoser
  0 siblings, 1 reply; 21+ messages in thread
From: Timothy Miller @ 2003-04-29 20:07 UTC (permalink / raw)
  To: Linux Kernel Mailing List


Con Kolivas wrote:

>On Tue, 29 Apr 2003 07:35, Timothy Miller wrote:
>  
>
>>    
>>
>The work that Rodrigo De Castro did on compressed caching 
>(linuxcompressed.sf.net) included a minilzo algorithm which I used by default 
>in the -ck patch addon as it performed the best for all the reasons you 
>mention. Why not look at that lzo code for adoption.
>
>  
>
Some time before rmoser started HIS discussion on compressed swap, I 
started a discussion on the same topic.  Out of that discussion came 
mention of an existing project which did EXACTLY what I was proposing. 
 That made me happy.  For some reason rmoser wants to start from 
scratch.  He can do that if he wants.  I had only hoped that my earlier 
mention of it would spark interest in taking the existing implementation 
and adding it to the mainline kernel, after some incompatbilities were 
dealt with.  Unfortunately, I don't have the time to engage directly in 
that particular aspect the kernel development.

>  
>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-29 20:07 Swap Compression Timothy Miller
@ 2003-04-29 20:40 ` rmoser
  2003-04-29 21:14   ` John Bradford
  0 siblings, 1 reply; 21+ messages in thread
From: rmoser @ 2003-04-29 20:40 UTC (permalink / raw)
  To: linux-kernel

*********** REPLY SEPARATOR ***********

On 4/29/2003 at 3:39 PM Timothy Miller wrote:

>
>
>Con Kolivas wrote:
>
>On Tue, 29 Apr 2003 07:35, Timothy Miller wrote:
>
>The work that Rodrigo De Castro did on compressed caching
>(linuxcompressed.sf.net) included a minilzo algorithm which I used by
>default
>in the -ck patch addon as it performed the best for all the reasons you
>mention. Why not look at that lzo code for adoption.
>Some time before rmoser started HIS discussion on compressed swap, I
>started a discussion on the same topic.  Out of that discussion came
>mention of an existing project which did EXACTLY what I was proposing.
>That made me happy.  For some reason rmoser wants to start from scratch.
>He can do that if he wants.  I had only hoped that my earlier mention of
>it would spark interest in taking the existing implementation and adding
>it to the mainline kernel, after some incompatbilities were dealt with.
>Unfortunately, I don't have the time to engage directly in that particular
>aspect the kernel development
>

I want to start from scratch because I am trying a different angle, and I don't understand
fully current projects on it.  I am not trying to discredit anyone.  In fact, I would hope that
the existing implimentation (different as it is) would manage to get itself in as well.
Remember, modularity is all about options. Options aren't just "Do you want this or
that?", but also "How do you want this or that done?"  Plus, I am not compressing the
page cache, assuming I understand what this means.  AFAIK (from others' help), the
page cache is a cached copy of pages that have gone to the swap recently, or been
pulled off recently.  I am not touching that.

Other things (not brought up by me) include making a central compression library for the
kernel (modular, i.e. modprobe zlib and such) (Jorn's idea).  That is something that I think
would be essential for swap compression; why should one module horde all the compression
algo's?

--Bluefox



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-29 20:40 ` rmoser
@ 2003-04-29 21:14   ` John Bradford
  2003-04-30  0:59     ` rmoser
  0 siblings, 1 reply; 21+ messages in thread
From: John Bradford @ 2003-04-29 21:14 UTC (permalink / raw)
  To: rmoser; +Cc: linux-kernel

> I want to start from scratch because I am trying a different angle,
> and I don't understand fully current projects on it.

There is nothing wrong from having a separate, parallel project
running - it's a good idea, and generally helps to spark interest in
both projects.

John.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-29 21:14   ` John Bradford
@ 2003-04-30  0:59     ` rmoser
  2003-04-30  2:48       ` Con Kolivas
  0 siblings, 1 reply; 21+ messages in thread
From: rmoser @ 2003-04-30  0:59 UTC (permalink / raw)
  To: John Bradford; +Cc: linux-kernel



*********** REPLY SEPARATOR  ***********

On 4/29/2003 at 10:14 PM John Bradford wrote:

>> I want to start from scratch because I am trying a different angle,
>> and I don't understand fully current projects on it.
>
>There is nothing wrong from having a separate, parallel project
>running - it's a good idea, and generally helps to spark interest in
>both projects.
>

THANK YOU!

You've saved me from having to defend meself.

--Bluefox Icy
>John.
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-30  0:59     ` rmoser
@ 2003-04-30  2:48       ` Con Kolivas
  2003-04-30 12:59         ` Jörn Engel
  0 siblings, 1 reply; 21+ messages in thread
From: Con Kolivas @ 2003-04-30  2:48 UTC (permalink / raw)
  To: rmoser, John Bradford; +Cc: linux-kernel

On Wed, 30 Apr 2003 10:59, rmoser wrote:
> *********** REPLY SEPARATOR  ***********
>
> On 4/29/2003 at 10:14 PM John Bradford wrote:
> >> I want to start from scratch because I am trying a different angle,
> >> and I don't understand fully current projects on it.
> >
> >There is nothing wrong from having a separate, parallel project
> >running - it's a good idea, and generally helps to spark interest in
> >both projects.
>
> THANK YOU!
>
> You've saved me from having to defend meself.

I don't think a parallel project is a bad idea either. I was just suggesting 
adding the minilzo algorithm from the linuxcompressed project as one of the 
compression algorithms available.

Con

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-30  2:48       ` Con Kolivas
@ 2003-04-30 12:59         ` Jörn Engel
  2003-04-30 19:18           ` rmoser
  2003-05-01 22:07           ` rmoser
  0 siblings, 2 replies; 21+ messages in thread
From: Jörn Engel @ 2003-04-30 12:59 UTC (permalink / raw)
  To: Con Kolivas; +Cc: rmoser, John Bradford, linux-kernel

On Wed, 30 April 2003 12:48:07 +1000, Con Kolivas wrote:
> 
> I don't think a parallel project is a bad idea either. I was just suggesting 
> adding the minilzo algorithm from the linuxcompressed project as one of the 
> compression algorithms available.

Actually, I'd like a central compression library with a large
assortment of algorithms. That way the really common code is shared
between both (or more) projects is shared.

Also, yet another unused compression algorithm hurts about as bad, as
yet another unused device driver. It just grows the kernel .tar.bz2.

Jörn

-- 
Time? What's that? Time is only worth what you do with it.
-- Theo de Raadt

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-30 12:59         ` Jörn Engel
@ 2003-04-30 19:18           ` rmoser
  2003-05-01 22:07           ` rmoser
  1 sibling, 0 replies; 21+ messages in thread
From: rmoser @ 2003-04-30 19:18 UTC (permalink / raw)
  To: =?UNKNOWN?Q?J=F6rn?= Engel; +Cc: linux-kernel



*********** REPLY SEPARATOR  ***********

On 4/30/2003 at 2:59 PM Jörn Engel wrote:

>On Wed, 30 April 2003 12:48:07 +1000, Con Kolivas wrote:
>> 
>> I don't think a parallel project is a bad idea either. I was just
>suggesting 
>> adding the minilzo algorithm from the linuxcompressed project as one of
>the 
>> compression algorithms available.
>
>Actually, I'd like a central compression library with a large
>assortment of algorithms. That way the really common code is shared
>between both (or more) projects is shared.
>

That's just great, heh.  It will in the future cut kernel code size and matinence
work.

>Also, yet another unused compression algorithm hurts about as bad, as
>yet another unused device driver. It just grows the kernel .tar.bz2.
>

Not to get side tracked, but there is an answer for this.....

Well then let's restructure the kernel's build system soon.  It's 15 seconds
since I read this, and already I'm working out in my head the high-level
workings of a modular build system (what it would look like).

For an example, future kernel releases could be in directories, which contain
the kernel .tar.bz2, then separate sets of drivers and such.  Simply unpacking
these drivers into your kernel source tree could place files that make would
read, i.e. the kernel build system would adapt.  For example:

linux/options/foo.lod <-- Linux Option Definition file.

This file would reference other LO's that it requires, and give configuration
options.  These options would have references to LO's that they require.
They would also reference which version ranges of themselves they are
compatible with.  Thus:

make menuconfig

<M>Foo
----<M>Foo with Bar support

<SELECT> <EXIT> <HELP> <MISSING>

Hit missing on an option, say Foo:

Dependencies for CONFIG_FOO
< >Foo
----< >Bar
----< >Baz [FAILED DEPENDS!]

Hit baz:

Dependencies for CONFIG_FOO_BAZ:

Foo with Baz support needs Baz compatible with Baz v1.32

So you get the Baz option tarball, or the tarball containing it:

linux/options/baz.lod

make menuconfig:

<M>Foo
----<M>Foo with Bar support
----<M>Foo with Baz support


Yes I know this is a hassle, but it's not like Microsoft drivers
where you spend 12 hours all over the net searching for stuff;
the main kernel source distribution tree would contain the
kernel, and the kernel.org mirrors would all have the Linux
Options.  There'd be a tarball for the "default must-have drivers"
separate from the kernel core.

It's just a suggestion for the future.

--Bluefox Icy
>Jörn
>
>-- 
>Time? What's that? Time is only worth what you do with it.
>-- Theo de Raadt
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-30 12:59         ` Jörn Engel
  2003-04-30 19:18           ` rmoser
@ 2003-05-01 22:07           ` rmoser
  2003-05-02  2:46             ` jw schultz
  1 sibling, 1 reply; 21+ messages in thread
From: rmoser @ 2003-05-01 22:07 UTC (permalink / raw)
  To: =?UNKNOWN?Q?J=F6rn?= Engel; +Cc: linux-kernel



>Actually, I'd like a central compression library with a large
>assortment of algorithms. That way the really common code is shared
>between both (or more) projects is shared.
>
>Also, yet another unused compression algorithm hurts about as bad, as
>yet another unused device driver. It just grows the kernel .tar.bz2.
>
>Jörn


Had a thought.  Why wait for a compression algorithm?  Jorn, if you are going
to work on putting the code into the kernel and making the stuff to allow the
swap code to use it, why not start coding it before the compression code is
finished?  i.e. get the stuff down for the swap filtering (filtering i.e. passing
through a compression or encryption routine) and swap-on-ram stuff, and later
take the compression algo code and place the module interface on it and make
a kernel module.

At this point, I'd say to allow specified order filters, to allow for swap cyphering
and compression.  Security, you know; swap files are a security hazard.  Just
power-off, boot a root disk, pull up the swap partition, rip out the blocks, and
look for what looks to be the root password.

--Bluefox Icy


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-05-01 22:07           ` rmoser
@ 2003-05-02  2:46             ` jw schultz
  0 siblings, 0 replies; 21+ messages in thread
From: jw schultz @ 2003-05-02  2:46 UTC (permalink / raw)
  To: linux-kernel

On Thu, May 01, 2003 at 06:07:59PM -0400, rmoser wrote:
> Had a thought.  Why wait for a compression algorithm?  Jorn, if you are going
> to work on putting the code into the kernel and making the stuff to allow the
> swap code to use it, why not start coding it before the compression code is
> finished?  i.e. get the stuff down for the swap filtering (filtering i.e. passing
> through a compression or encryption routine) and swap-on-ram stuff, and later
> take the compression algo code and place the module interface on it and make
> a kernel module.
> 
> At this point, I'd say to allow specified order filters, to allow for swap cyphering
> and compression.  Security, you know; swap files are a security hazard.  Just
> power-off, boot a root disk, pull up the swap partition, rip out the blocks, and
> look for what looks to be the root password.

While we're having thoughts, this thread keeps me thinking
it would make sense to have a block device driver that would
be assigned unused memory.

I don't mean memory on video cards etc.  I'm thinking of the
10% of RAM unused when 1GB systems are booted with MEM=900M
because they run faster with HIGHMEM turned off.

The primary use for this "device" would be high priority swap.
Even with whatever overhead it takes to access it should be
orders of magnitude faster than any spinning media.

-- 
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		jw@pegasys.ws

		Remember Cernan and Schmitt

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: Swap Compression
@ 2003-05-09  3:21 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 21+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-05-09  3:21 UTC (permalink / raw)
  To: 'Jörn Engel', Perez-Gonzalez, Inaky
  Cc: 'jw schultz', 'linux-kernel@vger.kernel.org'

> From: Jörn Engel [mailto:joern@wohnheim.fh-wedel.de]
>
> On Wed, 7 May 2003 20:17:32 -0700, Perez-Gonzalez, Inaky wrote:
> > This reminds me of some howto I saw somewhere of someway to
> > use the MTD drivers to access the unused video RAM and turn
> > it into swap (maybe with blkmtd?) ... probably it can be done
> > with that too.
> 
> Jupp, if you know the physical address range of the RAM, it's a piece
> of cake. Except that the slram option parsing is not user-friendly,
> with me being an examplary user.

It should be ... I need to find some time to dig that howto and
try to do it ...

> For memory above 4GB, things are harder. Basically you'd have to write
> a new mtd driver that copies some of the highmem code. Maybe a day or
> two plus testing.

Ok, right to the stack of 'would be nice to work on' stuff. 

The "feeling" thing is going to be groovy to test - I guess some parallel
kernel compiles would do - hmmm ... will think about it.

Thanks,

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-05-08  3:17 Perez-Gonzalez, Inaky
@ 2003-05-08  8:07 ` Jörn Engel
  0 siblings, 0 replies; 21+ messages in thread
From: Jörn Engel @ 2003-05-08  8:07 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky
  Cc: 'jw schultz', 'linux-kernel@vger.kernel.org'

On Wed, 7 May 2003 20:17:32 -0700, Perez-Gonzalez, Inaky wrote:
> 
> This reminds me of some howto I saw somewhere of someway to
> use the MTD drivers to access the unused video RAM and turn
> it into swap (maybe with blkmtd?) ... probably it can be done
> with that too.

Jupp, if you know the physical address range of the RAM, it's a piece
of cake. Except that the slram option parsing is not user-friendly,
with me being an examplary user.

For memory above 4GB, things are harder. Basically you'd have to write
a new mtd driver that copies some of the highmem code. Maybe a day or
two plus testing.

> I'd really love it ... I don't know if I can blame it on highmem
> or not, but since I enabled it, my system 'feels' slower.

Go ahead and try it. If it 'feels' faster, it should be possible to
benchmark your feeling into some numbers.

Jörn

-- 
Victory in war is not repetitious.
-- Sun Tzu

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: Swap Compression
@ 2003-05-08  3:17 Perez-Gonzalez, Inaky
  2003-05-08  8:07 ` Jörn Engel
  0 siblings, 1 reply; 21+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-05-08  3:17 UTC (permalink / raw)
  To: 'jw schultz', 'linux-kernel@vger.kernel.org'



> From: jw schultz [mailto:jw@pegasys.ws]
>
> While we're having thoughts, this thread keeps me thinking
> it would make sense to have a block device driver that would
> be assigned unused memory.
> 
> I don't mean memory on video cards etc.  I'm thinking of the
> 10% of RAM unused when 1GB systems are booted with MEM=900M
> because they run faster with HIGHMEM turned off.
> 
> The primary use for this "device" would be high priority swap.
> Even with whatever overhead it takes to access it should be
> orders of magnitude faster than any spinning media.

This reminds me of some howto I saw somewhere of someway to
use the MTD drivers to access the unused video RAM and turn
it into swap (maybe with blkmtd?) ... probably it can be done
with that too.

I'd really love it ... I don't know if I can blame it on highmem
or not, but since I enabled it, my system 'feels' slower.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
       [not found]                   ` <200304291521120230.0462A551@smtp.comcast.net>
@ 2003-04-29 19:21                     ` rmoser
  0 siblings, 0 replies; 21+ messages in thread
From: rmoser @ 2003-04-29 19:21 UTC (permalink / raw)
  To: linux-kernel

Why keep a fixed page size?  A 4k page can be represented by an
N bit offset in the swap partition (32 for 4 gig or less) and a 13 bit
length description.  Let's not go with the overhead of 13 bit; 16 bit
lengths.  Something divisible by two.  Sure, we gain what
4 + 2 == 6 bytes per page, but we compress out more than that in
most cases (in theory).

and as for RAM, I really prefer the user to control swap-on-ram, and
to have it implimented as such.  4 meg'ers might try SoR but it may
hurt.  The kernel should default to using the RAM swap as its primary
swap partition though.  Why make extra overhead chopping up and
reassembling pages?  We did that with compression.

--Bluefox Icy
(Well that's my opinion)

*********** REPLY SEPARATOR  ***********

On 4/29/2003 at 10:13 AM Timothy Miller wrote:

>Here's a way to keep the two-level swap complexity down, perhaps.
>
>The VM is aware of two kinds of memory space and therefore two kinds of 
>swap.  The first kind of memory is "normal" memory that is used by 
>applications.  When the VM has to swap that, it compresses to RAM.  The 
>second kind of memory is "compressed" memory.  When the VM has to swap 
>that, it swaps it to disk.
>

Swap-on-RAM with compression enabled.

>All swapping operations are done in page units.  Compressed pages will 
>use arbitrary amounts of memory, so when compressed pages are swapped, 
>the boundaries between one compressed page and another are not 
>considered.  Compressed pages will be broken up.  But that's okay, 
>because if there is a page fault in the compressed memory, the VM just 
>swaps in from disk.  Perhaps some intelligent memory management could be 
>employed which reorganizes compressed RAM so that a recently used 
>compressed page does not share a physical page with a compressed page 
>that has not been touched in a while.
>

Ouch.  That introduces extra managment between the compressed RAM
and the swapping procedure.  On the plus, it would save us the hassle
of fragmented swap but heck, idle-time and on-urgent page defragmentation
should take care of that (do I need to explain these concepts?).

>There has been talk of a "simpler" system which compresses to swap 
>without the intermediate level.  The thing is, that intermediate level 
>always exists to some extent.  And trying to manage compressed pages on 
>disk like that can get quite complex.  If we were to compress to a whole 
>number of sectors, just so we could keep things separate, then we would 
>limit the benefit from compressing.  The two level system could be 
>employed to compress to swap simply by keeping the compressed memory 
>fixed and very small.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
       [not found]           ` <200304282258310030.00DED562@smtp.comcast.net>
@ 2003-04-29  2:58             ` rmoser
  0 siblings, 0 replies; 21+ messages in thread
From: rmoser @ 2003-04-29  2:58 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1616 bytes --]



*********** REPLY SEPARATOR  ***********

On 4/28/2003 at 6:25 PM Timothy Miller wrote:

>rmoser wrote:
>
>>So what's the best way to do this?  I was originally thinking like this:
>>
>>Grab some swap data
>>Stuff it into fcomp_push()
>>When you have 100k of data, seal it up
>>Write that 100k block
>>
>>But does swap compress in 64k blocks?  80x86 has 64k segments.
>>The calculation for compression performance loss, 256/size_of_input,
>>gives a loss of 0.003906 (0.3906%) for a dataset 65536 bytes long.
>>So would it be better to just compress segments, whatever size they
>>may be, and index those?  This would, of course, be much more efficient
>>in terms of finding the data to uncompress.  (And system dependant)
>>
>>
>We're not using DOS here.  x86 has arbitrarily-sized segments.  It is
>the PAGES you want to swap, and they are typically 4k.
>
>
>BTW, I see swap compression as being more valuable for over-loaded
>servers than for PDA's.  Yes, I see the advantage for a PDA, but you
>only get any significant benefit out of this if you have the horsepower
>and RAM required for doing heavy-weight compression.  If you can't
>compress a page very much, you don't benefit much from swapping it to RAM.

Feh.  Selectable compression is the eventual goal.  If you want serious
heavy-weight compression, go with fcomp2.  Ahh heck I'll attatch the
.plan file for fcomp2; this is rediculously RAM and CPU intensive in good
implimentation, so don't even think for a second that you'll want to use
this on your cpu-overloaded boxen.

And no implimenting this right away, it's too much to code!

--Bluefox Icy

[-- Attachment #2: __fcomp2.plan --]
[-- Type: application/octet-stream, Size: 7901 bytes --]

fcomp
Fox Compression 2:  Size is everything

by Bluefox Icy

This algoritm is copyright Bluefox Icy under the LGPL as it exists on April
28, 2003.  LGPL v2.0

Definitions:
  Base 0:  A number that starts at 0.  So 1 byte base 0 counters are ranged
  from 0 to 255.

  Base 1:  A number that starts at 1.  So 1 byte base 1 counters are ranged
  from 1 to 256, with 0x00 being 1 and 0x01 being 2 and 0xFF being 256.

  Order of Redundancy:  A numeric count of how much a specific string is used
  to reference other data in a file's compressed output.

fcomp uses a compression algorithm that is focussed on speed only.  It uses
little RAM, and was intended for kernel-level RAM compression and for packing
executable files on 1 Mhz 6502 processors (its creation purpose).  fcomp2 is
quite different.

fcomp2 uses compression and decompression routines by Bluefox Icy.  It was
created literally with size in mind only.  fcomp2 compression should be sane,
but there's always the warning that I wrote the boyer-moore search myself, and
someone really needs to FSA-prove that it works.  Replace it with KMP,  brute
force, or your own equivalent BM if you want a 100% guarentee.

fcomp2 compressed data is a mixed backpointer/table data format.  Officially,
fcomp2 is a floating size backpointer format; backpointer size and max distance
is capable of switching along the way.  Most implimentations will want to use
a fixed size backpointer though, usually 24 bit (16 MB).

fcomp2 uses a pointer table and various pointer types.  The pointer types are
quite diverse.  A general pointer container looks like so:

TYPE    SIZE    DESC
Byte       1    Type of pointer
X          X    The pointer itself
3Byte      3    24 bit forward reference indicating the location of the next
                pointer.  It is base 0, and a 0 indicates EOS (just like in
		fcomp)

Literal pointers (1) point back into the stream and may be 8, 16, 24, or 32
bit. These pointers are standard go-back-and-copy-N pointers, like fcomp uses.
They provide a pointer within the window that the scan is using.

TYPE    SIZE    DESC
Byte       1    Size N in bytes of pointer data
NByte      N    Distance back to look, base 1 (0 == 1, range is 1..2^N)
NByte      N    Distance to copy, base 1 (0 == 1, range is 0..2^N)

Table pointers (2) are extra power.  Table pointers are pointers that reference
a table which holds the absolute locations in the stream (not including the
table) of data that each pointer points to.  In reality, all back pointers can
be replaced with table pointers.

Please note that by stream, we mean the actual pointer-and-data stream that is
processed in the compression and NOT the supplimentary header or table.

TYPE    SIZE    DESC
Byte       1    Size N in bytes of pointer data.  Increasing the size increases
                your range in the table, i.e. 1 byte can access entries 0..255,
		2 can access 0..65535, 3 0..16777383, and so on.
NByte      N    Index of the entry to copy
NByte      N    Number of bytes base 0 to skip from the beginning
NByte      N    Number of bytes base 1 to copy

The final type of pointer is a NULL (0) pointer.  If the pointer is null, it
simply is blank, i.e. X = 0 in the general pointer container definition.  A
null pointer is always 4 bytes long including the general pointer container
defined above, and 0 bytes long not including it.  It looks like this:

TYPE    SIZE    DESC

Yes, this is complete.

The stream format is:

fcomp2 stream:
TYPE   SIZE    DESC
3Byte     3    Length of X base 0 (for consistency)
stream    X    a bunch of bytes to take as pure stream
Pointer   Y    A pointer inside a general pointer container

The last 2 repeat until EOS, which is where the general pointer container has
its next pointer as a 0.  The stream should always end with a pointer with a
forward reference of 0, either Literal, Table, or NULL.

The fcomp2 table is pretty simple.  It points to offsets in the stream of data,
which is read by a decompressor and used to give further
compression/decompression performance.  This works when things are out of reach
of backpointers.  Also, a very good implimentation may take the time to
optimize the table and stream; that is, it may move all the most commonly used
table entries to the beginning and use the smallest pointer data size possible.

The fcomp2 table is in itself not built for size.  Data of multiple redundancy
is initially entered into the table as a 32 bit (4 byte) offset.  The length is
not stored; the compressor will find an offset from this within the reach of
the next table entry at compression time, while the decompressor reads entry,
skip, and copy.  To do this more easily, the compressor should keep the data
table in the order the data appears in the file until compression is finished,
and then sort the table based on order of redundancy (aka how many times each
entry is used) from greatest to least.  As the table is sorted, the stream and
table both may be adjusted so as to squeeze out more space (i.e. the most used
table entries are referenced as 8 bit pointers, changing the pointers to point
at these and use 8 bit storage changes the compressed stream).  Note that
altering the size of the compressed stream should not alter the table, as it is
in reference to the uncompressed stream.

fcomp2-table:
TYPE    SIZE    DESC
Dword      4    A 32 bit offset of the data in the uncompressed stream

An fcomp2 data file contains a few things.  First are 2 longs:  Table and
Stream offsets in the file.  Second is some data, the table, and the stream.
The "some data" can be anything (encryption flags, CRC's, etc).

fcomp2 data file:
TYPE   SIZE    DESC
DWord     4    32 bit offset base 0 (this is AT 0) of where the table is in the
               fire
DWord     4    32 bit base 0 offset of the fcomp2 stream
stream    X    Whatever you want until the table occurs
fcomp2-table Y  The table
fcomp2-stream Z The stream.  The beginning of this is exactly where a pointer to
               offset 0 in the table would point to

I would encourage the open source community to experiment with implimenting
this compression schema.  It is VERY RAM intensive, but a good implimentation
should be able to squeeze great compression ratios from this.  Here are the
requirements for the best implimentation:

1.  Intelligent Table Generation
  Table entries are each 4 bytes in size.  A table should not be generated at a
  point less than 4 bytes from the previous table.
2.  Optimized Table Sorting
  The entries most used in the table should be placed at the beginning; the
  table should be sorted in descending reference order.  Then the pointers must
  be adjusted (must as in this will break the stream if you don't do this) in
  the compressed stream to point to the new locations of the table entries.  In
  adjusting the pointers, the compressor should shrink them to the smallest
  possible size given the index number they must reference and the
  distance/vector they must skip and copy.  For the best optimization, this
  step should also take into account the distance/vector sizes in the pointers,
  to assess how many pointers would gain and lose size in each range of index
  size (1/2/3/4 bytes) and compute the total size gain (positive or negative)
  for each pointer given the positions, and adjust according to these final
  scores.
3.  Intelligent Table Discarding
  When table entries in the table are close enough together, the pointers which
  reference them may be capable of using only a small set from a larger set of
  table entries.  If this is the case, the compressor should remove those table
  entries and readjust all related pointers.

If a compressor is written, it does not have to follow any of the above to have
compatible output with fcomp2 binary files; however, the above guidelines give
the best compression ratios for fcomp2 compressed files.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-28 21:35 ` Timothy Miller
@ 2003-04-29  0:43   ` Con Kolivas
  0 siblings, 0 replies; 21+ messages in thread
From: Con Kolivas @ 2003-04-29  0:43 UTC (permalink / raw)
  To: Timothy Miller, rmoser; +Cc: linux-kernel

On Tue, 29 Apr 2003 07:35, Timothy Miller wrote:
> rmoser wrote:
> >Yeah you did but I'm going into a bit more detail, and with a very tight
> > algorithm.  Heck the algo was originally designed based on another
> > compression algorithm, but for a 6502 packer.  I aimed at speed,
> > simplicity, and minimal RAM usage (hint:  it used 4k for the code AND the
> > compressed data on a 6502, 336 bytes for code, and if I turn it into just
> > a straight packer I can go under 200 bytes on the 6502).
> >
> >Honestly, I just never looked.  I look in my kernel.  But still, the stuff
> > I defined about swapon options, swap-on-ram, and how the compression
> > works (yes, compressed without headers) is all the detail you need about
> > it to go do it AFAIK.  Preplanning should be done there--done meaning
> > workable, not "the absolute best."
>
> I think we might be able to deal with a somewhat more heavy-weight
> compression.  Considering how much faster the compression is than the
> disk access, the better the compression, the better the performance.
>
> Usually, if you have too much swapping, the CPU usage will drop, because
> things aren't getting done.  That means we have plenty of head room to
> spend time compressing rather than waiting.  The speed over-all would go
> up.  Theoretically, we could run into a situation where the compression
> time dominates.  In that case, it would be beneficial to have a tuning
> options which uses a less CPU-intensive compression algorithm.

The work that Rodrigo De Castro did on compressed caching 
(linuxcompressed.sf.net) included a minilzo algorithm which I used by default 
in the -ck patch addon as it performed the best for all the reasons you 
mention. Why not look at that lzo code for adoption.

Con

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-25 22:32 rmoser
@ 2003-04-28 21:35 ` Timothy Miller
  2003-04-29  0:43   ` Con Kolivas
  0 siblings, 1 reply; 21+ messages in thread
From: Timothy Miller @ 2003-04-28 21:35 UTC (permalink / raw)
  To: rmoser; +Cc: linux-kernel



rmoser wrote:

>Yeah you did but I'm going into a bit more detail, and with a very tight algorithm.  Heck the algo was originally designed based on another compression algorithm, but for a 6502 packer.  I aimed at speed, simplicity, and minimal RAM usage (hint:  it used 4k for the code AND the compressed data on a 6502, 336 bytes for code, and if I turn it into just a straight packer I can go under 200 bytes on the 6502).
>
>Honestly, I just never looked.  I look in my kernel.  But still, the stuff I defined about swapon options, swap-on-ram, and how the compression works (yes, compressed without headers) is all the detail you need about it to go do it AFAIK.  Preplanning should be done there--done meaning workable, not "the absolute best."
>  
>
I think we might be able to deal with a somewhat more heavy-weight 
compression.  Considering how much faster the compression is than the 
disk access, the better the compression, the better the performance.  

Usually, if you have too much swapping, the CPU usage will drop, because 
things aren't getting done.  That means we have plenty of head room to 
spend time compressing rather than waiting.  The speed over-all would go 
up.  Theoretically, we could run into a situation where the compression 
time dominates.  In that case, it would be beneficial to have a tuning 
options which uses a less CPU-intensive compression algorithm.

>  
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-28  8:52                   ` Eric W. Biederman
@ 2003-04-28 10:26                     ` Jörn Engel
  0 siblings, 0 replies; 21+ messages in thread
From: Jörn Engel @ 2003-04-28 10:26 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: rmoser, linux-kernel

On Mon, 28 April 2003 02:52:15 -0600, Eric W. Biederman wrote:
> JXrn Engel <joern@wohnheim.fh-wedel.de> writes:
> 
> > Yes, zlib eats up several 100k of memory. You really notice this when
> > you add it to a bootloader that was (once) supposed to be small. :)
> 
> I only measured about 32k for decompression.  But that was using
> the variant from gzip via the kernel.

What were you measuring? Code size or runtime memory consumption? It
looks a bit large for code size, but _very_ small for runtime.

> The really small algorithm I know about (at least for decompression)
> is upx.  The compression is comparable with gzip with a decompressor
> that can fit in a page or two of assembly code.

Sounds interesting as well. Maybe we should add a central compression
library to the kernel. zlib is already central, but at least jffs2 and
ppp also have some other algorithms that could be moved and possibly
reused for other subsystems/drivers.

Jörn

-- 
Optimizations always bust things, because all optimizations are, in
the long haul, a form of cheating, and cheaters eventually get caught.
-- Larry Wall 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-27 19:04                 ` Jörn Engel
@ 2003-04-28  8:52                   ` Eric W. Biederman
  2003-04-28 10:26                     ` Jörn Engel
  0 siblings, 1 reply; 21+ messages in thread
From: Eric W. Biederman @ 2003-04-28  8:52 UTC (permalink / raw)
  To: JXrn Engel; +Cc: rmoser, linux-kernel

JXrn Engel <joern@wohnheim.fh-wedel.de> writes:

> Yes, zlib eats up several 100k of memory. You really notice this when
> you add it to a bootloader that was (once) supposed to be small. :)

I only measured about 32k for decompression.  But that was using
the variant from gzip via the kernel.

The really small algorithm I know about (at least for decompression)
is upx.  The compression is comparable with gzip with a decompressor
that can fit in a page or two of assembly code.

Probably irrelevant at this juncture but...

Eric


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-25 20:48 ` rmoser
  2003-04-25 21:14   ` Jörn Engel
@ 2003-04-25 21:17   ` John Bradford
  1 sibling, 0 replies; 21+ messages in thread
From: John Bradford @ 2003-04-25 21:17 UTC (permalink / raw)
  To: rmoser; +Cc: linux-kernel

> Sorry if this is HTML mailed.  I don't know how to control those settings

HTML mail is automatically filtered from LKML.

> COMPRESSED SWAP

We discussed this on the list quite recently, have a look at:

http://marc.theaimsgroup.com/?l=linux-kernel&m=105018674018129&w=2

and:

http://linuxcompressed.sourceforge.net/

John.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Swap Compression
  2003-04-25 20:48 ` rmoser
@ 2003-04-25 21:14   ` Jörn Engel
  2003-04-25 21:17   ` John Bradford
  1 sibling, 0 replies; 21+ messages in thread
From: Jörn Engel @ 2003-04-25 21:14 UTC (permalink / raw)
  To: rmoser; +Cc: linux-kernel

On Fri, 25 April 2003 16:48:15 -0400, rmoser wrote:
> 
> Sorry if this is HTML mailed.  I don't know how to control those settings

It is not, but if you could limit lines to <80 characters, that would
be nice.

> COMPRESSED SWAP
> 
> This is mainly for things like linux on iPaq (handhelds.org) and
> people who like to play (me :), but how about compressed swap and
> RAM as swap?  To be plausable, we need a very fast compression
> algorithm.  I'd say use the following back pointer algorithm (this
> is headerless and I coded a decompressor in 6502 assembly in about
> 315 bytes) and 100k block sizes (compress streams of data until they
> are 100k in size, then stop.  Include the cap at the end in the
> 100k).
> 
> [...]
> 
> CONCLUSION
> 
> I think compressed swap and swap-on-ram with compression would be a
> great idea, especially for embedded systems.  High-performance
> systems that can handle the compression/decompression without
> blinking would especially benefit, as the swap-on-ram feature would
> give an almost seamless RAM increase.  Low-performance systems would
> take a performance hit, but embedded devices would still benefit
> from the swap-on-ram with compression RAM boost, considering they
> can probably handle the algorithm.  I am looking forward to seeing
> this implimented in 2.4 and 2.5/2.6 if it is adopted.

Nice idea. This might even benefit normal pc style boxes, if the
performance loss through compression is overcompensated by io gains
(less data transferred).

The tiny problem I see is that most people here have tons of whacky
ideas themselves but lack the time to actually implement them. If you
really want to get it done, do it yourself. It doesn't have to be
perfect, if it works in principle and appears to be promising, you
will likely receive enough help to finish it. But you have to get
there first.

At least, that is how it usually works. Feel free to prove me wrong.

Jörn

-- 
When in doubt, use brute force.
-- Ken Thompson

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Swap Compression
       [not found] <200304251640110420.0069172B@smtp.comcast.net>
@ 2003-04-25 20:48 ` rmoser
  2003-04-25 21:14   ` Jörn Engel
  2003-04-25 21:17   ` John Bradford
  0 siblings, 2 replies; 21+ messages in thread
From: rmoser @ 2003-04-25 20:48 UTC (permalink / raw)
  To: linux-kernel

please CC a copy to me personally; I am not subscribed.

Sorry if this is HTML mailed.  I don't know how to control those settings


COMPRESSED SWAP

This is mainly for things like linux on iPaq (handhelds.org) and people who like to play (me :), but how about compressed swap and RAM as swap?  To be plausable, we need a very fast compression algorithm.  I'd say use the following back pointer algorithm (this is headerless and I coded a decompressor in 6502 assembly in about 315 bytes) and 100k block sizes (compress streams of data until they are 100k in size, then stop.  Include the cap at the end in the 100k).

Here is how the compression works (use fixed width font):
;
; Type Size Description
; Byte 1 Distance to the next backpointer. 0 means end-of-stream.
; Stream X Just straight data, no work needbe performed on it.
; Byte 1 Distance (up to 256, it's base 1) back to seek
; Byte 1 Number of bytes (Up to 255) to copy. 0 means don't
; really do anything (for chaining pointers in large
; areas of nonredundant data)
;
; The above repeats until the end of the stream is reached. Teach by example!
;
; 04 00 01 02 03 03 03 04 00 01 02 03 05 04 06 01 03 00 00 00
; ^ & # ^ & # ^ & # ^
; ^ = Distance to next; & = backseek; # = duplicate length
;
; The above stream uncompresses to:
; 00 01 02 03 00 01 02 00 01 02 03 01 02 00 01 01 03
;
; Note how very small datasets do not compress well. Very large would
; begin to catch up. This is only a 17 byte dataset.

Also, use a booyer-moore algorithm to do the redundancy searching (modify the one in the fdber project at fdber.sourceforge.net to work on binary data, for instance) to further speed it up.  In the end I'd project about a 2-4k code increase (compiled/assembled) in the kernel size, plus 256 bytes for the compression/decompression buffer, plus the dedicated 100k to load the compressed block into RAM.  So about 2-4k increase in the kernel size and 105k increase in RAM usage.

The feature should be optional, and controlled by swapon options.  For instance:

swapon -o compress /dev/hda5

The above could turn a swap partition on under compressed swap mode.  Of course we only would want to use 100k blocks of compressed data, but some extra code can allow the user to configure it:

swapon -o compress=1M /dev/hda5

1 MB block size for instance if you want.  Don't make this too limited; if such a thing were implimented, with such an option, I'd still expect the following to work:

swapon -o compress=1247299 /dev/hda5

to load a swap partition with 1,247,299 byte blocks.  Of course there'd be a rediculous cap on the high end (500 MB block size?!!!!!!!!!!!!), and an impossible cap on both ends (block size > available RAM; block size < 5 (a valid stream fits in 4 but it can't store any data or be processed)).

For predicting available swap, just take statistics and do some calculations, figure out what the average ratio is, and give that times real size as the total swap size.  If you really really care that much, discard outliers.

SWAP ON RAM

The other feature, for handheld devices, is for all those iPaqs with 32 or 64 MB RAM:  swap-on-RAM.  This is useless (i.e. swap on a RAMdisk), but with the swap compression it becomes useful.

Swap on RAM allows the swap driver to use RAM directly as swap, i.e. not as a swap file on a ramdisk.  For instance:

swapon -o compress -o swaponram=16M

The above would use 16 MB of my RAM as a compressed swap file, negating the overhead of disk access, filesystem control, ramdisk control, and so on.  On an iPaq with 32 MB RAM, I could access say 16 M RAM (physical) and 32 MB swap now, giving me 1.5x my real ram (predicted).  With 64 MB, it would be 82 MB RAM (1.25x real RAM), or I could just use 32MB (1.5x = 96 MB) or even 48 MB (1.75x = 112 MB).  Can't use all of it of course; and the more I use the more it swaps.

When a real swap and a RAM swap exist, a RAM swap should be the first choice for swapping out (highest precidence).  This would keep performence up the most under these odd conditions.


CONCLUSION

I think compressed swap and swap-on-ram with compression would be a great idea, especially for embedded systems.  High-performance systems that can handle the compression/decompression without blinking would especially benefit, as the swap-on-ram feature would give an almost seamless RAM increase.  Low-performance systems would take a performance hit, but embedded devices would still benefit from the swap-on-ram with compression RAM boost, considering they can probably handle the algorithm.  I am looking forward to seeing this implimented in 2.4 and 2.5/2.6 if it is adopted.

-- Bluefox Icy


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2003-05-09  3:08 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-29 20:07 Swap Compression Timothy Miller
2003-04-29 20:40 ` rmoser
2003-04-29 21:14   ` John Bradford
2003-04-30  0:59     ` rmoser
2003-04-30  2:48       ` Con Kolivas
2003-04-30 12:59         ` Jörn Engel
2003-04-30 19:18           ` rmoser
2003-05-01 22:07           ` rmoser
2003-05-02  2:46             ` jw schultz
  -- strict thread matches above, loose matches on Subject: below --
2003-05-09  3:21 Perez-Gonzalez, Inaky
2003-05-08  3:17 Perez-Gonzalez, Inaky
2003-05-08  8:07 ` Jörn Engel
2003-04-25 22:48 rmoser
2003-04-26  9:17 ` Jörn Engel
     [not found]   ` <200304261148590300.00CE9372@smtp.comcast.net>
     [not found]     ` <20030426160920.GC21015@wohnheim.fh-wedel.de>
2003-04-27  2:24       ` rmoser
2003-04-27  9:04         ` Jörn Engel
2003-04-27 17:24           ` rmoser
2003-04-27 17:51             ` Jörn Engel
2003-04-27 18:31               ` rmoser
2003-04-27 19:04                 ` Jörn Engel
2003-04-28  8:52                   ` Eric W. Biederman
2003-04-28 10:26                     ` Jörn Engel
     [not found]                 ` <3EAE8899.2010208@techsource.com>
     [not found]                   ` <200304291521120230.0462A551@smtp.comcast.net>
2003-04-29 19:21                     ` rmoser
     [not found]         ` <3EADAA5D.1090408@techsource.com>
     [not found]           ` <200304282258310030.00DED562@smtp.comcast.net>
2003-04-29  2:58             ` rmoser
2003-04-25 22:32 rmoser
2003-04-28 21:35 ` Timothy Miller
2003-04-29  0:43   ` Con Kolivas
     [not found] <200304251640110420.0069172B@smtp.comcast.net>
2003-04-25 20:48 ` rmoser
2003-04-25 21:14   ` Jörn Engel
2003-04-25 21:17   ` John Bradford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).