mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-24 17:59:32 +00:00
![Minchan Kim](/assets/img/avatar_default.png)
xvmalloc can't handle PAGE_SIZE page so that zram have to handle it specially but zsmalloc can do it so let's remove unnecessary special handling code. Quote from Nitin "I think page vs handle distinction was added since xvmalloc could not handle full page allocation. Now that zsmalloc allows full page allocation, we can just use it for both cases. This would also allow removing the ZRAM_UNCOMPRESSED flag. The only downside will be slightly slower code path for full page allocation but this event is anyways supposed to be rare, so should be fine." 1. This patch reduces code very much. drivers/staging/zram/zram_drv.c | 104 +++++-------------------------------- drivers/staging/zram/zram_drv.h | 17 +----- drivers/staging/zram/zram_sysfs.c | 6 +-- 3 files changed, 15 insertions(+), 112 deletions(-) 2. change pages_expand with bad_compress so it can count bad compression(above 75%) ratio. 3. remove zobj_header which is for back-reference for defragmentation because firstly, it's not used at the moment and zsmalloc can't handle bigger size than PAGE_SIZE so zram can't do it any more without redesign. Cc: Seth Jennings <sjenning@linux.vnet.ibm.com> Signed-off-by: Minchan Kim <minchan@kernel.org> Acked-by: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
225 lines
5.3 KiB
C
225 lines
5.3 KiB
C
/*
|
|
* Compressed RAM block device
|
|
*
|
|
* Copyright (C) 2008, 2009, 2010 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/device.h>
|
|
#include <linux/genhd.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include "zram_drv.h"
|
|
|
|
static u64 zram_stat64_read(struct zram *zram, u64 *v)
|
|
{
|
|
u64 val;
|
|
|
|
spin_lock(&zram->stat64_lock);
|
|
val = *v;
|
|
spin_unlock(&zram->stat64_lock);
|
|
|
|
return val;
|
|
}
|
|
|
|
static struct zram *dev_to_zram(struct device *dev)
|
|
{
|
|
int i;
|
|
struct zram *zram = NULL;
|
|
|
|
for (i = 0; i < zram_get_num_devices(); i++) {
|
|
zram = &zram_devices[i];
|
|
if (disk_to_dev(zram->disk) == dev)
|
|
break;
|
|
}
|
|
|
|
return zram;
|
|
}
|
|
|
|
static ssize_t disksize_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n", zram->disksize);
|
|
}
|
|
|
|
static ssize_t disksize_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t len)
|
|
{
|
|
int ret;
|
|
u64 disksize;
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
ret = kstrtoull(buf, 10, &disksize);
|
|
if (ret)
|
|
return ret;
|
|
|
|
down_write(&zram->init_lock);
|
|
if (zram->init_done) {
|
|
up_write(&zram->init_lock);
|
|
pr_info("Cannot change disksize for initialized device\n");
|
|
return -EBUSY;
|
|
}
|
|
|
|
zram->disksize = PAGE_ALIGN(disksize);
|
|
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
|
|
up_write(&zram->init_lock);
|
|
|
|
return len;
|
|
}
|
|
|
|
static ssize_t initstate_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%u\n", zram->init_done);
|
|
}
|
|
|
|
static ssize_t reset_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t len)
|
|
{
|
|
int ret;
|
|
unsigned short do_reset;
|
|
struct zram *zram;
|
|
struct block_device *bdev;
|
|
|
|
zram = dev_to_zram(dev);
|
|
bdev = bdget_disk(zram->disk, 0);
|
|
|
|
/* Do not reset an active device! */
|
|
if (bdev->bd_holders)
|
|
return -EBUSY;
|
|
|
|
ret = kstrtou16(buf, 10, &do_reset);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (!do_reset)
|
|
return -EINVAL;
|
|
|
|
/* Make sure all pending I/O is finished */
|
|
if (bdev)
|
|
fsync_bdev(bdev);
|
|
|
|
down_write(&zram->init_lock);
|
|
if (zram->init_done)
|
|
__zram_reset_device(zram);
|
|
up_write(&zram->init_lock);
|
|
|
|
return len;
|
|
}
|
|
|
|
static ssize_t num_reads_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n",
|
|
zram_stat64_read(zram, &zram->stats.num_reads));
|
|
}
|
|
|
|
static ssize_t num_writes_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n",
|
|
zram_stat64_read(zram, &zram->stats.num_writes));
|
|
}
|
|
|
|
static ssize_t invalid_io_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n",
|
|
zram_stat64_read(zram, &zram->stats.invalid_io));
|
|
}
|
|
|
|
static ssize_t notify_free_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n",
|
|
zram_stat64_read(zram, &zram->stats.notify_free));
|
|
}
|
|
|
|
static ssize_t zero_pages_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%u\n", zram->stats.pages_zero);
|
|
}
|
|
|
|
static ssize_t orig_data_size_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n",
|
|
(u64)(zram->stats.pages_stored) << PAGE_SHIFT);
|
|
}
|
|
|
|
static ssize_t compr_data_size_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
return sprintf(buf, "%llu\n",
|
|
zram_stat64_read(zram, &zram->stats.compr_size));
|
|
}
|
|
|
|
static ssize_t mem_used_total_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
u64 val = 0;
|
|
struct zram *zram = dev_to_zram(dev);
|
|
|
|
if (zram->init_done)
|
|
val = zs_get_total_size_bytes(zram->mem_pool);
|
|
|
|
return sprintf(buf, "%llu\n", val);
|
|
}
|
|
|
|
static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
|
|
disksize_show, disksize_store);
|
|
static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
|
|
static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
|
|
static DEVICE_ATTR(num_reads, S_IRUGO, num_reads_show, NULL);
|
|
static DEVICE_ATTR(num_writes, S_IRUGO, num_writes_show, NULL);
|
|
static DEVICE_ATTR(invalid_io, S_IRUGO, invalid_io_show, NULL);
|
|
static DEVICE_ATTR(notify_free, S_IRUGO, notify_free_show, NULL);
|
|
static DEVICE_ATTR(zero_pages, S_IRUGO, zero_pages_show, NULL);
|
|
static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
|
|
static DEVICE_ATTR(compr_data_size, S_IRUGO, compr_data_size_show, NULL);
|
|
static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
|
|
|
|
static struct attribute *zram_disk_attrs[] = {
|
|
&dev_attr_disksize.attr,
|
|
&dev_attr_initstate.attr,
|
|
&dev_attr_reset.attr,
|
|
&dev_attr_num_reads.attr,
|
|
&dev_attr_num_writes.attr,
|
|
&dev_attr_invalid_io.attr,
|
|
&dev_attr_notify_free.attr,
|
|
&dev_attr_zero_pages.attr,
|
|
&dev_attr_orig_data_size.attr,
|
|
&dev_attr_compr_data_size.attr,
|
|
&dev_attr_mem_used_total.attr,
|
|
NULL,
|
|
};
|
|
|
|
struct attribute_group zram_disk_attr_group = {
|
|
.attrs = zram_disk_attrs,
|
|
};
|