[lc-checkins] CVS: linux/mm/comp_cache minilzo.c,NONE,1.1 Makefile,1.7,1.8 adaptivity.c,1.19,1.20 au
Status: Beta
Brought to you by:
nitin_sf
|
From: Rodrigo S. de C. <rc...@us...> - 2002-05-29 21:28:58
|
Update of /cvsroot/linuxcompressed/linux/mm/comp_cache
In directory usw-pr-cvs1:/tmp/cvs-serv29510/mm/comp_cache
Modified Files:
Makefile adaptivity.c aux.c proc.c
Added Files:
minilzo.c
Log Message:
- Support for LZO compression algorithm is back
echo 2 > /proc/sys/vm/comp_cache/algorithm
- Now there is a /proc/comp_cache_hist that shows the free space histogram.
That histogram now also displays how many fragments the pages have, so you
have a better picture of what's going on in the compressed cache.
--- NEW FILE ---
/* minilzo.c -- mini subset of the LZO real-time data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
[...2809 lines suppressed...]
input_overrun:
*out_len = op - out;
return LZO_E_INPUT_OVERRUN;
#endif
#if defined(HAVE_NEED_OP)
output_overrun:
*out_len = op - out;
return LZO_E_OUTPUT_OVERRUN;
#endif
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
lookbehind_overrun:
*out_len = op - out;
return LZO_E_LOOKBEHIND_OVERRUN;
#endif
}
/***** End of minilzo.c *****/
Index: Makefile
===================================================================
RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/Makefile,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** Makefile 21 Mar 2002 19:24:17 -0000 1.7
--- Makefile 29 May 2002 21:28:54 -0000 1.8
***************
*** 7,11 ****
export-objs := swapin.o
! obj-y := main.o vswap.o free.o swapout.o swapin.o adaptivity.o aux.o proc.o WK4x4.o WKdm.o
include $(TOPDIR)/Rules.make
--- 7,11 ----
export-objs := swapin.o
! obj-y := main.o vswap.o free.o swapout.o swapin.o adaptivity.o aux.o proc.o WK4x4.o WKdm.o minilzo.o
include $(TOPDIR)/Rules.make
Index: adaptivity.c
===================================================================
RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/adaptivity.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** adaptivity.c 28 May 2002 19:16:15 -0000 1.19
--- adaptivity.c 29 May 2002 21:28:54 -0000 1.20
***************
*** 2,6 ****
* linux/mm/comp_cache/adaptivity.c
*
! * Time-stamp: <2002-05-28 15:44:25 rcastro>
*
* Linux Virtual Memory Compressed Cache
--- 2,6 ----
* linux/mm/comp_cache/adaptivity.c
*
! * Time-stamp: <2002-05-29 18:17:59 rcastro>
*
* Linux Virtual Memory Compressed Cache
***************
*** 25,28 ****
--- 25,30 ----
#define comp_cache_total_space (preset_comp_cache[i].size * PAGE_SIZE)
+
+ exter void comp_cache_fix_watermarks(int);
/***
Index: aux.c
===================================================================
RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/aux.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -r1.27 -r1.28
*** aux.c 29 May 2002 13:05:25 -0000 1.27
--- aux.c 29 May 2002 21:28:54 -0000 1.28
***************
*** 2,6 ****
* linux/mm/comp_cache/aux.c
*
! * Time-stamp: <2002-05-28 17:32:52 rcastro>
*
* Linux Virtual Memory Compressed Cache
--- 2,6 ----
* linux/mm/comp_cache/aux.c
*
! * Time-stamp: <2002-05-29 17:13:08 rcastro>
*
* Linux Virtual Memory Compressed Cache
***************
*** 165,171 ****
unsigned long
! free_space_count(int index) {
comp_cache_t * comp_page;
! unsigned long total;
if (index < 0)
--- 165,172 ----
unsigned long
! free_space_count(int index, unsigned long * num_fragments) {
comp_cache_t * comp_page;
! unsigned long total, total_fragments;
! struct list_head * fragment_lh;
if (index < 0)
***************
*** 174,179 ****
if (index >= free_space_hash_size)
BUG();
!
! for (comp_page = free_space_hash[index], total = 0; comp_page; comp_page = comp_page->next_hash, total++);
return total;
--- 175,190 ----
if (index >= free_space_hash_size)
BUG();
!
! for (comp_page = free_space_hash[index], total = 0; comp_page; comp_page = comp_page->next_hash, total++) {
! total_fragments = 0;
!
! for_each_fragment(fragment_lh, comp_page)
! total_fragments++;
!
! if (total_fragments > 3)
! num_fragments[3]++;
! else
! num_fragments[total_fragments]++;
! }
return total;
Index: proc.c
===================================================================
RCS file: /cvsroot/linuxcompressed/linux/mm/comp_cache/proc.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** proc.c 29 May 2002 13:05:26 -0000 1.11
--- proc.c 29 May 2002 21:28:55 -0000 1.12
***************
*** 2,6 ****
* linux/mm/comp_cache/proc.c
*
! * Time-stamp: <2002-05-28 17:56:39 rcastro>
*
* Linux Virtual Memory Compressed Cache
--- 2,6 ----
* linux/mm/comp_cache/proc.c
*
! * Time-stamp: <2002-05-29 18:16:35 rcastro>
*
* Linux Virtual Memory Compressed Cache
***************
*** 12,23 ****
#include <linux/comp_cache.h>
#include <linux/sysctl.h>
#include <linux/WKcommon.h>
#include <linux/WKdm.h>
#include <linux/WK4x4.h>
! #define NUM_ALGORITHMS 2
#define WKDM_IDX 0
#define WK4X4_IDX 1
extern unsigned long new_num_comp_pages, max_num_comp_pages, min_num_comp_pages;
--- 12,27 ----
#include <linux/comp_cache.h>
#include <linux/sysctl.h>
+ #include <linux/slab.h>
+ #include <linux/vmalloc.h>
#include <linux/WKcommon.h>
#include <linux/WKdm.h>
#include <linux/WK4x4.h>
+ #include <linux/minilzo.h>
! #define NUM_ALGORITHMS 3
#define WKDM_IDX 0
#define WK4X4_IDX 1
+ #define LZO_IDX 2
extern unsigned long new_num_comp_pages, max_num_comp_pages, min_num_comp_pages;
***************
*** 25,29 ****
static compression_algorithm_t compression_algorithms[NUM_ALGORITHMS];
static int algorithm_min = WKDM_IDX;
! static int algorithm_max = WK4X4_IDX;
static int current_algorithm;
--- 29,33 ----
static compression_algorithm_t compression_algorithms[NUM_ALGORITHMS];
static int algorithm_min = WKDM_IDX;
! static int algorithm_max = LZO_IDX;
static int current_algorithm;
***************
*** 41,44 ****
--- 45,50 ----
static DictionaryElement compresseddictionary[DICTIONARY_SIZE];
+ lzo_byte * wrkmem;
+
enum
{
***************
*** 146,153 ****
set_fragment_algorithm(comp_cache_fragment_t * fragment, unsigned short algorithm)
{
! if (algorithm == WKDM_IDX)
CompFragmentSetWKdm(fragment);
! else
CompFragmentSetWK4x4(fragment);
}
--- 152,196 ----
set_fragment_algorithm(comp_cache_fragment_t * fragment, unsigned short algorithm)
{
! switch (algorithm) {
! case WKDM_IDX:
CompFragmentSetWKdm(fragment);
! break;
! case WK4X4_IDX:
CompFragmentSetWK4x4(fragment);
+ break;
+ case LZO_IDX:
+ CompFragmentSetLZO(fragment);
+ break;
+ default:
+ BUG();
+ }
+ }
+
+ static unsigned int
+ lzo_wrapper_compress(unsigned long * from, unsigned long * to, unsigned int words, void * page)
+ {
+ int error;
+ lzo_uint out_len;
+
+ error = lzo1x_1_compress((lzo_byte *) from, words * sizeof(unsigned long), (lzo_byte *) to, &out_len, wrkmem);
+
+ if (error != LZO_E_OK)
+ BUG();
+
+ return out_len;
+ }
+
+ static void
+ lzo_wrapper_decompress(unsigned long * from, unsigned long * to, unsigned int words, void * page)
+ {
+ int error;
+ lzo_uint new_len;
+
+ error = lzo1x_decompress((lzo_byte *) from, ((comp_data_t *) page)->compressed_size, (lzo_byte *) to, &new_len, NULL);
+
+ if (error != LZO_E_OK || new_len != PAGE_SIZE) {
+ printk(KERN_EMERG "internal error - decompression failed: %d\n", error);
+ BUG();
+ }
}
***************
*** 174,185 ****
{
stats_page_t comp_page_stats;
void * from = page_address(fragment->comp_page->page) + fragment->offset;
void * to = page_address(page);
- unsigned int algorithm;
! if (CompFragmentWKdm(fragment))
! algorithm = WKDM_IDX;
! else
algorithm = WK4X4_IDX;
START_ZEN_TIME(comp_page_stats.myTimer);
--- 217,230 ----
{
stats_page_t comp_page_stats;
+ unsigned int algorithm = WKDM_IDX;
void * from = page_address(fragment->comp_page->page) + fragment->offset;
void * to = page_address(page);
! if (CompFragmentWK4x4(fragment))
algorithm = WK4X4_IDX;
+ else if (CompFragmentLZO(fragment)) {
+ algorithm = LZO_IDX;
+ comp_data.compressed_size = fragment->compressed_size;
+ }
START_ZEN_TIME(comp_page_stats.myTimer);
***************
*** 217,220 ****
--- 262,273 ----
compression_algorithms[WK4X4_IDX].comp = WK4x4_compress;
compression_algorithms[WK4X4_IDX].decomp = WK4x4_decompress;
+
+ strcpy(compression_algorithms[LZO_IDX].name, "LZO");
+ compression_algorithms[LZO_IDX].comp = lzo_wrapper_compress;
+ compression_algorithms[LZO_IDX].decomp = lzo_wrapper_decompress;
+
+ wrkmem = (lzo_byte *) kmalloc(LZO1X_1_MEM_COMPRESS, GFP_ATOMIC);
+ if (!wrkmem)
+ panic("comp_cache_algorithms_init(): cannot allocate wrkmem (for LZO)");
current_algorithm = WKDM_IDX;
***************
*** 237,241 ****
print_comp_cache_stats(unsigned short alg_idx, char * page, int * length)
{
! unsigned int compression_ratio, discard_ratio, i;
unsigned int mean_size, mean_comp_cycles, mean_decomp_cycles;
unsigned long total_comp_pages, total_wout_pages, total_decomp_pages, total_faultin_pages;
--- 290,294 ----
print_comp_cache_stats(unsigned short alg_idx, char * page, int * length)
{
! unsigned int compression_ratio, discard_ratio;
unsigned int mean_size, mean_comp_cycles, mean_decomp_cycles;
unsigned long total_comp_pages, total_wout_pages, total_decomp_pages, total_faultin_pages;
***************
*** 314,335 ****
stats->decomp_cycles_max,
mean_decomp_cycles);
!
! *length += sprintf(page + *length,
! "Free Space Histogram\n"
! " Zero: %8lu\n",
! free_space_count(0));
! for (i = 1; i < free_space_hash_size - 1; i += 2) {
! *length += sprintf(page + *length,
! " %4d - %4d: %8lu\n",
! (i+1)*100-200?:1, (i+1)*100,
! free_space_count(i) + free_space_count(i+1));
}
! *length += sprintf(page + *length,
! " Page Size: %8lu\n",
! free_space_count(free_space_hash_size - 1));
!
}
--- 367,423 ----
stats->decomp_cycles_max,
mean_decomp_cycles);
! }
! #define FRAGMENTS_PRINTK num_fragments[0], num_fragments[1], num_fragments[2], num_fragments[3], num_fragments[4]
! #define FRAGMENTS_COUNT 5
!
! int
! comp_cache_hist_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
! {
! unsigned long * num_fragments, total1, total2;
! int length = 0, i;
!
! num_fragments = (unsigned long *) vmalloc(FRAGMENTS_COUNT * sizeof(unsigned long));
!
! if (!num_fragments) {
! printk("couldn't allocate data structures for free space histogram\n");
! goto out;
}
! length = sprintf(page, "compressed cache - free space histogram\n");
!
! memset((void *) num_fragments, 0, FRAGMENTS_COUNT * sizeof(unsigned long));
!
! total1 = free_space_count(0, num_fragments);
! length += sprintf(page + length,
! " total 0f 1f 2f 3f more\n"
! " %4d: %8lu %5lu %5lu %5lu %5lu %5lu\n",
! 0,
! total1,
! FRAGMENTS_PRINTK);
!
! for (i = 1; i < free_space_hash_size - 1; i += 2) {
! memset((void *) num_fragments, 0, FRAGMENTS_COUNT * sizeof(unsigned long));
! total1 = free_space_count(i, num_fragments);
! total2 = free_space_count(i + 1, num_fragments);
!
! length += sprintf(page + length,
! "%4d - %4d: %8lu %5lu %5lu %5lu %5lu %5lu\n",
! (i+1)*100-200?:1, (i+1)*100, total1 + total2,
! FRAGMENTS_PRINTK);
! }
!
! memset((void *) num_fragments, 0, FRAGMENTS_COUNT * sizeof(unsigned long));
! total1 = free_space_count(free_space_hash_size - 1, num_fragments);
! length += sprintf(page + length,
! "%4d - %4d: %8lu %5lu %5lu %5lu %5lu %5lu\n",
! (free_space_hash_size - 2) * 100 + 1, (int) PAGE_SIZE,
! total1,
! FRAGMENTS_PRINTK);
!
! vfree(num_fragments);
! out:
! return proc_calc_metrics(page, start, off, count, eof, length);
}
|