Skip to contentSkip to conversation

virtual block device driver (ramzswap)

PATCH In review Nitin Gupta 6 participants 20 messages Sep 9, 2009 – Sep 15, 2009 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/4 xvmalloc memory allocator

xvmalloc is a memory allocator designed specifically for ramzswap project.

* Features:
- Low metadata overhead (just 4 bytes per object)
- O(1) Alloc/Free - except when we have to call system page allocator to get additional memory.
- Very low fragmentation: In all tests, xvmalloc memory usage is within 12% of "Ideal".
- Pool based allocator: Each pool can grow and shrink.
- It maps pages only when required. So, it does not hog vmalloc area which is very small on 32-bit systems.

SLUB allocator could not be used due to fragmentation issues:
http://code.google.com/p/compcache/wiki/AllocatorsComparison
Data here shows kmalloc using ~43% more memory than TLSF and xvMalloc is showed ~2% more space efficiency than TLSF (due to smaller metadata). Creating various kmem_caches can reduce space efficiency gap but still problem of being limited to low memory exists. Also, it depends on allocating higher order pages to reduce fragmentation - this is not acceptable for ramzswap as it is used under memory crunch (its a swap device!).

SLOB allocator could not be used do to reasons mentioned here:
http://lkml.org/lkml/2009/3/18/210

* Implementation:
It uses two-level bitmap search to find free list containing block of correct size. This idea is taken from TLSF (Two-Level Segregate Fit) allocator and is well explained in its paper (see [Links] below).

* Limitations:
- Poor scalability: No per-cpu data structures (work in progress).

[Links]
1. Details and Performance data:
http://code.google.com/p/compcache/wiki/xvMalloc
http://code.google.com/p/compcache/wiki/xvMallocPerformance

2. TLSF memory allocator:
home: http://rtportal.upv.es/rtmalloc/
paper: http://rtportal.upv.es/rtmalloc/files/MRBC_2008.pdf

---

 drivers/block/ramzswap/xvmalloc.c     |  533 +++++++++++++++++++++++++++++++++
 drivers/block/ramzswap/xvmalloc.h     |   30 ++
 drivers/block/ramzswap/xvmalloc_int.h |   86 ++++++
 3 files changed, 649 insertions(+), 0 deletions(-)
drivers/block/ramzswap/xvmalloc.c new file +533 -0
new file mode 100644
index 0000000..12ad1a3
@@ -0,0 +1,533 @@
+/*
+ * xvmalloc memory allocator
+ *
+ * Copyright (C) 2008, 2009  Nitin Gupta
+ *
+ * This code is released using a dual license strategy: BSD/GPL
+ * You can choose the licence that better fits your requirements.
+ *
+ * Released under the terms of 3-clause BSD License
+ * Released under the terms of GNU General Public License Version 2.0
+ */
+
+#include <linux/bitops.h>
+#include <linux/errno.h>
+#include <linux/highmem.h>
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+
+#include "xvmalloc.h"
+#include "xvmalloc_int.h"
+
+static void stat_inc(u64 *value)
+{
+	*value = *value + 1;
+}
+
+static void stat_dec(u64 *value)
+{
+	*value = *value - 1;
+}
+
+static int test_flag(struct block_header *block, enum blockflags flag)
+{
+	return block->prev & BIT(flag);
+}
+
+static void set_flag(struct block_header *block, enum blockflags flag)
+{
+	block->prev |= BIT(flag);
+}
+
+static void clear_flag(struct block_header *block, enum blockflags flag)
+{
+	block->prev &= ~BIT(flag);
+}
+
+/*
+ * Given <page, offset> pair, provide a derefrencable pointer.
+ * This is called from xv_malloc/xv_free path, so it
+ * needs to be fast.
+ */
+static void *get_ptr_atomic(struct page *page, u16 offset, enum km_type type)
+{
+	unsigned char *base;
+
+	base = kmap_atomic(page, type);
+	return base + offset;
+}
+
+static void put_ptr_atomic(void *ptr, enum km_type type)
+{
+	kunmap_atomic(ptr, type);
+}
+
+static u32 get_blockprev(struct block_header *block)
+{
+	return block->prev & PREV_MASK;
+}
+
+static void set_blockprev(struct block_header *block, u16 new_offset)
+{
+	block->prev = new_offset | (block->prev & FLAGS_MASK);
+}
+
+static struct block_header *BLOCK_NEXT(struct block_header *block)
+{
+	return (struct block_header *)
+		((char *)block + block->size + XV_ALIGN);
+}
+
+/*
+ * Get index of free list containing blocks of maximum size
+ * which is less than or equal to given size.
+ */
+static u32 get_index_for_insert(u32 size)
+{
+	if (unlikely(size > XV_MAX_ALLOC_SIZE))
+		size = XV_MAX_ALLOC_SIZE;
+	size &= ~FL_DELTA_MASK;
+	return (size - XV_MIN_ALLOC_SIZE) >> FL_DELTA_SHIFT;
+}
+
+/*
+ * Get index of free list having blocks of size greater than
+ * or equal to requested size.
+ */
+static u32 get_index(u32 size)
+{
+	if (unlikely(size < XV_MIN_ALLOC_SIZE))
+		size = XV_MIN_ALLOC_SIZE;
+	size = ALIGN(size, FL_DELTA);
+	return (size - XV_MIN_ALLOC_SIZE) >> FL_DELTA_SHIFT;
+}
+
+/*
+ * Allocate a memory page. Called when a pool needs to grow.
+ */
+static struct page *xv_alloc_page(gfp_t flags)
+{
+	struct page *page;
+
+	page = alloc_page(flags);
+	if (unlikely(!page))
+		return 0;
+
+	return page;
+}
+
+/*
+ * Called when all objects in a page are freed.
+ */
+static void xv_free_page(struct page *page)
+{
+	__free_page(page);
+}
+
+/**
+ * find_block - find block of at least given size
+ * @pool: memory pool to search from
+ * @size: size of block required
+ * @page: page containing required block
+ * @offset: offset within the page where block is located.
+ *
+ * Searches two level bitmap to locate block of at least
+ * the given size. If such a block is found, it provides
+ * <page, offset> to identify this block and returns index
+ * in freelist where we found this block.
+ * Otherwise, returns 0 and <page, offset> params are not touched.
+ */
+static u32 find_block(struct xv_pool *pool, u32 size,
+			struct page **page, u32 *offset)
+{
+	ulong flbitmap, slbitmap;
+	u32 flindex, slindex, slbitstart;
+
+	/* There are no free blocks in this pool */
+	if (!pool->flbitmap)
+		return 0;
+
+	/* Get freelist index correspoding to this size */
+	slindex = get_index(size);
+	slbitmap = pool->slbitmap[slindex / BITS_PER_LONG];
+	slbitstart = slindex % BITS_PER_LONG;
+
+	/*
+	 * If freelist is not empty at this index, we found the
+	 * block - head of this list. This is approximate best-fit match.
+	 */
+	if (test_bit(slbitstart, &slbitmap)) {
+		*page = pool->freelist[slindex].page;
+		*offset = pool->freelist[slindex].offset;
+		return slindex;
+	}
+
+	/*
+	 * No best-fit found. Search a bit further in bitmap for a free block.
+	 * Second level bitmap consists of series of 32-bit chunks. Search
+	 * further in the chunk where we expected a best-fit, starting from
+	 * index location found above.
+	 */
+	slbitstart++;
+	slbitmap >>= slbitstart;
+
+	/* Skip this search if we were already at end of this bitmap chunk */
+	if ((slbitstart != BITS_PER_LONG) && slbitmap) {
+		slindex += __ffs(slbitmap) + 1;
+		*page = pool->freelist[slindex].page;
+		*offset = pool->freelist[slindex].offset;
+		return slindex;
+	}
+
+	/* Now do a full two-level bitmap search to find next nearest fit */
+	flindex = slindex / BITS_PER_LONG;
+
+	flbitmap = (pool->flbitmap) >> (flindex + 1);
+	if (!flbitmap)
+		return 0;
+
+	flindex += __ffs(flbitmap) + 1;
+	slbitmap = pool->slbitmap[flindex];
+	slindex = (flindex * BITS_PER_LONG) + __ffs(slbitmap);
+	*page = pool->freelist[slindex].page;
+	*offset = pool->freelist[slindex].offset;
+
+	return slindex;
+}
+
+/*
+ * Insert block at <page, offset> in freelist of given pool.
+ * freelist used depends on block size.
+ */
+static void insert_block(struct xv_pool *pool, struct page *page, u32 offset,
+			struct block_header *block)
+{
+	u32 flindex, slindex;
+	struct block_header *nextblock;
+
+	slindex = get_index_for_insert(block->size);
+	flindex = slindex / BITS_PER_LONG;
+
+	block->link.prev_page = 0;
+	block->link.prev_offset = 0;
+	block->link.next_page = pool->freelist[slindex].page;
+	block->link.next_offset = pool->freelist[slindex].offset;
+	pool->freelist[slindex].page = page;
+	pool->freelist[slindex].offset = offset;
+
+	if (block->link.next_page) {
+		nextblock = get_ptr_atomic(block->link.next_page,
+					block->link.next_offset, KM_USER1);
+		nextblock->link.prev_page = page;
+		nextblock->link.prev_offset = offset;
+		put_ptr_atomic(nextblock, KM_USER1);
+	}
+
+	__set_bit(slindex % BITS_PER_LONG, &pool->slbitmap[flindex]);
+	__set_bit(flindex, &pool->flbitmap);
+}
+
+/*
+ * Remove block from head of freelist. Index 'slindex' identifies the freelist.
+ */
+static void remove_block_head(struct xv_pool *pool,
+			struct block_header *block, u32 slindex)
+{
+	struct block_header *tmpblock;
+	u32 flindex = slindex / BITS_PER_LONG;
+
+	pool->freelist[slindex].page = block->link.next_page;
+	pool->freelist[slindex].offset = block->link.next_offset;
+	block->link.prev_page = 0;
+	block->link.prev_offset = 0;
+
+	if (!pool->freelist[slindex].page) {
+		__clear_bit(slindex % BITS_PER_LONG, &pool->slbitmap[flindex]);
+		if (!pool->slbitmap[flindex])
+			__clear_bit(flindex, &pool->flbitmap);
+	} else {
+		/*
+		 * DEBUG ONLY: We need not reinitialize freelist head previous
+		 * pointer to 0 - we never depend on its value. But just for
+		 * sanity, lets do it.
+		 */
+		tmpblock = get_ptr_atomic(pool->freelist[slindex].page,
+				pool->freelist[slindex].offset, KM_USER1);
+		tmpblock->link.prev_page = 0;
+		tmpblock->link.prev_offset = 0;
+		put_ptr_atomic(tmpblock, KM_USER1);
+	}
+}
+
+/*
+ * Remove block from freelist. Index 'slindex' identifies the freelist.
+ */
+static void remove_block(struct xv_pool *pool, struct page *page, u32 offset,
+			struct block_header *block, u32 slindex)
+{
+	u32 flindex;
+	struct block_header *tmpblock;
+
+	if (pool->freelist[slindex].page == page
+	   && pool->freelist[slindex].offset == offset) {
+		remove_block_head(pool, block, slindex);
+		return;
+	}
+
+	flindex = slindex / BITS_PER_LONG;
+
+	if (block->link.prev_page) {
+		tmpblock = get_ptr_atomic(block->link.prev_page,
+				block->link.prev_offset, KM_USER1);
+		tmpblock->link.next_page = block->link.next_page;
+		tmpblock->link.next_offset = block->link.next_offset;
+		put_ptr_atomic(tmpblock, KM_USER1);
+	}
+
+	if (block->link.next_page) {
+		tmpblock = get_ptr_atomic(block->link.next_page,
+				block->link.next_offset, KM_USER1);
+		tmpblock->link.prev_page = block->link.prev_page;
+		tmpblock->link.prev_offset = block->link.prev_offset;
+		put_ptr_atomic(tmpblock, KM_USER1);
+	}
+
+	return;
+}
+
+/*
+ * Allocate a page and add it freelist of given pool.
+ */
+static int grow_pool(struct xv_pool *pool, gfp_t flags)
+{
+	struct page *page;
+	struct block_header *block;
+
+	page = xv_alloc_page(flags);
+	if (unlikely(!page))
+		return -ENOMEM;
+
+	stat_inc(&pool->total_pages);
+
+	spin_lock(&pool->lock);
+	block = get_ptr_atomic(page, 0, KM_USER0);
+
+	block->size = PAGE_SIZE - XV_ALIGN;
+	set_flag(block, BLOCK_FREE);
+	clear_flag(block, PREV_FREE);
+	set_blockprev(block, 0);
+
+	insert_block(pool, page, 0, block);
+
+	put_ptr_atomic(block, KM_USER0);
+	spin_unlock(&pool->lock);
+
+	return 0;
+}
+
+/*
+ * Create a memory pool. Allocates freelist, bitmaps and other
+ * per-pool metadata.
+ */
+struct xv_pool *xv_create_pool(void)
+{
+	u32 ovhd_size;
+	struct xv_pool *pool;
+
+	ovhd_size = roundup(sizeof(*pool), PAGE_SIZE);
+	pool = kzalloc(ovhd_size, GFP_KERNEL);
+	if (!pool)
+		return NULL;
+
+	spin_lock_init(&pool->lock);
+
+	return pool;
+}
+
+void xv_destroy_pool(struct xv_pool *pool)
+{
+	kfree(pool);
+}
+
+/**
+ * xv_malloc - Allocate block of given size from pool.
+ * @pool: pool to allocate from
+ * @size: size of block to allocate
+ * @page: page no. that holds the object
+ * @offset: location of object within page
+ *
+ * On success, <page, offset> identifies block allocated
+ * and 0 is returned. On failure, <page, offset> is set to
+ * 0 and -ENOMEM is returned.
+ *
+ * Allocation requests with size > XV_MAX_ALLOC_SIZE will fail.
+ */
+int xv_malloc(struct xv_pool *pool, u32 size, struct page **page,
+		u32 *offset, gfp_t flags)
+{
+	int error;
+	u32 index, tmpsize, origsize, tmpoffset;
+	struct block_header *block, *tmpblock;
+
+	*page = NULL;
+	*offset = 0;
+	origsize = size;
+
+	if (unlikely(!size || size > XV_MAX_ALLOC_SIZE))
+		return -ENOMEM;
+
+	size = ALIGN(size, XV_ALIGN);
+
+	spin_lock(&pool->lock);
+
+	index = find_block(pool, size, page, offset);
+
+	if (!*page) {
+		spin_unlock(&pool->lock);
+		if (flags & GFP_NOWAIT)
+			return -ENOMEM;
+		error = grow_pool(pool, flags);
+		if (unlikely(error))
+			return -ENOMEM;
+
+		spin_lock(&pool->lock);
+		index = find_block(pool, size, page, offset);
+	}
+
+	if (!*page) {
+		spin_unlock(&pool->lock);
+		return -ENOMEM;
+	}
+
+	block = get_ptr_atomic(*page, *offset, KM_USER0);
+
+	remove_block_head(pool, block, index);
+
+	/* Split the block if required */
+	tmpoffset = *offset + size + XV_ALIGN;
+	tmpsize = block->size - size;
+	tmpblock = (struct block_header *)((char *)block + size + XV_ALIGN);
+	if (tmpsize) {
+		tmpblock->size = tmpsize - XV_ALIGN;
+		set_flag(tmpblock, BLOCK_FREE);
+		clear_flag(tmpblock, PREV_FREE);
+
+		set_blockprev(tmpblock, *offset);
+		if (tmpblock->size >= XV_MIN_ALLOC_SIZE)
+			insert_block(pool, *page, tmpoffset, tmpblock);
+
+		if (tmpoffset + XV_ALIGN + tmpblock->size != PAGE_SIZE) {
+			tmpblock = BLOCK_NEXT(tmpblock);
+			set_blockprev(tmpblock, tmpoffset);
+		}
+	} else {
+		/* This block is exact fit */
+		if (tmpoffset != PAGE_SIZE)
+			clear_flag(tmpblock, PREV_FREE);
+	}
+
+	block->size = origsize;
+	clear_flag(block, BLOCK_FREE);
+
+	put_ptr_atomic(block, KM_USER0);
+	spin_unlock(&pool->lock);
+
+	*offset += XV_ALIGN;
+
+	return 0;
+}
+
+/*
+ * Free block identified with <page, offset>
+ */
+void xv_free(struct xv_pool *pool, struct page *page, u32 offset)
+{
+	void *page_start;
+	struct block_header *block, *tmpblock;
+
+	offset -= XV_ALIGN;
+
+	spin_lock(&pool->lock);
+
+	page_start = get_ptr_atomic(page, 0, KM_USER0);
+	block = (struct block_header *)((char *)page_start + offset);
+
+	/* Catch double free bugs */
+	BUG_ON(test_flag(block, BLOCK_FREE));
+
+	block->size = ALIGN(block->size, XV_ALIGN);
+
+	tmpblock = BLOCK_NEXT(block);
+	if (offset + block->size + XV_ALIGN == PAGE_SIZE)
+		tmpblock = NULL;
+
+	/* Merge next block if its free */
+	if (tmpblock && test_flag(tmpblock, BLOCK_FREE)) {
+		/*
+		 * Blocks smaller than XV_MIN_ALLOC_SIZE
+		 * are not inserted in any free list.
+		 */
+		if (tmpblock->size >= XV_MIN_ALLOC_SIZE) {
+			remove_block(pool, page,
+				    offset + block->size + XV_ALIGN, tmpblock,
+				    get_index_for_insert(tmpblock->size));
+		}
+		block->size += tmpblock->size + XV_ALIGN;
+	}
+
+	/* Merge previous block if its free */
+	if (test_flag(block, PREV_FREE)) {
+		tmpblock = (struct block_header *)((char *)(page_start) +
+						get_blockprev(block));
+		offset = offset - tmpblock->size - XV_ALIGN;
+
+		if (tmpblock->size >= XV_MIN_ALLOC_SIZE)
+			remove_block(pool, page, offset, tmpblock,
+				    get_index_for_insert(tmpblock->size));
+
+		tmpblock->size += block->size + XV_ALIGN;
+		block = tmpblock;
+	}
+
+	/* No used objects in this page. Free it. */
+	if (block->size == PAGE_SIZE - XV_ALIGN) {
+		put_ptr_atomic(page_start, KM_USER0);
+		spin_unlock(&pool->lock);
+
+		xv_free_page(page);
+		stat_dec(&pool->total_pages);
+		return;
+	}
+
+	set_flag(block, BLOCK_FREE);
+	if (block->size >= XV_MIN_ALLOC_SIZE)
+		insert_block(pool, page, offset, block);
+
+	if (offset + block->size + XV_ALIGN != PAGE_SIZE) {
+		tmpblock = BLOCK_NEXT(block);
+		set_flag(tmpblock, PREV_FREE);
+		set_blockprev(tmpblock, offset);
+	}
+
+	put_ptr_atomic(page_start, KM_USER0);
+	spin_unlock(&pool->lock);
+
+	return;
+}
+
+u32 xv_get_object_size(void *obj)
+{
+	struct block_header *blk;
+
+	blk = (struct block_header *)((char *)(obj) - XV_ALIGN);
+	return blk->size;
+}
+
+/*
+ * Returns total memory used by allocator (userdata + metadata)
+ */
+u64 xv_get_total_size_bytes(struct xv_pool *pool)
+{
+	return pool->total_pages << PAGE_SHIFT;
+}
drivers/block/ramzswap/xvmalloc.h new file +30 -0
new file mode 100644
index 0000000..010c6fe
@@ -0,0 +1,30 @@
+/*
+ * xvmalloc memory allocator
+ *
+ * Copyright (C) 2008, 2009  Nitin Gupta
+ *
+ * This code is released using a dual license strategy: BSD/GPL
+ * You can choose the licence that better fits your requirements.
+ *
+ * Released under the terms of 3-clause BSD License
+ * Released under the terms of GNU General Public License Version 2.0
+ */
+
+#ifndef _XV_MALLOC_H_
+#define _XV_MALLOC_H_
+
+#include <linux/types.h>
+
+struct xv_pool;
+
+struct xv_pool *xv_create_pool(void);
+void xv_destroy_pool(struct xv_pool *pool);
+
+int xv_malloc(struct xv_pool *pool, u32 size, struct page **page,
+			u32 *offset, gfp_t flags);
+void xv_free(struct xv_pool *pool, struct page *page, u32 offset);
+
+u32 xv_get_object_size(void *obj);
+u64 xv_get_total_size_bytes(struct xv_pool *pool);
+
+#endif
drivers/block/ramzswap/xvmalloc_int.h new file +86 -0

86 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

PATCH 2/4 virtual block device driver (ramzswap)

In reply to a message not in the archive

Creates RAM based block devices (/dev/ramzswapX) which can be used (only) as swap disks. Pages swapped to these are compressed and stored in memory itself.

The module is called ramzswap.ko. It depends on:
- xvmalloc.ko: memory allocator
- lzo_compress.ko
- lzo_decompress.ko

See Documentation/blockdev/ramzswap.txt for usage details.

---

 drivers/block/Kconfig                 |   22 +
 drivers/block/Makefile                |    1 +
 drivers/block/ramzswap/Makefile       |    3 +
 drivers/block/ramzswap/ramzswap_drv.c | 1529 +++++++++++++++++++++++++++++++++
 drivers/block/ramzswap/ramzswap_drv.h |  183 ++++
 include/linux/ramzswap_ioctl.h        |   51 ++
 6 files changed, 1789 insertions(+), 0 deletions(-)
drivers/block/Kconfig +22 -0
index 1d886e0..4c2cac6 100644
@@ -381,6 +381,28 @@ config BLK_DEV_XIP
 	  will prevent RAM block device backing store memory from being
 	  allocated from highmem (only a problem for highmem systems).
 
+config BLK_DEV_RAMZSWAP
+	tristate "Compressed in-memory swap device"
+	depends on SWAP
+	select LZO_COMPRESS
+	select LZO_DECOMPRESS
+	default m
+	help
+	  Creates virtual block devices which can be used (only) as swap
+	  disks. Pages swapped to these disks are compressed and stored in
+	  memory itself.
+
+	  See Documentation/blockdev/ramzswap.txt for more information.
+	  Project home: http://compcache.googlecode.com/
+
+config BLK_DEV_RAMZSWAP_STATS
+	bool "Enable ramzswap stats"
+	depends on BLK_DEV_RAMZSWAP
+	default y
+	help
+	  Enable statistics collection for ramzswap. This adds only a minimal
+	  overhead. In unsure, say Y.
+
 config CDROM_PKTCDVD
 	tristate "Packet writing on CD/DVD media"
 	depends on !UML
drivers/block/Makefile +1 -0
index cdaa3f8..174efcc 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_PS3_VRAM)		+= ps3vram.o
 obj-$(CONFIG_ATARI_FLOPPY)	+= ataflop.o
 obj-$(CONFIG_AMIGA_Z2RAM)	+= z2ram.o
 obj-$(CONFIG_BLK_DEV_RAM)	+= brd.o
+obj-$(CONFIG_BLK_DEV_RAMZSWAP)	+= ramzswap/
 obj-$(CONFIG_BLK_DEV_LOOP)	+= loop.o
 obj-$(CONFIG_BLK_DEV_XD)	+= xd.o
 obj-$(CONFIG_BLK_CPQ_DA)	+= cpqarray.o
drivers/block/ramzswap/Makefile new file +3 -0
new file mode 100644
index 0000000..94e99b5
@@ -0,0 +1,3 @@
+ramzswap-objs	:=	ramzswap_drv.o xvmalloc.o
+
+obj-$(CONFIG_BLK_DEV_RAMZSWAP)	+=	ramzswap.o
drivers/block/ramzswap/ramzswap_drv.c new file +1529 -0

1,529 lines not on this page · raw message

drivers/block/ramzswap/ramzswap_drv.h new file +183 -0

183 lines not on this page · raw message

include/linux/ramzswap_ioctl.h new file +51 -0

51 lines not on this page · raw message

#3 lore raw

Hi Nitin,

I am not a block driver expert but here are some comments on the code that probably need to be addressed before merging.

Pekka

Quoted 37 lines · Nitin Gupta
drivers/block/ramzswap/ramzswap_drv.c new file +36 -0
@@ -0,0 +1,1529 @@
+/*
+ * Compressed RAM based swap device
+ *
+ * Copyright (C) 2008, 2009  Nitin Gupta
+ *
+ * This code is released using a dual license strategy: BSD/GPL
+ * You can choose the licence that better fits your requirements.
+ *
+ * Released under the terms of 3-clause BSD License
+ * Released under the terms of GNU General Public License Version 2.0
+ *
+ * Project home: http://compcache.googlecode.com
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/blkdev.h>
+#include <linux/buffer_head.h>
+#include <linux/device.h>
+#include <linux/genhd.h>
+#include <linux/highmem.h>
+#include <linux/lzo.h>
+#include <linux/marker.h>
+#include <linux/mutex.h>
+#include <linux/string.h>
+#include <linux/swap.h>
+#include <linux/swapops.h>
+#include <linux/vmalloc.h>
+#include <linux/version.h>
+
+#include "ramzswap_drv.h"
+
+/* Globals */
+static int RAMZSWAP_MAJOR;
+static struct ramzswap *DEVICES;

drivers/block/ramzswap/ramzswap_drv.c line 46

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+/*
+ * Pages that compress to larger than this size are
+ * forwarded to backing swap, if present or stored
+ * uncompressed in memory otherwise.
+ */
+static unsigned int MAX_CPAGE_SIZE;
+
+/* Module params (documentation at end) */
+static unsigned long NUM_DEVICES;

These variable names should be in lower case.

drivers/block/ramzswap/ramzswap_drv.c line 55

Quoted 9 lines
drivers/block/ramzswap/ramzswap_drv.c new file +9 -0
+
+/* Function declarations */
+static int __init ramzswap_init(void);
+static int ramzswap_ioctl(struct block_device *, fmode_t,
+                       unsigned, unsigned long);
+static int setup_swap_header(struct ramzswap *, union swap_header *);
+static void ramzswap_set_memlimit(struct ramzswap *, size_t);
+static void ramzswap_set_disksize(struct ramzswap *, size_t);
+static void reset_device(struct ramzswap *rzs);

It's preferable not to use forward declarations in new kernel code.

Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+static int test_flag(struct ramzswap *rzs, u32 index, enum rzs_pageflags flag)
+{
+       return rzs->table[index].flags & BIT(flag);
+}
+

drivers/block/ramzswap/ramzswap_drv.c line 76

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+static void set_flag(struct ramzswap *rzs, u32 index, enum rzs_pageflags flag)
+{
+       rzs->table[index].flags |= BIT(flag);
+}
+
+static void clear_flag(struct ramzswap *rzs, u32 index,
+                                       enum rzs_pageflags flag)
+{
+       rzs->table[index].flags &= ~BIT(flag);
+}

These function names could use a ramzswap specific prefix.

Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+
+static int page_zero_filled(void *ptr)
+{
+       u32 pos;
+       u64 *page;

drivers/block/ramzswap/ramzswap_drv.c line 91

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+       page = (u64 *)ptr;
+
+       for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
+               if (page[pos])
+                       return 0;
+       }
+
+       return 1;
+}

This looks like something that could be in lib/string.c.

/me looks

There's strspn so maybe you could introduce a memspn equivalent.

Quoted 6 lines
drivers/block/ramzswap/ramzswap_drv.c new file +6 -0
+
+/*
+ * Given <pagenum, offset> pair, provide a dereferencable pointer.
+ */
+static void *get_ptr_atomic(struct page *page, u16 offset, enum km_type type)
+{

drivers/block/ramzswap/ramzswap_drv.c line 107

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+       unsigned char *base;
+
+       base = kmap_atomic(page, type);
+       return base + offset;
+}
+
+static void put_ptr_atomic(void *ptr, enum km_type type)
+{
+       kunmap_atomic(ptr, type);
+}

These two functions also appear in xmalloc. It's probably best to just kill the wrappers and use kmap/kunmap directly.

Quoted 12 lines
drivers/block/ramzswap/ramzswap_drv.c new file +12 -0
+
+static void ramzswap_flush_dcache_page(struct page *page)
+{
+#ifdef CONFIG_ARM
+       int flag = 0;
+       /*
+        * Ugly hack to get flush_dcache_page() work on ARM.
+        * page_mapping(page) == NULL after clearing this swap cache flag.
+        * Without clearing this flag, flush_dcache_page() will simply set
+        * "PG_dcache_dirty" bit and return.
+        */
+       if (PageSwapCache(page)) {

drivers/block/ramzswap/ramzswap_drv.c line 129

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+               flag = 1;
+               ClearPageSwapCache(page);
+       }
+#endif
+       flush_dcache_page(page);
+#ifdef CONFIG_ARM
+       if (flag)
+               SetPageSwapCache(page);
+#endif
+}

The above CONFIG_ARM magic really has no place in drivers/block.

Quoted 22 lines
drivers/block/ramzswap/ramzswap_drv.c new file +22 -0
+static int add_backing_swap_extent(struct ramzswap *rzs,
+                               pgoff_t phy_pagenum,
+                               pgoff_t num_pages)
+{
+       unsigned int idx;
+       struct list_head *head;
+       struct page *curr_page, *new_page;
+       unsigned int extents_per_page = PAGE_SIZE /
+                               sizeof(struct ramzswap_backing_extent);
+
+       idx = rzs->num_extents % extents_per_page;
+       if (!idx) {
+               new_page = alloc_page(__GFP_ZERO);
+               if (!new_page)
+                       return -ENOMEM;
+
+               if (rzs->num_extents) {
+                       curr_page = virt_to_page(rzs->curr_extent);
+                       head = &curr_page->lru;
+               } else {
+                       head = &rzs->backing_swap_extent_list;
+               }

drivers/block/ramzswap/ramzswap_drv.c line 213

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+               list_add(&new_page->lru, head);
+               rzs->curr_extent = page_address(new_page);
+       }
+
+       rzs->curr_extent->phy_pagenum = phy_pagenum;
+       rzs->curr_extent->num_pages = num_pages;
+
+       pr_debug(C "extent: [%lu, %lu] %lu\n", phy_pagenum,
+               phy_pagenum + num_pages - 1, num_pages);

What's this "C" thing everywhere? A subsystem prefix? Shouldn't you override pr_fmt() instead?

Quoted 27 lines
drivers/block/ramzswap/ramzswap_drv.c new file +27 -0
+static int ramzswap_write(struct ramzswap *rzs, struct bio *bio)
+{
+       int ret, fwd_write_request = 0;
+       u32 offset;
+       size_t clen;
+       pgoff_t index;
+       struct zobj_header *zheader;
+       struct page *page, *page_store;
+       unsigned char *user_mem, *cmem, *src;
+
+       stat_inc(rzs->stats.num_writes);
+
+       page = bio->bi_io_vec[0].bv_page;
+       index = bio->bi_sector >> SECTORS_PER_PAGE_SHIFT;
+
+       src = rzs->compress_buffer;
+
+       /*
+        * System swaps to same sector again when the stored page
+        * is no longer referenced by any process. So, its now safe
+        * to free the memory that was allocated for this page.
+        */
+       if (rzs->table[index].page)
+               ramzswap_free_page(rzs, index);
+
+       /*
+        * No memory ia allocated for zero filled pages.

drivers/block/ramzswap/ramzswap_drv.c line 781

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+        * Simply clear zero page flag.
+        */
+       if (test_flag(rzs, index, RZS_ZERO)) {
+               stat_dec(rzs->stats.pages_zero);
+               clear_flag(rzs, index, RZS_ZERO);
+       }
+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

Quoted 80 lines
drivers/block/ramzswap/ramzswap_drv.c new file +80 -0
+
+       user_mem = get_ptr_atomic(page, 0, KM_USER0);
+       if (page_zero_filled(user_mem)) {
+               put_ptr_atomic(user_mem, KM_USER0);
+               mutex_unlock(&rzs->lock);
+               stat_inc(rzs->stats.pages_zero);
+               set_flag(rzs, index, RZS_ZERO);
+
+               set_bit(BIO_UPTODATE, &bio->bi_flags);
+               bio_endio(bio, 0);
+               return 0;
+       }
+
+       if (rzs->backing_swap &&
+               (rzs->stats.compr_size > rzs->memlimit - PAGE_SIZE)) {
+               put_ptr_atomic(user_mem, KM_USER0);
+               mutex_unlock(&rzs->lock);
+               fwd_write_request = 1;
+               goto out;
+       }
+
+       ret = lzo1x_1_compress(user_mem, PAGE_SIZE, src, &clen,
+                               rzs->compress_workmem);
+
+       put_ptr_atomic(user_mem, KM_USER0);
+
+       if (unlikely(ret != LZO_E_OK)) {
+               mutex_unlock(&rzs->lock);
+               pr_err(C "Compression failed! err=%d\n", ret);
+               stat_inc(rzs->stats.failed_writes);
+               goto out;
+       }
+
+       /*
+        * Page is incompressible. Forward it to backing swap
+        * if present. Otherwise, store it as-is (uncompressed)
+        * since we do not want to return too many swap write
+        * errors which has side effect of hanging the system.
+        */
+       if (unlikely(clen > MAX_CPAGE_SIZE)) {
+               if (rzs->backing_swap) {
+                       mutex_unlock(&rzs->lock);
+                       fwd_write_request = 1;
+                       goto out;
+               }
+
+               clen = PAGE_SIZE;
+               page_store = alloc_page(GFP_NOIO | __GFP_HIGHMEM);
+               if (unlikely(!page_store)) {
+                       mutex_unlock(&rzs->lock);
+                       pr_info(C "Error allocating memory for incompressible "
+                               "page: %lu\n", index);
+                       stat_inc(rzs->stats.failed_writes);
+                       goto out;
+               }
+
+               offset = 0;
+               set_flag(rzs, index, RZS_UNCOMPRESSED);
+               stat_inc(rzs->stats.pages_expand);
+               rzs->table[index].page = page_store;
+               src = get_ptr_atomic(page, 0, KM_USER0);
+               goto memstore;
+       }
+
+       if (xv_malloc(rzs->mem_pool, clen + sizeof(*zheader),
+                       &rzs->table[index].page, &offset,
+                       GFP_NOIO | __GFP_HIGHMEM)) {
+               mutex_unlock(&rzs->lock);
+               pr_info(C "Error allocating memory for compressed "
+                       "page: %lu, size=%zu\n", index, clen);
+               stat_inc(rzs->stats.failed_writes);
+               if (rzs->backing_swap)
+                       fwd_write_request = 1;
+               goto out;
+       }
+
+memstore:
+       rzs->table[index].offset = offset;
+
+       cmem = get_ptr_atomic(rzs->table[index].page,

drivers/block/ramzswap/ramzswap_drv.c line 871

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+                       rzs->table[index].offset, KM_USER1);
+
+#if 0
+       /* Back-reference needed for memory defragmentation */
+       if (!test_flag(rzs, index, RZS_UNCOMPRESSED)) {
+               zheader = (struct zobj_header *)cmem;
+               zheader->table_idx = index;
+               cmem += sizeof(*zheader);
+       }
+#endif

Drop the above dead code?

Quoted 24 lines
drivers/block/ramzswap/ramzswap_drv.c new file +24 -0
+
+       memcpy(cmem, src, clen);
+
+       put_ptr_atomic(cmem, KM_USER1);
+       if (unlikely(test_flag(rzs, index, RZS_UNCOMPRESSED)))
+               put_ptr_atomic(src, KM_USER0);
+
+       /* Update stats */
+       rzs->stats.compr_size += clen;
+       stat_inc(rzs->stats.pages_stored);
+       stat_inc_if_less(rzs->stats.good_compress, clen, PAGE_SIZE / 2 + 1);
+
+       mutex_unlock(&rzs->lock);
+
+       set_bit(BIO_UPTODATE, &bio->bi_flags);
+       bio_endio(bio, 0);
+       return 0;
+
+out:
+       if (fwd_write_request) {
+               stat_inc(rzs->stats.bdev_num_writes);
+               bio->bi_bdev = rzs->backing_swap;
+#if 0
+               /*

drivers/block/ramzswap/ramzswap_drv.c line 905

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+                * TODO: We currently have linear mapping of ramzswap and
+                * backing swap sectors. This is not desired since we want
+                * to optimize writes to backing swap to minimize disk seeks
+                * or have effective wear leveling (for SSDs). Also, a
+                * non-linear mapping is required to implement compressed
+                * on-disk swapping.
+                */
+                bio->bi_sector = get_backing_swap_page()
+                                       << SECTORS_PER_PAGE_SHIFT;
+#endif

This too?

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+static int ramzswap_ioctl_init_device(struct ramzswap *rzs)
+{
+       int ret;
+       size_t num_pages, totalram_bytes;
+       struct sysinfo i;
+       struct page *page;
+       union swap_header *swap_header;
+
+       if (rzs->init_done) {
+               pr_info(C "Device already initialized!\n");

drivers/block/ramzswap/ramzswap_drv.c line 974

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+               return -EBUSY;
+       }
+
+       ret = setup_backing_swap(rzs);
+       if (ret)
+               goto fail;
+
+       si_meminfo(&i);
+       /* Here is a trivia: guess unit used for i.totalram !! */
+       totalram_bytes = i.totalram << PAGE_SHIFT;

You can use totalram_pages here. OTOH, I'm not sure why the driver needs this information. Hmm?

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+
+       if (rzs->backing_swap)
+               ramzswap_set_memlimit(rzs, totalram_bytes);
+       else

drivers/block/ramzswap/ramzswap_drv.c line 988

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+               ramzswap_set_disksize(rzs, totalram_bytes);
+
+       rzs->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
+       if (rzs->compress_workmem == NULL) {
+               pr_err(C "Error allocating compressor working memory!\n");
+               ret = -ENOMEM;
+               goto fail;
+       }
+
+       rzs->compress_buffer = kzalloc(2 * PAGE_SIZE, GFP_KERNEL);

Use alloc_pages(__GFP_ZERO) here?

drivers/block/ramzswap/ramzswap_drv.h line 72

Quoted 11 lines
drivers/block/ramzswap/ramzswap_drv.h new file +5 -0
new file mode 100644
index 0000000..7f77edc
 
+
+#define SECTOR_SHIFT           9
+#define SECTOR_SIZE            (1 << SECTOR_SHIFT)
+#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
+#define SECTORS_PER_PAGE       (1 << SECTORS_PER_PAGE_SHIFT)

Don't we have these defines somewhere in include/linux?

drivers/block/ramzswap/ramzswap_drv.h line 75

Quoted 3 lines
drivers/block/ramzswap/ramzswap_drv.h new file +3 -0
+
+/* Message prefix */
+#define C "ramzswap: "

Use pr_fmt() instead.

drivers/block/ramzswap/ramzswap_drv.h line 78

Quoted 3 lines
drivers/block/ramzswap/ramzswap_drv.h new file +3 -0
+
+/* Debugging and Stats */
+#define NOP    do { } while (0)

Huh? Drop this.

drivers/block/ramzswap/ramzswap_drv.h line 82

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.h new file +4 -0
+
+#if defined(CONFIG_BLK_DEV_RAMZSWAP_STATS)
+#define STATS
+#endif

Why can't you rename that to CONFIG_RAMZSWAP_STATS and use that instead of the very generic STATS?

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.h new file +4 -0
+
+#if defined(STATS)
+#define stat_inc(stat)                 ((stat)++)
+#define stat_dec(stat)                 ((stat)--)

drivers/block/ramzswap/ramzswap_drv.h line 96

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.h new file +10 -0
+#define stat_inc_if_less(stat, val1, val2) \
+                               ((stat) += ((val1) < (val2) ? 1 : 0))
+#define stat_dec_if_less(stat, val1, val2) \
+                               ((stat) -= ((val1) < (val2) ? 1 : 0))
+#else  /* STATS */
+#define stat_inc(x)                    NOP
+#define stat_dec(x)                    NOP
+#define stat_inc_if_less(x, v1, v2)    NOP
+#define stat_dec_if_less(x, v1, v2)    NOP
+#endif /* STATS */

Why do you need inc_if_less() and dec_if_less()? And why are these not static inlines?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Hi Pekka,

Thanks for review. My comments inline.

Quoted 8 lines · Pekka Enberg

I am not a block driver expert but here are some comments on the code that probably need to be addressed before merging.

                       Pekka

On Thu, Sep 10, 2009 at 12:19 AM, Nitin Gupta <[email protected]> wrote:

Quoted 17 lines
Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+
+/* Globals */
+static int RAMZSWAP_MAJOR;
+static struct ramzswap *DEVICES;

drivers/block/ramzswap/ramzswap_drv.c line 46

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+/*
+ * Pages that compress to larger than this size are
+ * forwarded to backing swap, if present or stored
+ * uncompressed in memory otherwise.
+ */
+static unsigned int MAX_CPAGE_SIZE;
+
+/* Module params (documentation at end) */
+static unsigned long NUM_DEVICES;

These variable names should be in lower case.

Global variables with lower case causes confusion.

Quoted 12 lines

drivers/block/ramzswap/ramzswap_drv.c line 55

Quoted 9 lines
drivers/block/ramzswap/ramzswap_drv.c new file +9 -0
+
+/* Function declarations */
+static int __init ramzswap_init(void);
+static int ramzswap_ioctl(struct block_device *, fmode_t,
+                       unsigned, unsigned long);
+static int setup_swap_header(struct ramzswap *, union swap_header *);
+static void ramzswap_set_memlimit(struct ramzswap *, size_t);
+static void ramzswap_set_disksize(struct ramzswap *, size_t);
+static void reset_device(struct ramzswap *rzs);

It's preferable not to use forward declarations in new kernel code.

okay, I will rearrange functions to avoid this.

Quoted 9 lines
Quoted 9 lines
drivers/block/ramzswap/ramzswap_drv.c new file +9 -0
+static int test_flag(struct ramzswap *rzs, u32 index, enum rzs_pageflags flag)
+{
+       return rzs->table[index].flags & BIT(flag);
+}
+
+static void set_flag(struct ramzswap *rzs, u32 index, enum rzs_pageflags flag)
+{
+       rzs->table[index].flags |= BIT(flag);
+}
Quoted 8 lines

drivers/block/ramzswap/ramzswap_drv.c line 76

Quoted 6 lines
drivers/block/ramzswap/ramzswap_drv.c new file +6 -0
+
+static void clear_flag(struct ramzswap *rzs, u32 index,
+                                       enum rzs_pageflags flag)
+{
+       rzs->table[index].flags &= ~BIT(flag);
+}

These function names could use a ramzswap specific prefix.

okay.

Quoted 19 lines
Quoted 6 lines
drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+
+static int page_zero_filled(void *ptr)
+{
+       u32 pos;
+       u64 *page;

drivers/block/ramzswap/ramzswap_drv.c line 91

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+       page = (u64 *)ptr;
+
+       for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
+               if (page[pos])
+                       return 0;
+       }
+
+       return 1;
+}

This looks like something that could be in lib/string.c.

Quoted 4 lines

/me looks

There's strspn so maybe you could introduce a memspn equivalent.

Maybe this is just too specific to this driver. Who else will use it? So, this simple function should stay within this driver only. If it finds more user,
we can them move it to lib/string.c.

If I now move it to string.c I am sure I will get reverse argument from someone else:
"currently, it has no other users so bury it with this driver only".

Quoted 11 lines
Quoted 11 lines
drivers/block/ramzswap/ramzswap_drv.c new file +11 -0
+
+/*
+ * Given <pagenum, offset> pair, provide a dereferencable pointer.
+ */
+static void *get_ptr_atomic(struct page *page, u16 offset, enum km_type type)
+{
+       unsigned char *base;
+
+       base = kmap_atomic(page, type);
+       return base + offset;
+}
Quoted 9 lines

drivers/block/ramzswap/ramzswap_drv.c line 107

Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+
+static void put_ptr_atomic(void *ptr, enum km_type type)
+{
+       kunmap_atomic(ptr, type);
+}

These two functions also appear in xmalloc. It's probably best to just kill the wrappers and use kmap/kunmap directly.

Wrapper for kmap_atomic is nice as spreading:
kmap_atomic(page, KM_USER0,1) + offset everywhere looks worse. What is the problem if these little 1-liner wrappers are repeated in xvmalloc too?
To me, they just add some clarity.

Quoted 16 lines
Quoted 16 lines
drivers/block/ramzswap/ramzswap_drv.c new file +16 -0
+
+static void ramzswap_flush_dcache_page(struct page *page)
+{
+#ifdef CONFIG_ARM
+       int flag = 0;
+       /*
+        * Ugly hack to get flush_dcache_page() work on ARM.
+        * page_mapping(page) == NULL after clearing this swap cache flag.
+        * Without clearing this flag, flush_dcache_page() will simply set
+        * "PG_dcache_dirty" bit and return.
+        */
+       if (PageSwapCache(page)) {
+               flag = 1;
+               ClearPageSwapCache(page);
+       }
+#endif
Quoted 9 lines

drivers/block/ramzswap/ramzswap_drv.c line 129

Quoted 6 lines

+       flush_dcache_page(page);

drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+#ifdef CONFIG_ARM
+       if (flag)
+               SetPageSwapCache(page);
+#endif
+}

The above CONFIG_ARM magic really has no place in drivers/block.

Please read the comment above this hack to see why its needed. Also, for details see this mail:
http://www.linux-mips.org/archives/linux-mips/2008-11/msg00038.html

No one replied to above mail. So, I though just to temporarily introduce this hack while someone makes a proper fix for ARM (I will probably ping ARM/MIPS folks again for this).

Without this hack, ramzswap simply won't work on ARM. See:
http://code.google.com/p/compcache/issues/detail?id=33

So, its extremely difficult to wait for the _proper_ fix.

Quoted 7 lines
Quoted 3 lines

+
+       pr_debug(C "extent: [%lu, %lu] %lu\n", phy_pagenum,
+               phy_pagenum + num_pages - 1, num_pages);

What's this "C" thing everywhere? A subsystem prefix? Shouldn't you override pr_fmt() instead?

Yes, "C" is subsystem prefix. Will now override pr_fmt() instead.

Quoted 8 lines
Quoted 4 lines

+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

Quoted 10 lines

drivers/block/ramzswap/ramzswap_drv.c line 871

Quoted 8 lines
drivers/block/ramzswap/ramzswap_drv.c new file +8 -0
+#if 0
+       /* Back-reference needed for memory defragmentation */
+       if (!test_flag(rzs, index, RZS_UNCOMPRESSED)) {
+               zheader = (struct zobj_header *)cmem;
+               zheader->table_idx = index;
+               cmem += sizeof(*zheader);
+       }
+#endif

Drop the above dead code?

This is a reminder for me that every object has to contain this header ultimately
and hence object data does not start immediately from start of chunk.

More than the dead code, the comment adds more value to it. So lets keep it.

Quoted 29 lines
Quoted 29 lines
drivers/block/ramzswap/ramzswap_drv.c new file +28 -0
+
+       memcpy(cmem, src, clen);
+
+       put_ptr_atomic(cmem, KM_USER1);
+       if (unlikely(test_flag(rzs, index, RZS_UNCOMPRESSED)))
+               put_ptr_atomic(src, KM_USER0);
+
+       /* Update stats */
+       rzs->stats.compr_size += clen;
+       stat_inc(rzs->stats.pages_stored);
+       stat_inc_if_less(rzs->stats.good_compress, clen, PAGE_SIZE / 2 + 1);
+
+       mutex_unlock(&rzs->lock);
+
+       set_bit(BIO_UPTODATE, &bio->bi_flags);
+       bio_endio(bio, 0);
+       return 0;
+
+out:
+       if (fwd_write_request) {
+               stat_inc(rzs->stats.bdev_num_writes);
+               bio->bi_bdev = rzs->backing_swap;
+#if 0
+               /*
+                * TODO: We currently have linear mapping of ramzswap and
+                * backing swap sectors. This is not desired since we want
+                * to optimize writes to backing swap to minimize disk seeks
+                * or have effective wear leveling (for SSDs). Also, a
Quoted 9 lines
Quoted 6 lines

+                * non-linear mapping is required to implement compressed
+                * on-disk swapping.
+                */
+                bio->bi_sector = get_backing_swap_page()
+                                       << SECTORS_PER_PAGE_SHIFT; +#endif

This too?

Again, I want to retain this comment. Its very important for me. So, I prefer to keep this small bit of dead code.

Quoted 15 lines
Quoted 15 lines
drivers/block/ramzswap/ramzswap_drv.c new file +15 -0
+static int ramzswap_ioctl_init_device(struct ramzswap *rzs)
+{
+       int ret;
+       size_t num_pages, totalram_bytes;
+       struct sysinfo i;
+       struct page *page;
+       union swap_header *swap_header;
+
+       if (rzs->init_done) {
+               pr_info(C "Device already initialized!\n");
+               return -EBUSY;
+       }
+
+       ret = setup_backing_swap(rzs);
+       if (ret)
Quoted 9 lines
Quoted 5 lines

+               goto fail;
+
+       si_meminfo(&i);
+       /* Here is a trivia: guess unit used for i.totalram !! */
+       totalram_bytes = i.totalram << PAGE_SHIFT;

You can use totalram_pages here. OTOH, I'm not sure why the driver needs this information. Hmm?

The driver sets 'disksize' as 25% of RAM by default. So, it needs to know how much RAM the system has.

Quoted 8 lines
Quoted 8 lines
drivers/block/ramzswap/ramzswap_drv.c new file +8 -0
+
+       if (rzs->backing_swap)
+               ramzswap_set_memlimit(rzs, totalram_bytes);
+       else
+               ramzswap_set_disksize(rzs, totalram_bytes);
+
+       rzs->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
+       if (rzs->compress_workmem == NULL) {
Quoted 9 lines
Quoted 6 lines

+               pr_err(C "Error allocating compressor working memory!\n");
+               ret = -ENOMEM;
+               goto fail;
+       }
+
+       rzs->compress_buffer = kzalloc(2 * PAGE_SIZE, GFP_KERNEL);

Use alloc_pages(__GFP_ZERO) here?

alloc pages then map them (i.e. vmalloc). What did we gain? With vmalloc, pages might
not be physically contiguous which might hurt performance as compressor runs over this buffer.

So, use kzalloc().

Quoted 6 lines
Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.h new file +0 -0
new file mode 100644
index 0000000..7f77edc
Quoted 8 lines

drivers/block/ramzswap/ramzswap_drv.h line 72

Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.h new file +5 -0
+
+#define SECTOR_SHIFT           9
+#define SECTOR_SIZE            (1 << SECTOR_SHIFT)
+#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
+#define SECTORS_PER_PAGE       (1 << SECTORS_PER_PAGE_SHIFT)

Don't we have these defines somewhere in include/linux?

I couldn't find something equivalent. At least swap code hard codes a value of 9.
So, a #define looks somewhat better.

Quoted 5 lines

drivers/block/ramzswap/ramzswap_drv.h line 75

Quoted 3 lines
drivers/block/ramzswap/ramzswap_drv.h new file +3 -0
+
+/* Message prefix */
+#define C "ramzswap: "

Use pr_fmt() instead.

okay.

Quoted 6 lines

drivers/block/ramzswap/ramzswap_drv.h line 78

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.h new file +3 -0
+
+/* Debugging and Stats */
+#define NOP    do { } while (0)

Huh? Drop this.

This is more of individual taste. This makes the code look cleaner to me. I hope its not considered 'over decoration'.

Quoted 9 lines

drivers/block/ramzswap/ramzswap_drv.h line 82

Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.h new file +4 -0
+
+#if defined(CONFIG_BLK_DEV_RAMZSWAP_STATS)
+#define STATS
+#endif

Why can't you rename that to CONFIG_RAMZSWAP_STATS and use that instead of the very generic STATS?

Everything in drivers/block/Kconfig has BLK_DEV_ as prefix BLK_DEV_RAM
BLK_DEV_RAM_COUNT
BLK_DEV_RAM_SIZE

and following the pattern:

BLK_DEV_RAMZSWAP
BLK_DEV_RAMZSWAP_STATS

STATS is just a convenient shortcut for very longish BLK_DEV_RAMZSWAP_STATS but I see this not used very often, so this shortcut is really not needed. I will now directly
use the long version.

Quoted 8 lines
Quoted 8 lines
drivers/block/ramzswap/ramzswap_drv.h new file +8 -0
+
+#if defined(STATS)
+#define stat_inc(stat)                 ((stat)++)
+#define stat_dec(stat)                 ((stat)--)
+#define stat_inc_if_less(stat, val1, val2) \
+                               ((stat) += ((val1) < (val2) ? 1 : 0))
+#define stat_dec_if_less(stat, val1, val2) \
+                               ((stat) -= ((val1) < (val2) ? 1 : 0))
Quoted 8 lines

drivers/block/ramzswap/ramzswap_drv.h line 96

Quoted 6 lines
drivers/block/ramzswap/ramzswap_drv.h new file +6 -0
+#else  /* STATS */
+#define stat_inc(x)                    NOP
+#define stat_dec(x)                    NOP
+#define stat_inc_if_less(x, v1, v2)    NOP
+#define stat_dec_if_less(x, v1, v2)    NOP
+#endif /* STATS */

Why do you need inc_if_less() and dec_if_less()?

No good reason. I will get rid of inc/dec_if_less().

Quoted 2 lines

And why are these not static inlines?

stats variables exist only when 'STATS' is defined. So, every call to static inline will have to be enclosed within '#if defined (STATS)'. Thus we use macros instead.

Thanks,
Nitin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Hi Nitin,

Quoted 18 lines · Nitin Gupta
Quoted 9 lines · Nitin Gupta
Quoted 8 lines
drivers/block/ramzswap/ramzswap_drv.c new file +8 -0
+
+/* Globals */
+static int RAMZSWAP_MAJOR;
+static struct ramzswap *DEVICES;
+
+/*
+ * Pages that compress to larger than this size are
+ * forwarded to backing swap, if present or stored
Quoted 8 lines

drivers/block/ramzswap/ramzswap_drv.c line 46

Quoted 6 lines

+ * uncompressed in memory otherwise.
+ */

drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+static unsigned int MAX_CPAGE_SIZE;
+
+/* Module params (documentation at end) */
+static unsigned long NUM_DEVICES;

These variable names should be in lower case.

Quoted 1 line

Global variables with lower case causes confusion.

Hmm? You are not following the kernel coding style here. It's as simple as that.

Quoted 21 lines
Quoted 17 lines
Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+static int page_zero_filled(void *ptr)
+{
+       u32 pos;
+       u64 *page;

drivers/block/ramzswap/ramzswap_drv.c line 91

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+       page = (u64 *)ptr;
+
+       for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
+               if (page[pos])
+                       return 0;
+       }
+
+       return 1;
+}

This looks like something that could be in lib/string.c.

Quoted 3 lines

/me looks

There's strspn so maybe you could introduce a memspn equivalent.

Quoted 7 lines

Maybe this is just too specific to this driver. Who else will use it? So, this simple function should stay within this driver only. If it finds more user, we can them move it to lib/string.c.

If I now move it to string.c I am sure I will get reverse argument from someone else:
"currently, it has no other users so bury it with this driver only".

How can you be sure about that? If you don't want to move it to generic code, fine, but the above argumentation doesn't really convince me. Check the git logs to see that this is *exactly* how new functions get added to lib/string.c. It's not always a question of two or more users, it's also an API issue. It doesn't make sense to put helpers in driver code where they don't belong (and won't be discovered if they're needed somewhere else).

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+/*
+ * Given <pagenum, offset> pair, provide a dereferencable pointer.
+ */
+static void *get_ptr_atomic(struct page *page, u16 offset, enum km_type type)
+{
+       unsigned char *base;
+
+       base = kmap_atomic(page, type);
+       return base + offset;
+}
Quoted 8 lines

drivers/block/ramzswap/ramzswap_drv.c line 107

Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+
+static void put_ptr_atomic(void *ptr, enum km_type type)
+{
+       kunmap_atomic(ptr, type);
+}

These two functions also appear in xmalloc. It's probably best to just kill the wrappers and use kmap/kunmap directly.

Quoted 5 lines

Wrapper for kmap_atomic is nice as spreading:
kmap_atomic(page, KM_USER0,1) + offset everywhere looks worse. What is the problem if these little 1-liner wrappers are repeated in xvmalloc too?
To me, they just add some clarity.

To me, they look like useless wrappers which we don't do in the kernel.

Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
drivers/block/ramzswap/ramzswap_drv.c new file +15 -0
+static void ramzswap_flush_dcache_page(struct page *page)
+{
+#ifdef CONFIG_ARM
+       int flag = 0;
+       /*
+        * Ugly hack to get flush_dcache_page() work on ARM.
+        * page_mapping(page) == NULL after clearing this swap cache flag.
+        * Without clearing this flag, flush_dcache_page() will simply set
+        * "PG_dcache_dirty" bit and return.
+        */
+       if (PageSwapCache(page)) {
+               flag = 1;
+               ClearPageSwapCache(page);
+       }
+#endif
Quoted 9 lines

drivers/block/ramzswap/ramzswap_drv.c line 129

Quoted 6 lines

+       flush_dcache_page(page);

drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+#ifdef CONFIG_ARM
+       if (flag)
+               SetPageSwapCache(page);
+#endif
+}

The above CONFIG_ARM magic really has no place in drivers/block.

Please read the comment above this hack to see why its needed. Also, for details see this mail:
http://www.linux-mips.org/archives/linux-mips/2008-11/msg00038.html

Quoted 8 lines

No one replied to above mail. So, I though just to temporarily introduce this hack while someone makes a proper fix for ARM (I will probably ping ARM/MIPS folks again for this).

Without this hack, ramzswap simply won't work on ARM. See:
http://code.google.com/p/compcache/issues/detail?id=33

So, its extremely difficult to wait for the _proper_ fix.

Then make ramzswap depend on !CONFIG_ARM. In any case, CONFIG_ARM bits really don't belong into drivers/block.

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

It is ad hoc. Talk to the ftrace folks how to do it properly. I'd keep those bits out-of-tree until the issue is resolved, really.

Quoted 10 lines
Quoted 3 lines
Quoted 1 line

+       rzs->compress_buffer = kzalloc(2 * PAGE_SIZE, GFP_KERNEL);

Use alloc_pages(__GFP_ZERO) here?

alloc pages then map them (i.e. vmalloc). What did we gain? With vmalloc, pages might
not be physically contiguous which might hurt performance as compressor runs over this buffer.

So, use kzalloc().

I don't know what you're talking about. kzalloc() calls __get_free_pages() directly for your allocation. You probably should use that directly.

Quoted 7 lines
Quoted 4 lines

drivers/block/ramzswap/ramzswap_drv.h line 78

Quoted 2 lines
drivers/block/ramzswap/ramzswap_drv.h new file +2 -0
+/* Debugging and Stats */
+#define NOP    do { } while (0)

Huh? Drop this.

This is more of individual taste. This makes the code look cleaner to me. I hope its not considered 'over decoration'.

Hey, the kernel doesn't care about your or my individual taste. I'm pointing out things that I think fall in the category of "we don't do shit like this in the kernel", not things _I_ personally find annoying. If you want to ignore those comments, fine, that's your prerogative. However, people usually have better results in getting their code merged when they listen to kernel developers who take the time to review their code.

Pekka

#6 lore raw

Hi Pekka,

Quoted 20 lines · Pekka Enberg
Quoted 18 lines · Nitin Gupta
Quoted 17 lines · Nitin Gupta
Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+
+/* Globals */
+static int RAMZSWAP_MAJOR;
+static struct ramzswap *DEVICES;

drivers/block/ramzswap/ramzswap_drv.c line 46

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+/*
+ * Pages that compress to larger than this size are
+ * forwarded to backing swap, if present or stored
+ * uncompressed in memory otherwise.
+ */
+static unsigned int MAX_CPAGE_SIZE;
+
+/* Module params (documentation at end) */
+static unsigned long NUM_DEVICES;

These variable names should be in lower case.

Quoted 4 lines
Quoted 1 line

Global variables with lower case causes confusion.

Hmm? You are not following the kernel coding style here. It's as simple as that.

ok....all lower case/.

Quoted 29 lines
Quoted 21 lines
Quoted 17 lines
Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+static int page_zero_filled(void *ptr)
+{
+       u32 pos;
+       u64 *page;

drivers/block/ramzswap/ramzswap_drv.c line 91

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+       page = (u64 *)ptr;
+
+       for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
+               if (page[pos])
+                       return 0;
+       }
+
+       return 1;
+}

This looks like something that could be in lib/string.c.

Quoted 3 lines

/me looks

There's strspn so maybe you could introduce a memspn equivalent.

Quoted 7 lines

Maybe this is just too specific to this driver. Who else will use it? So, this simple function should stay within this driver only. If it finds more user, we can them move it to lib/string.c.

If I now move it to string.c I am sure I will get reverse argument from someone else:
"currently, it has no other users so bury it with this driver only".

Quoted 8 lines

How can you be sure about that? If you don't want to move it to generic code, fine, but the above argumentation doesn't really convince me. Check the git logs to see that this is *exactly* how new functions get added to lib/string.c. It's not always a question of two or more users, it's also an API issue. It doesn't make sense to put helpers in driver code where they don't belong (and won't be discovered if they're needed somewhere else).

I don't want to ponder too much about this point now. If you all are okay with keeping this function buried in driver, I will do so. I'm almost tired maintaining this compcache thing outside of mainline.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+/*
+ * Given <pagenum, offset> pair, provide a dereferencable pointer.
+ */
+static void *get_ptr_atomic(struct page *page, u16 offset, enum km_type type)
+{

drivers/block/ramzswap/ramzswap_drv.c line 107

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+       unsigned char *base;
+
+       base = kmap_atomic(page, type);
+       return base + offset;
+}
+
+static void put_ptr_atomic(void *ptr, enum km_type type)
+{
+       kunmap_atomic(ptr, type);
+}

These two functions also appear in xmalloc. It's probably best to just kill the wrappers and use kmap/kunmap directly.

Quoted 8 lines
Quoted 5 lines

Wrapper for kmap_atomic is nice as spreading:
kmap_atomic(page, KM_USER0,1) + offset everywhere looks worse. What is the problem if these little 1-liner wrappers are repeated in xvmalloc too?
To me, they just add some clarity.

To me, they look like useless wrappers which we don't do in the kernel.

I will see how it looks without wrappers and depending on that I will decide if keeping this wrapper is better. Again, I don't want to ponder too much about this and will open code this if so required.

Quoted 33 lines
Quoted 33 lines
Quoted 15 lines
Quoted 15 lines
drivers/block/ramzswap/ramzswap_drv.c new file +15 -0
+static void ramzswap_flush_dcache_page(struct page *page)
+{
+#ifdef CONFIG_ARM
+       int flag = 0;
+       /*
+        * Ugly hack to get flush_dcache_page() work on ARM.
+        * page_mapping(page) == NULL after clearing this swap cache flag.
+        * Without clearing this flag, flush_dcache_page() will simply set
+        * "PG_dcache_dirty" bit and return.
+        */
+       if (PageSwapCache(page)) {
+               flag = 1;
+               ClearPageSwapCache(page);
+       }
+#endif
Quoted 9 lines

drivers/block/ramzswap/ramzswap_drv.c line 129

Quoted 6 lines

+       flush_dcache_page(page);

drivers/block/ramzswap/ramzswap_drv.c new file +5 -0
+#ifdef CONFIG_ARM
+       if (flag)
+               SetPageSwapCache(page);
+#endif
+}

The above CONFIG_ARM magic really has no place in drivers/block.

Please read the comment above this hack to see why its needed. Also, for details see this mail:
http://www.linux-mips.org/archives/linux-mips/2008-11/msg00038.html

No one replied to above mail. So, I though just to temporarily introduce this hack while someone makes a proper fix for ARM (I will probably ping ARM/MIPS folks again for this).

Quoted 8 lines
Quoted 4 lines

Without this hack, ramzswap simply won't work on ARM. See:
http://code.google.com/p/compcache/issues/detail?id=33

So, its extremely difficult to wait for the _proper_ fix.

Then make ramzswap depend on !CONFIG_ARM. In any case, CONFIG_ARM bits really don't belong into drivers/block.

ARM is an extremely important user of compcache -- Its currently being tested (unofficially)
on Android, Nokia etc.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

Quoted 7 lines
Quoted 3 lines

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

It is ad hoc. Talk to the ftrace folks how to do it properly. I'd keep those bits out-of-tree until the issue is resolved, really.

/me is speechless.

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

+       rzs->compress_buffer = kzalloc(2 * PAGE_SIZE, GFP_KERNEL);

Use alloc_pages(__GFP_ZERO) here?

alloc pages then map them (i.e. vmalloc). What did we gain? With vmalloc, pages might
not be physically contiguous which might hurt performance as compressor runs over this buffer.

Quoted 6 lines
Quoted 1 line

So, use kzalloc().

I don't know what you're talking about. kzalloc() calls __get_free_pages() directly for your allocation. You probably should use that directly.

What is wrong with kzalloc? I'm wholly totally stumped.
I respect your time reviewing the code but this really goes over my head. We can continue arguing about get_pages vs kzalloc but I doubt if we will gain anything out of it.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

drivers/block/ramzswap/ramzswap_drv.h line 78

Quoted 2 lines
drivers/block/ramzswap/ramzswap_drv.h new file +2 -0
+/* Debugging and Stats */
+#define NOP    do { } while (0)

Huh? Drop this.

This is more of individual taste. This makes the code look cleaner to me. I hope its not considered 'over decoration'.

Quoted 8 lines

Hey, the kernel doesn't care about your or my individual taste. I'm pointing out things that I think fall in the category of "we don't do shit like this in the kernel", not things _I_ personally find annoying. If you want to ignore those comments, fine, that's your prerogative. However, people usually have better results in getting their code merged when they listen to kernel developers who take the time to review their code.

Yikes! no NOP. okay.

Thanks,
Nitin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 3 lines · Nitin Gupta

I don't want to ponder too much about this point now. If you all are okay with keeping this function buried in driver, I will do so. I'm almost tired maintaining this compcache thing outside of mainline.

Yup, whatever makes most sense to you.

Quoted 5 lines
Quoted 2 lines

Then make ramzswap depend on !CONFIG_ARM. In any case, CONFIG_ARM bits really don't belong into drivers/block.

ARM is an extremely important user of compcache -- Its currently being tested (unofficially) on Android, Nokia etc.

That's not a technical argument for keeping CONFIG_ARM in the driver.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

It is ad hoc. Talk to the ftrace folks how to do it properly. I'd keep those bits out-of-tree until the issue is resolved, really.

/me is speechless.

That's fine, I CC'd the ftrace folks. Hopefully they'll be able to help you.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

+       rzs->compress_buffer = kzalloc(2 * PAGE_SIZE, GFP_KERNEL);

Use alloc_pages(__GFP_ZERO) here?

alloc pages then map them (i.e. vmalloc). What did we gain? With vmalloc, pages might
not be physically contiguous which might hurt performance as compressor runs over this buffer.

So, use kzalloc().

Quoted 8 lines
Quoted 3 lines

I don't know what you're talking about. kzalloc() calls __get_free_pages() directly for your allocation. You probably should use that directly.

What is wrong with kzalloc? I'm wholly totally stumped.
I respect your time reviewing the code but this really goes over my head. We can continue arguing about get_pages vs kzalloc but I doubt if we will gain anything out of it.

The slab allocator needs metadata for the allocation so you're wasting memory. If you really want *two pages*, why don't you simply use the page allocator for that?

Btw, Nitin, why are you targeting drivers/block and not drivers/staging at this point? It seems obvious enough that there are still some issues that need to be ironed out (like the CONFIG_ARM thing) so submitting the driver for inclusion in drivers/staging and fixing it up there incrementally would likely save you from a lot of trouble. Greg, does ramzswap sound like something that you'd be willing to take?

Pekka

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 7 lines · Pekka Enberg

Btw, Nitin, why are you targeting drivers/block and not drivers/staging at this point? It seems obvious enough that there are still some issues that need to be ironed out (like the CONFIG_ARM thing) so submitting the driver for inclusion in drivers/staging and fixing it up there incrementally would likely save you from a lot of trouble. Greg, does ramzswap sound like something that you'd be willing to take?

If it is self-contained, actually builds, and there is an active developer who is working getting it merged into the main kernel tree, then yes, I will be willing to take it into the drivers/staging/ tree. Just send me the patches.

thanks,

greg k-h

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw
Quoted 9 lines · Greg KH
Quoted 7 lines · Pekka Enberg

Btw, Nitin, why are you targeting drivers/block and not drivers/staging at this point? It seems obvious enough that there are still some issues that need to be ironed out (like the CONFIG_ARM thing) so submitting the driver for inclusion in drivers/staging and fixing it up there incrementally would likely save you from a lot of trouble. Greg, does ramzswap sound like something that you'd be willing to take?

Quoted 5 lines

If it is self-contained, actually builds, and there is an active developer who is working getting it merged into the main kernel tree, then yes, I will be willing to take it into the drivers/staging/ tree. Just send me the patches.

It is self contained (except for swap notify callback part). I will send revised patches addressing some of coding issues raised in reviews and moving everything over to drivers/staging.

Thanks,
Nitin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw
In reply to Pekka Enberg
Quoted 4 lines · On Tuesday 15 September 2009 03:30:23 you wrote:
Quoted 1 line

So, its extremely difficult to wait for the proper fix.

Then make ramzswap depend on !CONFIG_ARM. In any case, CONFIG_ARM bits really don't belong into drivers/block.

Problem is that ramzswap is usefull on boxes like the n800/n810... So this is a bad
suggestion from my POV. How about a comment saying this code goes when the
fix arrives???

Ed Tomlinson

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw
Quoted 4 lines · On Tuesday 15 September 2009 03:30:23 you wrote:
Quoted 4 lines
Quoted 1 line

So, its extremely difficult to wait for the proper fix.

Then make ramzswap depend on !CONFIG_ARM. In any case, CONFIG_ARM bits really don't belong into drivers/block.

Quoted 3 lines · Ed Tomlinson

Problem is that ramzswap is usefull on boxes like the n800/n810...  So this is a bad suggestion from my POV.    How about a comment saying this code goes when the fix arrives???

Just put the driver in driver/staging until the issue is resolved.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw
In reply to Pekka Enberg
Quoted 32 lines · Pekka Enberg

Hi Nitin,

Quoted 21 lines
Quoted 17 lines
Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+static int page_zero_filled(void *ptr)
+{
+       u32 pos;
+       u64 *page;

drivers/block/ramzswap/ramzswap_drv.c line 91

Quoted 10 lines
drivers/block/ramzswap/ramzswap_drv.c new file +10 -0
+
+       page = (u64 *)ptr;
+
+       for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
+               if (page[pos])
+                       return 0;
+       }
+
+       return 1;
+}

This looks like something that could be in lib/string.c.

Quoted 3 lines

/me looks

There's strspn so maybe you could introduce a memspn equivalent.

Quoted 7 lines

Maybe this is just too specific to this driver. Who else will use it? So, this simple function should stay within this driver only. If it finds more user, we can them move it to lib/string.c.

If I now move it to string.c I am sure I will get reverse argument from someone else:
"currently, it has no other users so bury it with this driver only".

Quoted 7 lines

How can you be sure about that? If you don't want to move it to generic code, fine, but the above argumentation doesn't really convince me. Check the git logs to see that this is *exactly* how new functions get added to lib/string.c. It's not always a question of two or more users, it's also an API issue. It doesn't make sense to put helpers in driver code where they don't belong (and won't be discovered if they're needed somewhere else).

I agree, a generic function like this should be put into string.c (or some library). That's the first place I look when I want to do some kind of generic string or memory manipulation.

If you don't put it there, and another driver writer needs the same thing, they will write their own. That's how we get 10 different implementations of the same code in the kernel. Because everyone thinks "this will only be used by me".

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

drivers/block/ramzswap/ramzswap_drv.c line 781

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

Quoted 6 lines
Quoted 3 lines

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

It is ad hoc. Talk to the ftrace folks how to do it properly. I'd keep those bits out-of-tree until the issue is resolved, really.

Yes, trace_mark is deprecated. You want to use TRACE_EVENT. See how gfs2 does it in:

fs/gfs2/gfs2_trace.h

and it is well documented in
samples/trace_events/trace-events-samples.[ch]

-- Steve

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

Hi Steve,

Quoted 15 lines · Steven Rostedt
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

drivers/block/ramzswap/ramzswap_drv.c line 781

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

Quoted 6 lines
Quoted 3 lines

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

It is ad hoc. Talk to the ftrace folks how to do it properly. I'd keep those bits out-of-tree until the issue is resolved, really.

Quoted 7 lines

Yes, trace_mark is deprecated. You want to use TRACE_EVENT. See how gfs2 does it in:

fs/gfs2/gfs2_trace.h

and it is well documented in
samples/trace_events/trace-events-samples.[ch]

Does it really make sense to add special-case tracing in driver code to profile lock contention for a _single mutex_?

Pekka

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw
Quoted 21 lines · Pekka Enberg

Hi Steve,

Quoted 18 lines · Steven Rostedt
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

drivers/block/ramzswap/ramzswap_drv.c line 781

Quoted 4 lines
drivers/block/ramzswap/ramzswap_drv.c new file +4 -0
+
+       trace_mark(ramzswap_lock_wait, "ramzswap_lock_wait");
+       mutex_lock(&rzs->lock);
+       trace_mark(ramzswap_lock_acquired, "ramzswap_lock_acquired");

Hmm? What's this? I don't think you should be doing ad hoc trace_mark() in driver code.

Quoted 6 lines
Quoted 3 lines

This is not ad hoc. It is to see contention over this lock which I believe is a major bottleneck even on dual-cores. I need to keep this to measure improvements as I gradually make this locking more fine grained (using per-cpu buffer etc).

It is ad hoc. Talk to the ftrace folks how to do it properly. I'd keep those bits out-of-tree until the issue is resolved, really.

Yes, trace_mark is deprecated. You want to use TRACE_EVENT. See how gfs2 does it in:

Quoted 7 lines
Quoted 4 lines

fs/gfs2/gfs2_trace.h

and it is well documented in
samples/trace_events/trace-events-samples.[ch]

Does it really make sense to add special-case tracing in driver code to profile lock contention for a _single mutex_?

No that's what LOCKSTAT is for ;-)

-- Steve

#15 lore raw

PATCH 3/4 send callback when swap slot is freed

In reply to a message not in the archive

Currently, we have "swap discard" mechanism which sends a discard bio request when we find a free cluster during scan_swap_map(). This callback can come a long time after swap slots are actually freed.

This delay in callback is a great problem when (compressed) RAM [1] is used as a swap device. So, this change adds a callback which is called as soon as a swap slot becomes free. For above mentioned case of swapping over compressed RAM device, this is very useful since we can immediately free memory allocated for this swap page.

This callback does not replace swap discard support. It is called with swap_lock held, so it is meant to trigger action that finishes quickly. However, swap discard is an I/O request and can be used for taking longer actions.

It is preferred to use this callback for ramzswap case even if discard mechanism could be improved such that it can be called as often as required. This is because, allocation of 'bio'(s) is undesirable since ramzswap always operates under low memory conditions (its a swap device). Also, batching of discard bio requests is not optimal since stale data can accumulate very quickly in ramzswap devices, pushing system further into low memory state.

Links:
[1] http://compcache.googlecode.com/

---

 include/linux/swap.h |    5 +++++
 mm/swapfile.c        |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)
include/linux/swap.h +5 -0
index 7c15334..64796fc 100644
@@ -8,6 +8,7 @@
 #include <linux/memcontrol.h>
 #include <linux/sched.h>
 #include <linux/node.h>
+#include <linux/blkdev.h>
 
 #include <asm/atomic.h>
 #include <asm/page.h>
@@ -20,6 +21,8 @@ struct bio;
 #define SWAP_FLAG_PRIO_MASK	0x7fff
 #define SWAP_FLAG_PRIO_SHIFT	0
 
+typedef void (swap_free_notify_fn) (struct block_device *, unsigned long);
+
 static inline int current_is_kswapd(void)
 {
 	return current->flags & PF_KSWAPD;
@@ -155,6 +158,7 @@ struct swap_info_struct {
 	unsigned int max;
 	unsigned int inuse_pages;
 	unsigned int old_block_size;
+	swap_free_notify_fn *swap_free_notify_fn;
 };
 
 struct swap_list_t {
@@ -295,6 +299,7 @@ extern sector_t swapdev_block(int, pgoff_t);
 extern struct swap_info_struct *get_swap_info_struct(unsigned);
 extern int reuse_swap_page(struct page *);
 extern int try_to_free_swap(struct page *);
+extern void set_swap_free_notify(struct block_device *, swap_free_notify_fn *);
 struct backing_dev_info;
 
 /* linux/mm/thrash.c */
mm/swapfile.c +34 -0
index 8ffdc0d..fb6b8b2 100644
@@ -552,6 +552,38 @@ out:
 	return NULL;
 }
 
+/*
+ * Sets callback for event when swap_map[offset] == 0
+ * i.e. page at this swap offset is no longer used.
+ */
+void set_swap_free_notify(struct block_device *bdev,
+			swap_free_notify_fn *notify_fn)
+{
+	unsigned int i;
+	struct swap_info_struct *sis;
+
+	spin_lock(&swap_lock);
+	for (i = 0; i <= nr_swapfiles; i++) {
+		sis = &swap_info[i];
+		if (!(sis->flags & SWP_USED))
+			continue;
+		if (sis->bdev == bdev)
+			break;
+	}
+
+	/* swap device not found */
+	if (i > nr_swapfiles) {
+		spin_unlock(&swap_lock);
+		return;
+	}
+
+	BUG_ON(!sis || sis->swap_free_notify_fn);
+	sis->swap_free_notify_fn = notify_fn;
+	spin_unlock(&swap_lock);
+	return;
+}
+EXPORT_SYMBOL_GPL(set_swap_free_notify);
+
 static int swap_entry_free(struct swap_info_struct *p,
 			   swp_entry_t ent, int cache)
 {
@@ -583,6 +615,8 @@ static int swap_entry_free(struct swap_info_struct *p,
 			swap_list.next = p - swap_info;
 		nr_swap_pages++;
 		p->inuse_pages--;
+		if (p->swap_free_notify_fn)
+			p->swap_free_notify_fn(p->bdev, offset);
 	}
 	if (!swap_count(count))
 		mem_cgroup_uncharge_swap(ent);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

PATCH 4/4 documentation

In reply to a message not in the archive

Short guide on how to setup and use ramzswap.

---

 Documentation/blockdev/00-INDEX     |    2 +
 Documentation/blockdev/ramzswap.txt |   50 +++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
Documentation/blockdev/00-INDEX +2 -0
index c08df56..c1cb074 100644
@@ -16,3 +16,5 @@ paride.txt
 	- information about the parallel port IDE subsystem.
 ramdisk.txt
 	- short guide on how to set up and use the RAM disk.
+ramzswap.txt
+	- short guide on how to setup compressed in-memory swap device.
Documentation/blockdev/ramzswap.txt new file +50 -0

50 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

cover compcache: in-memory compressed swapping v2

In reply to a message not in the archive

Hi,

Project home: http://compcache.googlecode.com/

* Changelog: v2 vs initial revision
- Use 'struct page' instead of 32-bit PFNs in ramzswap driver and xvmalloc. This is to make these 64-bit safe.
- xvmalloc is no longer a separate module and does not export any symbols. Its compiled directly with ramzswap block driver. This is to avoid any last bit of confusion with any other allocator.
- set_swap_free_notify() now accepts block_device as parameter instead of swp_entry_t (interface cleanup).
- Fix: Make sure ramzswap disksize matches usable pages in backing swap file. This caused initialization error in case backing swap file had intra-page fragmentation.

It creates RAM based block devices which can be used (only) as swap disks. Pages swapped to these disks are compressed and stored in memory itself. This is a big win over swapping to slow hard-disk which are typically used as swap disk. For flash, these suffer from wear-leveling issues when used as swap disk
- so again its helpful. For swapless systems, it allows more apps to run for a given amount of memory.

It can create multiple ramzswap devices (/dev/ramzswapX, X = 0, 1, 2, ...). Each of these devices can have separate backing swap (file or disk partition) which is used when incompressible page is found or memory limit for device is reached.

A separate userspace utility called rzscontrol is used to manage individual ramzswap devices.

* Testing notes

Tested on x86, x64, ARM
ARM:
- Cortex-A8 (Beagleboard)
- ARM11 (Android G1)
- OMAP2420 (Nokia N810)

* Performance

All performance numbers/plots can be found at:
http://code.google.com/p/compcache/wiki/Performance

Below is a summary of this data:

General:
- Swap R/W times are reduced from milliseconds (in case of hard disks)
down to microseconds.

Positive cases:
- Shows 33% improvement in 'scan' benchmark which allocates given amount
of memory and linearly reads/writes to this region. This benchmark also exposes bottlenecks in ramzswap code (global mutex) due to which this gain is so small.
- On Linux thin clients, it gives the effect of nearly doubling the amount of
memory.

Negative cases:
Any workload that has active working set w.r.t. filesystem cache that is nearly equal to amount of RAM while has minimal anonymous memory requirement, is expected to suffer maximum loss in performance with ramzswap enabled.

Iozone filesystem benchmark can simulate exactly this kind of workload. As expected, this test shows performance loss of ~25% with ramzswap.

(Sorry for long patch[2/4] but its now very hard to split it up).

 Documentation/blockdev/00-INDEX       |    2 +
 Documentation/blockdev/ramzswap.txt   |   50 ++
 drivers/block/Kconfig                 |   22 +
 drivers/block/Makefile                |    1 +
 drivers/block/ramzswap/Makefile       |    3 +
 drivers/block/ramzswap/ramzswap_drv.c | 1529 +++++++++++++++++++++++++++++++++
 drivers/block/ramzswap/ramzswap_drv.h |  183 ++++
 drivers/block/ramzswap/xvmalloc.c     |  533 ++++++++++++
 drivers/block/ramzswap/xvmalloc.h     |   30 +
 drivers/block/ramzswap/xvmalloc_int.h |   86 ++
 include/linux/ramzswap_ioctl.h        |   51 ++
 include/linux/swap.h                  |    5 +
 mm/swapfile.c                         |   34 +
 13 files changed, 2529 insertions(+), 0 deletions(-)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

Re: [PATCH 0/4] compcache: in-memory compressed swapping v2

Hi,

Quoted 15 lines · Nitin Gupta

Project home: http://compcache.googlecode.com/

* Changelog: v2 vs initial revision
- Use 'struct page' instead of 32-bit PFNs in ramzswap driver and xvmalloc. This is to make these 64-bit safe.
- xvmalloc is no longer a separate module and does not export any symbols. Its compiled directly with ramzswap block driver. This is to avoid any last bit of confusion with any other allocator.
- set_swap_free_notify() now accepts block_device as parameter instead of swp_entry_t (interface cleanup).
- Fix: Make sure ramzswap disksize matches usable pages in backing swap file. This caused initialization error in case backing swap file had intra-page fragmentation.

Can anyone please review these patches for possible inclusion in 2.6.32? Sorry for the weird email threading.

Thanks,
Nitin

Quoted 66 lines

It creates RAM based block devices which can be used (only) as swap disks. Pages swapped to these disks are compressed and stored in memory itself. This is a big win over swapping to slow hard-disk which are typically used as swap disk. For flash, these suffer from wear-leveling issues when used as swap disk
- so again its helpful. For swapless systems, it allows more apps to run for a given amount of memory.

It can create multiple ramzswap devices (/dev/ramzswapX, X = 0, 1, 2, ...). Each of these devices can have separate backing swap (file or disk partition) which is used when incompressible page is found or memory limit for device is reached.

A separate userspace utility called rzscontrol is used to manage individual ramzswap devices.

* Testing notes

Tested on x86, x64, ARM
ARM:
- Cortex-A8 (Beagleboard)
- ARM11 (Android G1)
- OMAP2420 (Nokia N810)

* Performance

All performance numbers/plots can be found at:
http://code.google.com/p/compcache/wiki/Performance

Below is a summary of this data:

General:
- Swap R/W times are reduced from milliseconds (in case of hard disks)
down to microseconds.

Positive cases:
- Shows 33% improvement in 'scan' benchmark which allocates given amount
of memory and linearly reads/writes to this region. This benchmark also exposes bottlenecks in ramzswap code (global mutex) due to which this gain is so small.
- On Linux thin clients, it gives the effect of nearly doubling the amount of
memory.

Negative cases:
Any workload that has active working set w.r.t. filesystem cache that is nearly equal to amount of RAM while has minimal anonymous memory requirement, is expected to suffer maximum loss in performance with ramzswap enabled.

Iozone filesystem benchmark can simulate exactly this kind of workload. As expected, this test shows performance loss of ~25% with ramzswap.

(Sorry for long patch[2/4] but its now very hard to split it up).

  Documentation/blockdev/00-INDEX       |    2 +
  Documentation/blockdev/ramzswap.txt   |   50 ++
  drivers/block/Kconfig                 |   22 +
  drivers/block/Makefile                |    1 +
  drivers/block/ramzswap/Makefile       |    3 +
  drivers/block/ramzswap/ramzswap_drv.c | 1529 +++++++++++++++++++++++++++++++++
  drivers/block/ramzswap/ramzswap_drv.h |  183 ++++
  drivers/block/ramzswap/xvmalloc.c     |  533 ++++++++++++
  drivers/block/ramzswap/xvmalloc.h     |   30 +
  drivers/block/ramzswap/xvmalloc_int.h |   86 ++
  include/linux/ramzswap_ioctl.h        |   51 ++
  include/linux/swap.h                  |    5 +
  mm/swapfile.c                         |   34 +
  13 files changed, 2529 insertions(+), 0 deletions(-)
Quoted 2 lines

_______________________________________________

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw

Re: [PATCH 0/4] compcache: in-memory compressed swapping v2

Quoted 18 lines · Nitin Gupta
Quoted 16 lines · Nitin Gupta

Project home: http://compcache.googlecode.com/

* Changelog: v2 vs initial revision
- Use 'struct page' instead of 32-bit PFNs in ramzswap driver and xvmalloc.
This is to make these 64-bit safe.
- xvmalloc is no longer a separate module and does not export any symbols. Its compiled directly with ramzswap block driver. This is to avoid any last bit of confusion with any other allocator.
- set_swap_free_notify() now accepts block_device as parameter instead of swp_entry_t (interface cleanup).
- Fix: Make sure ramzswap disksize matches usable pages in backing swap file.
This caused initialization error in case backing swap file had intra-page
fragmentation.

Quoted 1 line

Can anyone please review these patches for possible inclusion in 2.6.32?

Sorry, I certainly wouldn't be able to review them for 2.6.32 myself.

Since we're already in the merge window, and this work has not yet had exposure in mmotm (preferably) or linux-next, I really doubt anyone should be pushing it for 2.6.32.

I'd be quite glad to see it and experiment with it in mmotm, so it could go into 2.6.33 if all okay. And I now fully accept that the discard/trim situation is so hazy that you are quite right to be asking for your own well-defined notifier instead.

But I'm not going to pretend to have reviewed it.

Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#20 lore raw

Re: [PATCH 0/4] compcache: in-memory compressed swapping v2

Quoted 27 lines · Hugh Dickins
Quoted 18 lines · Nitin Gupta
Quoted 16 lines · Nitin Gupta

Project home: http://compcache.googlecode.com/

* Changelog: v2 vs initial revision
  - Use 'struct page' instead of 32-bit PFNs in ramzswap driver and xvmalloc.
    This is to make these 64-bit safe.
  - xvmalloc is no longer a separate module and does not export any symbols. Its compiled directly with ramzswap block driver. This is to avoid any last bit of confusion with any other allocator.
  - set_swap_free_notify() now accepts block_device as parameter instead of swp_entry_t (interface cleanup).
  - Fix: Make sure ramzswap disksize matches usable pages in backing swap file.
    This caused initialization error in case backing swap file had intra-page
    fragmentation.

Quoted 1 line

Can anyone please review these patches for possible inclusion in 2.6.32?

Sorry, I certainly wouldn't be able to review them for 2.6.32 myself.

Since we're already in the merge window, and this work has not yet had exposure in mmotm (preferably) or linux-next, I really doubt anyone should be pushing it for 2.6.32.

Quoted 7 lines

I'd be quite glad to see it and experiment with it in mmotm, so it could go into 2.6.33 if all okay.  And I now fully accept that the discard/trim situation is so hazy that you are quite right to be asking for your own well-defined notifier instead.

But I'm not going to pretend to have reviewed it.

Thanks for the pointer Hugh -- I will try to post patches against mmotm later.

Nitin