Skip to content

Commit

Permalink
zbud: add to mm/
Browse files Browse the repository at this point in the history
zbud is an special purpose allocator for storing compressed pages.  It
is designed to store up to two compressed pages per physical page.
While this design limits storage density, it has simple and
deterministic reclaim properties that make it preferable to a higher
density approach when reclaim will be used.

zbud works by storing compressed pages, or "zpages", together in pairs
in a single memory page called a "zbud page".  The first buddy is "left
justifed" at the beginning of the zbud page, and the last buddy is
"right justified" at the end of the zbud page.  The benefit is that if
either buddy is freed, the freed buddy space, coalesced with whatever
slack space that existed between the buddies, results in the largest
possible free region within the zbud page.

zbud also provides an attractive lower bound on density.  The ratio of
zpages to zbud pages can not be less than 1.  This ensures that zbud can
never "do harm" by using more pages to store zpages than the
uncompressed zpages would have used on their own.

This implementation is a rewrite of the zbud allocator internally used
by zcache in the driver/staging tree.  The rewrite was necessary to
remove some of the zcache specific elements that were ingrained
throughout and provide a generic allocation interface that can later be
used by zsmalloc and others.

This patch adds zbud to mm/ for later use by zswap.

Signed-off-by: Seth Jennings <[email protected]>
Acked-by: Rik van Riel <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Nitin Gupta <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Dan Magenheimer <[email protected]>
Cc: Robert Jennings <[email protected]>
Cc: Jenifer Hopper <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Larry Woodman <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Cody P Schafer <[email protected]>
Cc: Hugh Dickens <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Bob Liu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Seth Jennings authored and torvalds committed Jul 11, 2013
1 parent bfffbea commit 4e2e277
Show file tree
Hide file tree
Showing 4 changed files with 560 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/linux/zbud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _ZBUD_H_
#define _ZBUD_H_

#include <linux/types.h>

struct zbud_pool;

struct zbud_ops {
int (*evict)(struct zbud_pool *pool, unsigned long handle);
};

struct zbud_pool *zbud_create_pool(gfp_t gfp, struct zbud_ops *ops);
void zbud_destroy_pool(struct zbud_pool *pool);
int zbud_alloc(struct zbud_pool *pool, int size, gfp_t gfp,
unsigned long *handle);
void zbud_free(struct zbud_pool *pool, unsigned long handle);
int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries);
void *zbud_map(struct zbud_pool *pool, unsigned long handle);
void zbud_unmap(struct zbud_pool *pool, unsigned long handle);
u64 zbud_get_pool_size(struct zbud_pool *pool);

#endif /* _ZBUD_H_ */
10 changes: 10 additions & 0 deletions mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ config FRONTSWAP

If unsure, say Y to enable frontswap.

config ZBUD
tristate
default n
help
A special purpose allocator for storing compressed pages.
It is designed to store up to two compressed pages per physical
page. While this design limits storage density, it has simple and
deterministic reclaim properties that make it preferable to a higher
density approach when reclaim will be used.

config MEM_SOFT_DIRTY
bool "Track memory changes"
depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY
Expand Down
1 change: 1 addition & 0 deletions mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
obj-$(CONFIG_CLEANCACHE) += cleancache.o
obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
obj-$(CONFIG_ZBUD) += zbud.o
Loading

0 comments on commit 4e2e277

Please sign in to comment.