Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Jan 26, 2011 11:26 am 
Offline
Senior Newbie

Joined: Thu May 27, 2010 4:09 pm
Posts: 8
Website: http://www.citizensombudsman.org
Location: Hong Kong
http://code.google.com/p/compcache/
Image
Quote:
This project creates RAM based block device (NOW named zram) which acts as swap disk (AND a generic in memory self-compressing block device). Pages swapped to this disk are compressed and stored in memory itself.

FYI: They have removed the redundant backing disk option that activates if the page is not compressable. I guess this is for the short term so if it can't swap a page you still need your old swapdisk as a backup.

Compressing pages and keeping them in RAM virtually increases its capacity. This allows more applications to fit in given amount of memory. That's more for less money on your monthly linode bill.

The usual argument I get is - memory is so cheap so why bother with compression? So I list here some of the use cases. Rest depends on your imagination :)

* Netbooks: Market is now getting flooded with these "lightweight laptops". These are memory constrained but have CPU enough to drive on compressed memory (e.g. Cloudbook features 1.2 GHz processor!).

* Virtualization: With compcache at hypervisor level, we can compress any part of guest memory transparently - this is true for any type of Guest OS (Linux, Windows etc.). This should allow running more number of VMs for given amount of total host memory.


* Embedded Devices: Memory is scarce and adding more memory increases device cost. Also, flash storage suffers from wear-leveling issues, so its useful if we can avoid using them as swap device.


Just use this if you want FASTER SWAP traded in for a smaller amount of memory. I think it sells itself :)

I wonder if Linode is over-subscribing their server's memory transparently yet using this technology.... Sounds interesting.

Please confirm or deny this on the record linode admins. I'm hoping the answer is NO but I'd just like to hear it from you guys.

Also I wonder if the competitors will do this.... With everyone on dreamhost being pushed to run debian, I'd assume they just free the duplicate pages in memory as their $$$ saver.

I'd like to know because if they aren't there will be a performance boost if power users do this in some cases.
Could the linode admins confirm or deny if this is use.
[update: Crackpots comments aside, it's worth documenting exactly what kind of Xen implementation a linode IS and IS NOT
Linode doesn't admins say they don't use this
]

I'm testing now. All the more reason to roll your own kernel ;)
(or at least reconfigure the linode one).

And the testing is done! I've rolled out my implementation to a gentoo bug.

http://bugs.gentoo.org/show_bug.cgi?id=252987

Here's the ebuild and the init.d scripts for those who are interested.
compcache-0.7-r9999.ebuild
Code:
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"
inherit eutils linux-mod toolchain-funcs mercurial

DESCRIPTION="Compressed RAM as fast swap"
HOMEPAGE="http://compcache.googlecode.com/"
#SRC_URI="http://compcache.googlecode.com/files/${P}.tar.gz"
EHG_REPO_URI="https://compcache.googlecode.com/hg/"
S="${WORKDIR}/compcache"

LICENSE="GPL-2 LGPL-2.1"
KEYWORDS="~arm ~amd64 ~x86"
IUSE="swap_free_notify"

DEPEND=">=virtual/linux-sources-2.6
      dev-vcs/mercurial
      "
RDEPEND="${DEPEND}"

pkg_setup() {
      BUILD_PARAMS='KV_OUT_DIR="${KV_OUT_DIR}"'
      BUILD_TARGETS="all"
      CONFIG_CHECK="LZO_COMPRESS LZO_DECOMPRESS SWAP !RAMZSWAP"
      MODULE_NAMES="zram(compcache:${S}:${S})"
      MODULESD_ZRAM_DOCS="Changelog README"
      MODULESD_ZRAM_EXAMPLES=('zram num_devices=1')
      linux-mod_pkg_setup
}

src_prepare() {
   find . -name Makefile -exec sed -i \
      -e 's:make:$(MAKE):g' \
      -e "s:@gcc:$(tc-getCC) :g" \
      -e 's#/lib/modules/$(shell uname -r)/build#"$(KV_OUT_DIR)"#' \
      {} \; || die

   cd "${S}"
   use swap_free_notify && epatch "${FILESDIR}"/${P}-free_notify.patch
}

src_compile() {
   linux-mod_src_compile
}

src_install() {
   linux-mod_src_install

   dosbin sub-projects/scripts/zram_stats || die

   newinitd "${FILESDIR}/init.d-${PN}" ${PN} || die
   newconfd "${FILESDIR}/conf.d-${PN}" ${PN} || die

   dodoc Changelog README || die
   dodoc patches/patch_swap_notify_core_support_2.6.33.diff || die
}


init.d-compcache
Code:
#!/sbin/runscript
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

depend() {
   need localmount
   after bootmisc modules
}

start() {
   if [ "${LOAD_ON_START}" = "yes" ] ; then
      if ! grep zram /proc/devices >/dev/null ; then
         einfo "Loading zram module..."
         modprobe zram num_devices=${NUM_DEVICES}
         eend $?
      fi
   fi
   # exit if the driver is not yet installed
   grep zram /proc/devices >/dev/null || exit 1

   for I in `seq 0 \`expr ${NUM_DEVICES} - 1\`` ; do
      eval _a=\${ZRAM_SIZE_${I}}
      einfo "Enabling swap /dev/zram${I}..."
      if test ! -z ${_a} && test -f /sys/block/zram${I}/disksize ; then
         echo $(($_a*1024)) > "/sys/block/zram${I}/disksize"
         mkswap -L zram${I} /dev/zram${I} ${_a}
      fi
      if test -b "/dev/zram${I}" ; then
         swapon ${SWAPON_OPTS} "/dev/zram${I}"
      fi
      eend $?
   done
}

stop() {
   for I in `seq 0 \`expr ${NUM_DEVICES} - 1\`` ; do
      einfo "Disabling swap /dev/zram${I}..."
      swapoff "/dev/zram${I}" && \
      echo 1 > "/sys/block/zram${I}/reset"
      eend $?
   done

   if [ "${UNLOAD_ON_STOP}" = "yes" ] && grep zram /proc/modules >/dev/null  ; then
      einfo "Unloading zram module..."
      rmmod zram
      eend $?
   fi
}

info() {
   for I in `seq 0 \`expr ${NUM_DEVICES} - 1\`` ; do
      zram_stats "/dev/zram${I}"
   done
}

reload() {
   for I in `seq 0 \`expr ${NUM_DEVICES} - 1\`` ; do
      swapoff "/dev/zram${I}" && \
      echo 1 > "/sys/block/zram${I}/reset"
      swapon ${SWAPON_OPTS} "/dev/zram${I}"
   done
}

restart() {
   stop
   start
}


conf.d-compcache
Code:
# CompCache settings...

# load ramzswap kernel module on start?
LOAD_ON_START="yes"

# unload ramzswap kernel module on stop?
UNLOAD_ON_STOP="yes"

# number of device
NUM_DEVICES="4"

# uncompressed size in Kilobytes of each compressed ram swap disk
# (numbered from 0 to $NUM_DEVICES-1)
# only allocated / used / non-zeroed memory is actually used and will be less than this figure
# example 32 MB
ZRAM_SIZE_0="32768"
ZRAM_SIZE_1="32768"
ZRAM_SIZE_2="32768"
ZRAM_SIZE_3="32768"

# options for swapon
# (if this number is higher than your disk swap drive zram will be used for swap)
SWAPON_OPTS="-p 666"



If you run gentoo you can get the latest version from source (mercurial / googlecode) and RTFM or maybe someone cares can add it to the linode library.

You need the latest version if you want to install a module under linux-2.6.34+! refer to this bug
http://code.google.com/p/compcache/issues/detail?id=68


I think mysql locks memory so it can't be swapped, so there is no substitute for the real thing.

Let's be honest, linode IO is pretty constrained so a ramzswap might be your answer to trade CPU clicks you may not be using for some more memory....

Gentoo users see here

Others see here:
http://library.linode.com/linode-platfo ... led-kernel

All this reminds me of the days when we had constrained memory on SIMMs on the 486 and some 3rd party commercial software for windows claimed to boost performance.

If your linode is SWAPPING due to load, this seriously might deserve a look in.


Cheers,

Luke


Last edited by hojuruku on Wed Jan 26, 2011 4:03 pm, edited 2 times in total.

Top
   
 Post subject: mysql tip
PostPosted: Wed Jan 26, 2011 11:38 am 
Offline
Senior Newbie

Joined: Thu May 27, 2010 4:09 pm
Posts: 8
Website: http://www.citizensombudsman.org
Location: Hong Kong
http://don.blogs.smugmug.com/2008/05/01 ... p-problem/

This ramzswap compares to regular swap in memory (tmpfs)

It's very advisable to have a swap device of some kind if you run mysql. It's more advisable to have a swap disk in ram with a higher priority.

ramzswap compares relatively well in performance.

Remember to use 4 ramdisks instead of one to make use of the 4 cpu cores linode gives us access to.


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 11:45 am 
Offline
Senior Newbie

Joined: Thu May 27, 2010 4:09 pm
Posts: 8
Website: http://www.citizensombudsman.org
Location: Hong Kong
oh and check out the backing device feature in ramzswap.

compressed IO to the linode disks. i'm recreating my single swap partition as 4 seperate xvd devices for a little more grunt ;)

like anything in performance there are tradeoffs. your trading cpu cycles for more efficent use of memory (assuming you NEED to swap).

PS. psandin told me linode doesn't use this on their hypervisor (xen dom0). they shouldn't either!


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 11:51 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
I highly doubt linode use it.

I'd be interested to see what performance gains you get (if any), let us know.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
PostPosted: Wed Jan 26, 2011 12:37 pm 
Offline
Senior Member

Joined: Fri Jan 09, 2009 5:32 pm
Posts: 634
hojuruku wrote:
I wonder if Linode is over-subscribing their server's memory transparently yet using this technology.

Please confirm or deny this on the record linode admins. I'm hoping the answer is NO but I'd just like to hear it from you guys.


That's right, admins, you better answer every crackpot theory about how you might be oversubscribing!


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 3:33 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
I was sold a Linode with 1.0 Jeds, but I've heard rumours that Linode does not have enough Jeds to supply every customer with a full Jed, and that they must be oversold. Please confirm or deny this on the record! How many Jeds are available at Linode?


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 3:37 pm 
Offline
Senior Member

Joined: Fri Dec 07, 2007 1:37 am
Posts: 385
Location: NC, USA
Linode has patched Xen to allow virtualization of Jeds - you appear to have your own Jed, even though it is actually shared among many linodes.

EDIT: I'm not sure linode has worked out the whole Jed compression thing, but I'm sure they are trying ;)


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 3:42 pm 
Offline
Senior Newbie

Joined: Thu May 27, 2010 4:09 pm
Posts: 8
Website: http://www.citizensombudsman.org
Location: Hong Kong
I've got this working in production with the init script i just patched for the sysfs configured zram.ko that replaces the in kernel ramzsawp.ko (broken on 2.6.35 at least with the latest user-space tools now redundant too)

It shouldn't be hard for you guys to knock up a kernel module from hg version (see the bug above) and modify the init script for your distro.

Other who have tried this seem happy so far.

Refer to the bug. You need something related to the Gentoo version or manually install from source if you want to use a module with a linode kernel 2.6.35.4 otherwise it wont work.

Keep whingeing or try it out. Feedback welcome.

EDIT: What is this jed compression thingy? something to do with a linode admin called jed?


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 4:44 pm 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
hojuruku wrote:
EDIT: What is this jed compression thingy? something to do with a linode admin called jed?

Image <-- Jed, Linode are trying to clone him and compress him so they can fit him into your linode's RAM give you uber support before you ask.

...Also if you google images for "Linode Jed" you get some reaally strange things (nsfw).

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 5:51 pm 
Offline
Senior Member

Joined: Sat Jun 05, 2004 12:49 am
Posts: 333
Quote:
Just use this if you want FASTER SWAP traded in for a smaller amount of memory. I think it sells itself


So you get faster bandwith on your swap partition, but since you have less ram you're going to be swapping more. Does the speed benefit actually outweigh the extra swapping?


Top
   
 Post subject:
PostPosted: Wed Jan 26, 2011 6:25 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
This isn't about getting faster swap, it's about fitting more into RAM.

See also: Connectix Ram Doubler, released 17 years ago. Touted as an alternative to Apple's virtual memory implementation (as Apple called swap in the early 90s), it took a two-tier approach, first extending existing RAM by compressing less used blocks, and then swapping those blocks to disk if it needed still more RAM. It's effectively the exact same thing as compcache, just almost two decades sooner.

Of course, I'm sure somebody will point out some similar software/memory manager that did this even earlier.


Top
   
 Post subject: face it
PostPosted: Thu Jan 27, 2011 3:37 am 
Offline
Senior Newbie

Joined: Thu May 27, 2010 4:09 pm
Posts: 8
Website: http://www.citizensombudsman.org
Location: Hong Kong
as i said before even android phones get a peformance boost. They have limited memory right?

http://linux-tipps.blogspot.com/2010/08 ... zswap.html

If you run mysql due to the nature of liinux you are going to swap at some point (see the link above). Do you want to swap to disk or use some faster memory.

I tested it using C++ compiling and here's the stats:

Code:
# zram_stats

/sys/block/zram3
disksize:           67108864
num_reads:               223
num_writes:             8928
invalid_io:                0
notify_free:               0
zero_pages:             4814
orig_data_size:     16846848
compr_data_size:     2132626
mem_used_total:      2252800
avg_compr_ratio:          12 %
mem_overhead:              5 %



When the backing feature comes back you'll have compressed access to a swap disk = less disk IO.

Zero pages are NOT written to disk. It's more intelligent swap too.

You could even run this for your /tmp partition , or uses it with a big instance of mcached. There possibilities are endless.

So you hit your CPU more, so what, you don't use it all the time. If your more memory constained than CPU you get more bang for your buck on your linode.

For other users you might get better compression.

Cheers,

Luke


Top
   
 Post subject:
PostPosted: Thu Jan 27, 2011 11:24 am 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
Compressed or not, you *want* a bunch of stuff to be paged to disk. Idle memory is as wasted as free memory; it can be used for caching.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group