From: Nitin Gupta <ngupta@vflare.org>
To: Pekka Enberg <penberg@cs.helsinki.fi>,
Minchan Kim <minchan.kim@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Greg KH <greg@kroah.com>
Cc: Linux Driver Project <devel@driverdev.osuosl.org>,
linux-mm <linux-mm@kvack.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 08/10] Some cleanups
Date: Mon, 9 Aug 2010 22:56:54 +0530 [thread overview]
Message-ID: <1281374816-904-9-git-send-email-ngupta@vflare.org> (raw)
In-Reply-To: <1281374816-904-1-git-send-email-ngupta@vflare.org>
- xvmalloc: Remove unnecessary stat_{inc,dec} and increment
pages_stored directly
- xvmalloc: Initialize pointers with NULL instead of 0
- zram: Remove verbose message when use sets insane disksize
- zram: Mark some messages as pr_debug
- zram: Refine some comments
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
---
drivers/staging/zram/xvmalloc.c | 22 ++++-------------
drivers/staging/zram/zram_drv.c | 49 +++++++++++++-------------------------
drivers/staging/zram/zram_drv.h | 26 ++++----------------
3 files changed, 28 insertions(+), 69 deletions(-)
diff --git a/drivers/staging/zram/xvmalloc.c b/drivers/staging/zram/xvmalloc.c
index 3fdbb8a..6268f65 100644
--- a/drivers/staging/zram/xvmalloc.c
+++ b/drivers/staging/zram/xvmalloc.c
@@ -20,16 +20,6 @@
#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);
@@ -187,7 +177,7 @@ static void insert_block(struct xv_pool *pool, struct page *page, u32 offset,
slindex = get_index_for_insert(block->size);
flindex = slindex / BITS_PER_LONG;
- block->link.prev_page = 0;
+ block->link.prev_page = NULL;
block->link.prev_offset = 0;
block->link.next_page = pool->freelist[slindex].page;
block->link.next_offset = pool->freelist[slindex].offset;
@@ -217,7 +207,7 @@ static void remove_block_head(struct xv_pool *pool,
pool->freelist[slindex].page = block->link.next_page;
pool->freelist[slindex].offset = block->link.next_offset;
- block->link.prev_page = 0;
+ block->link.prev_page = NULL;
block->link.prev_offset = 0;
if (!pool->freelist[slindex].page) {
@@ -232,7 +222,7 @@ static void remove_block_head(struct xv_pool *pool,
*/
tmpblock = get_ptr_atomic(pool->freelist[slindex].page,
pool->freelist[slindex].offset, KM_USER1);
- tmpblock->link.prev_page = 0;
+ tmpblock->link.prev_page = NULL;
tmpblock->link.prev_offset = 0;
put_ptr_atomic(tmpblock, KM_USER1);
}
@@ -284,7 +274,7 @@ static int grow_pool(struct xv_pool *pool, gfp_t flags)
if (unlikely(!page))
return -ENOMEM;
- stat_inc(&pool->total_pages);
+ pool->total_pages++;
spin_lock(&pool->lock);
block = get_ptr_atomic(page, 0, KM_USER0);
@@ -361,8 +351,6 @@ int xv_malloc(struct xv_pool *pool, u32 size, struct page **page,
if (!*page) {
spin_unlock(&pool->lock);
- if (flags & GFP_NOWAIT)
- return -ENOMEM;
error = grow_pool(pool, flags);
if (unlikely(error))
return error;
@@ -472,7 +460,7 @@ void xv_free(struct xv_pool *pool, struct page *page, u32 offset)
spin_unlock(&pool->lock);
__free_page(page);
- stat_dec(&pool->total_pages);
+ pool->total_pages--;
return;
}
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 0f9785f..42aa271 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -9,7 +9,7 @@
* 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
+ * Project home: http://compcache.googlecode.com/
*/
#define KMSG_COMPONENT "zram"
@@ -130,33 +130,15 @@ static void zram_insert_obj(struct zram *zram, u32 index, struct page *page,
zram->table[index].addr = addr;
}
-static void zram_set_disksize(struct zram *zram, size_t totalram_bytes)
+static u64 zram_default_disksize(void)
{
- if (!zram->disksize) {
- pr_info(
- "disk size not provided. You can use disksize_kb module "
- "param to specify size.\nUsing default: (%u%% of RAM).\n",
- default_disksize_perc_ram
- );
- zram->disksize = default_disksize_perc_ram *
- (totalram_bytes / 100);
- }
+ u64 disksize;
- if (zram->disksize > 2 * (totalram_bytes)) {
- pr_info(
- "There is little point creating a zram of greater than "
- "twice the size of memory since we expect a 2:1 compression "
- "ratio. Note that zram uses about 0.1%% of the size of "
- "the disk when not in use so a huge zram is "
- "wasteful.\n"
- "\tMemory Size: %zu kB\n"
- "\tSize you selected: %llu kB\n"
- "Continuing anyway ...\n",
- totalram_bytes >> 10, zram->disksize
- );
- }
+ disksize = default_disksize_perc_ram *
+ (totalram_pages / 100);
+ disksize = (disksize << PAGE_SHIFT) & PAGE_MASK;
- zram->disksize &= PAGE_MASK;
+ return disksize;
}
static void zram_free_page(struct zram *zram, size_t index)
@@ -459,7 +441,7 @@ static int zram_make_request(struct request_queue *queue, struct bio *bio)
int ret = 0;
struct zram *zram = queue->queuedata;
- if (!valid_io_request(zram, bio)) {
+ if (unlikely(!valid_io_request(zram, bio))) {
zram_inc_stat(zram, ZRAM_STAT_INVALID_IO);
bio_io_error(bio);
return 0;
@@ -504,7 +486,7 @@ void zram_reset_device(struct zram *zram)
/* Reset stats */
memset(&zram->stats, 0, sizeof(zram->stats));
- zram->disksize = 0;
+ zram->disksize = zram_default_disksize();
mutex_unlock(&zram->init_lock);
}
@@ -520,7 +502,8 @@ int zram_init_device(struct zram *zram)
return 0;
}
- zram_set_disksize(zram, totalram_pages << PAGE_SHIFT);
+ if (!zram->disksize)
+ zram->disksize = zram_default_disksize();
num_pages = zram->disksize >> PAGE_SHIFT;
zram->table = vmalloc(num_pages * sizeof(*zram->table));
@@ -566,7 +549,8 @@ fail:
return ret;
}
-void zram_slot_free_notify(struct block_device *bdev, unsigned long index)
+static void zram_slot_free_notify(struct block_device *bdev,
+ unsigned long index)
{
struct zram *zram;
@@ -614,8 +598,9 @@ static int create_device(struct zram *zram, int device_id)
zram->disk->private_data = zram;
snprintf(zram->disk->disk_name, 16, "zram%d", device_id);
- /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */
- set_capacity(zram->disk, 0);
+ /* Custom size can be set using syfs (/sys/block/zram<id>/disksize) */
+ zram->disksize = zram_default_disksize();
+ set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
/*
* To ensure that we always get PAGE_SIZE aligned
@@ -739,7 +724,7 @@ static int __init zram_init(void)
}
/* Allocate the device array and initialize each one */
- pr_info("Creating %u devices ...\n", num_devices);
+ pr_debug("Creating %u devices ...\n", num_devices);
devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL);
if (!devices) {
ret = -ENOMEM;
diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h
index bcc51ea..2cf36db 100644
--- a/drivers/staging/zram/zram_drv.h
+++ b/drivers/staging/zram/zram_drv.h
@@ -9,7 +9,7 @@
* 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
+ * Project home: http://compcache.googlecode.com/
*/
#ifndef _ZRAM_DRV_H_
@@ -26,18 +26,6 @@
*/
static const unsigned max_num_devices = 32;
-/*
- * Stored at beginning of each compressed object.
- *
- * It stores back-reference to table entry which points to this
- * object. This is required to support memory defragmentation.
- */
-struct zobj_header {
-#if 0
- u32 table_idx;
-#endif
-};
-
/*-- Configurable parameters */
/* Default zram disk size: 25% of total RAM */
@@ -50,8 +38,7 @@ static const unsigned default_disksize_perc_ram = 25;
static const unsigned max_zpage_size = PAGE_SIZE / 8 * 7;
/*
- * NOTE: max_zpage_size must be less than or equal to:
- * XV_MAX_ALLOC_SIZE - sizeof(struct zobj_header)
+ * NOTE: max_zpage_size must be less than or equal to XV_MAX_ALLOC_SIZE
* otherwise, xv_malloc() would always return failure.
*/
@@ -92,16 +79,15 @@ struct zram {
struct table *table;
struct request_queue *queue;
struct gendisk *disk;
- int init_done;
+ unsigned int init_done;
/* Prevent concurrent execution of device init and reset */
struct mutex init_lock;
/*
* This is the limit on amount of *uncompressed* worth of data
- * we can store in a disk.
+ * we can store in a disk (in bytes).
*/
- u64 disksize; /* bytes */
-
- struct zram_stats_cpu *stats;
+ u64 disksize;
+ struct zram_stats_cpu *stats; /* percpu stats */
};
extern struct zram *devices;
--
1.7.2.1
next prev parent reply other threads:[~2010-08-09 17:27 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-09 17:26 [PATCH 00/10] zram: various improvements and cleanups Nitin Gupta
2010-08-09 17:26 ` [PATCH 01/10] Replace ioctls with sysfs interface Nitin Gupta
2010-08-09 18:34 ` Pekka Enberg
2010-08-10 3:06 ` Nitin Gupta
2010-08-31 23:06 ` Dave Hansen
2010-08-09 17:26 ` [PATCH 02/10] Remove need for explicit device initialization Nitin Gupta
2010-08-09 18:36 ` Pekka Enberg
2010-08-10 3:38 ` Nitin Gupta
2010-08-09 17:26 ` [PATCH 03/10] Use percpu stats Nitin Gupta
2010-08-09 18:44 ` Pekka Enberg
2010-08-10 4:34 ` Andrew Morton
2010-08-11 16:39 ` Nitin Gupta
2010-08-11 17:18 ` Andrew Morton
2010-08-30 16:20 ` Christoph Lameter
2010-08-31 20:31 ` Nitin Gupta
2010-08-31 21:28 ` Eric Dumazet
2010-08-31 21:35 ` Christoph Lameter
2010-08-31 21:41 ` Eric Dumazet
2010-09-01 20:05 ` Christoph Lameter
2010-09-01 20:38 ` Eric Dumazet
2010-09-02 0:34 ` Christoph Lameter
2010-08-31 5:36 ` Anton Blanchard
2010-09-01 3:41 ` Anton Blanchard
2010-09-01 3:51 ` Anton Blanchard
2010-09-17 20:59 ` Andrew Morton
2010-08-09 17:26 ` [PATCH 04/10] Use percpu buffers Nitin Gupta
2010-08-09 18:57 ` Pekka Enberg
2010-08-10 4:47 ` Nitin Gupta
2010-08-10 5:05 ` Pekka Enberg
2010-08-10 5:32 ` Nitin Gupta
2010-08-10 7:36 ` Pekka Enberg
2010-08-09 17:26 ` [PATCH 05/10] Reduce per table entry overhead by 4 bytes Nitin Gupta
2010-08-09 18:59 ` Pekka Enberg
2010-08-10 4:55 ` Nitin Gupta
2010-08-09 17:26 ` [PATCH 06/10] Block discard support Nitin Gupta
2010-08-09 19:03 ` Pekka Enberg
2010-08-10 2:23 ` Jens Axboe
2010-08-10 4:54 ` Nitin Gupta
2010-08-10 15:54 ` Jens Axboe
2010-08-09 17:26 ` [PATCH 07/10] Increase compressed page size threshold Nitin Gupta
2010-08-09 18:32 ` Pekka Enberg
2010-08-09 17:26 ` Nitin Gupta [this message]
2010-08-09 19:02 ` [PATCH 08/10] Some cleanups Pekka Enberg
2010-08-09 17:26 ` [PATCH 09/10] Update zram documentation Nitin Gupta
2010-08-09 17:26 ` [PATCH 10/10] Document sysfs entries Nitin Gupta
2010-08-09 19:02 ` Pekka Enberg
2010-08-31 22:37 ` [PATCH 00/10] zram: various improvements and cleanups Greg KH
2010-09-01 3:32 ` Anton Blanchard
2010-09-09 17:24 ` OOM panics with zram Dave Hansen
2010-09-09 19:07 ` [patch -rc] oom: always return a badness score of non-zero for eligible tasks David Rientjes
2010-09-09 19:48 ` Dave Hansen
2010-09-09 21:00 ` David Rientjes
2010-09-09 21:10 ` Dave Hansen
2010-09-09 21:40 ` David Rientjes
2010-10-03 18:41 ` OOM panics with zram Nitin Gupta
2010-10-03 19:27 ` Dave Hansen
2010-10-03 19:40 ` Nitin Gupta
2010-10-04 11:08 ` Ed Tomlinson
2010-10-05 23:43 ` Greg KH
2010-10-06 2:29 ` Nitin Gupta
2010-10-06 2:36 ` Greg KH
2010-10-06 4:30 ` Nitin Gupta
2010-10-06 7:38 ` Pekka Enberg
2010-10-06 14:03 ` Greg KH
2010-10-06 14:16 ` Pekka Enberg
2010-10-06 14:53 ` Nitin Gupta
2010-10-06 14:02 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1281374816-904-9-git-send-email-ngupta@vflare.org \
--to=ngupta@vflare.org \
--cc=akpm@linux-foundation.org \
--cc=devel@driverdev.osuosl.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan.kim@gmail.com \
--cc=penberg@cs.helsinki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®