diff options
author | Ariane van der Steldt <ariane@cvs.openbsd.org> | 2011-07-08 18:34:47 +0000 |
---|---|---|
committer | Ariane van der Steldt <ariane@cvs.openbsd.org> | 2011-07-08 18:34:47 +0000 |
commit | a8d4b6864e0e57ef6192934b61ae926236764cf0 (patch) | |
tree | 4acf819053dd5f8550dd25b7e6dc9f4f9046f861 | |
parent | 7aadd4828ef0e6d3084a01ff560d1fdf094121a6 (diff) |
Put in RLE logic for hibernate compressor.
These have the potential to compress 1MB of physmem into 1 byte.
This works by noting the page is not in use and therefor skipping it.
Needed by mlarkin@ for hibernate. No callers yet.
-rw-r--r-- | sys/kern/subr_hibernate.c | 35 | ||||
-rw-r--r-- | sys/sys/hibernate.h | 3 |
2 files changed, 36 insertions, 2 deletions
diff --git a/sys/kern/subr_hibernate.c b/sys/kern/subr_hibernate.c index 8c8c4ccfd46..c622e1a2cb8 100644 --- a/sys/kern/subr_hibernate.c +++ b/sys/kern/subr_hibernate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_hibernate.c,v 1.4 2011/07/08 18:31:16 ariane Exp $ */ +/* $OpenBSD: subr_hibernate.c,v 1.5 2011/07/08 18:34:46 ariane Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -451,3 +451,36 @@ found: uvm_unlock_fpageq(); return 0; } + +/* + * Physmem RLE compression support. + * + * Given a physical page address, it will return the number of pages + * starting at the address, that are free. + * Returns 0 if the page at addr is not free. + */ +psize_t +uvm_page_rle(paddr_t addr) +{ + struct vm_page *pg, *pg_end; + struct vm_physseg *vmp; + int pseg_idx, off_idx; + + pseg_idx = vm_physseg_find(atop(addr), &off_idx); + if (pseg_idx == -1) + return 0; + + vmp = &vm_physmem[pseg_idx]; + pg = &vmp->pgs[off_idx]; + if (!(pg->pg_flags & PQ_FREE)) + return 0; + + /* + * Search for the first non-free page after pg. + * Note that the page may not be the first page in a free pmemrange, + * therefore pg->fpgsz cannot be used. + */ + for (pg_end = pg; pg_end <= vmp->lastpg && + (pg_end->pg_flags & PQ_FREE) == PQ_FREE; pg_end++); + return pg_end - pg; +} diff --git a/sys/sys/hibernate.h b/sys/sys/hibernate.h index f4b0307179c..64fb36f9fee 100644 --- a/sys/sys/hibernate.h +++ b/sys/sys/hibernate.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hibernate.h,v 1.4 2011/07/08 18:31:16 ariane Exp $ */ +/* $OpenBSD: hibernate.h,v 1.5 2011/07/08 18:34:46 ariane Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -41,5 +41,6 @@ int hiballoc_init(struct hiballoc_arena*, void*, size_t len); void uvm_pmr_zero_everything(void); int uvm_pmr_alloc_pig(paddr_t*, psize_t); int uvm_pmr_alloc_piglet(paddr_t*, psize_t, paddr_t); +psize_t uvm_page_rle(paddr_t); #endif /* _SYS_HIBERNATE_H_ */ |