[linux-mm-cc] First experience of compressed cache

John McCabe-Dansted gmatht at gmail.com
Fri Apr 25 01:59:22 EDT 2008


On Tue, Apr 1, 2008 at 9:19 PM, Nitin Gupta <nitingupta910 at gmail.com> wrote:
>  Exactly. Kernel assumes that its swapping to hard disk and doesn't
>  bother telling disk
>  that page is freed. I am holding changes to fix these issues till it
>  at least present code
>  get mainline.

In some pathological cases this may cause compcache to become larger
than the pages it stores; in which case something like the following
daemon may be useful:



#!/bin/sh
# This is a daemon that empties the compcache if it uses more memory
# than that useful pages it stores.
#
# This may help with compcache-0.3 as this version has no way of
# telling whether a page of swap is still in user.
# If pages were swapped out to compache but the kernel no longer
# needs swap compcache may hold onto useless pages.
# This would not be a problem when under severe memory pressure,
# as then the kernel would reuse the free memory pages.
# However under low memory pressure this script might increase
# the number of pages available to the file-cache.
#
# Be careful if using this script on swapless systems, as it may
# temporarily double the about of memory used and we do not free
# compcache until all pages stored are decompressed.

./use_compcache.sh
while true
do
  CurrentMem=`grep CurrentMem: /proc/compcache | sed s/[^0-9]//g`
  UsedSwap=`grep /dev/ramzswap0 /proc/swaps  | awk '{ print $4 }'`

  echo $CurrentMem , $UsedSwap

  if [ "$CurrentMem" -gt "$UsedSwap" ]
  then
    ./unuse_compcache.sh
    ./use_compcache.sh
    #We may wish to use the following instead
    #swapoff /dev/ramzswap0
    #rmmod compcache
    #modprobe compcache
    #swapon /dev/ramzswap0
  fi
  sleep 60
done



FYI, I did a quick test of this script with the following little c program:



/* A simple program to allocate "mb" million bytes of memory
 * Can be useful for testing vm systems such as compcache
 *
 * Uses calloc instead of malloc as kernel does not allocate
 * memory unless it is written to, and calloc writes zeros*/

int main() {
  char *b;
  int  mb=700;
  b=calloc(mb*1000000,1);
  return 0;
}



-- 
John C. McCabe-Dansted
PhD Student
University of Western Australia


More information about the linux-mm-cc mailing list