static ssize_t disksize_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
+ int ret;
u64 disksize;
struct zram_meta *meta;
struct zram *zram = dev_to_zram(dev);
+
+ /* Get disksize from user */
+ ret = kstrtoull(buf, 10, &disksize);
+ if (ret)
+ return ret;
- disksize = memparse(buf, NULL);
- if (!disksize)
- return -EINVAL;
+ /* If disksize is 0, then we give it a default setting. */
+ if (disksize == 0) {
+ /* Fix disksize */
+ disksize = default_disksize_perc_ram * ((totalram_pages << PAGE_SHIFT) / 100);
+ /* Expand its disksize if we have little system ram! */
+ if (totalram_pages < SUPPOSED_TOTALRAM) {
+ disksize += (disksize >> 1) ;
+ }
+ }
+
+ /* Align it! */
+ disksize = round_up(disksize, DISKSIZE_ALIGNMENT);
+ /* disksize = PAGE_ALIGN(disksize); */
- disksize = PAGE_ALIGN(disksize);
meta = zram_meta_alloc(disksize);
+ /* Check whether meta is null */
+ if (!meta) {
+ printk(KERN_ALERT"Failed to allocate memory for meta!\n");
+ return len;
+ }
down_write(&zram->init_lock);
if (zram->init_done) {
up_write(&zram->init_lock);
return sprintf(buf, "%u\n", zram->stats.pages_zero);
}
+static ssize_t good_compr_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.good_compress);
+}
+
+static ssize_t bad_compr_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.bad_compress);
+}
+
static ssize_t orig_data_size_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
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(good_compr_pages, S_IRUGO, good_compr_pages_show, NULL);
+static DEVICE_ATTR(bad_compr_pages, S_IRUGO, bad_compr_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);
&dev_attr_invalid_io.attr,
&dev_attr_notify_free.attr,
&dev_attr_zero_pages.attr,
+ &dev_attr_good_compr_pages.attr,
+ &dev_attr_bad_compr_pages.attr,
&dev_attr_orig_data_size.attr,
&dev_attr_compr_data_size.attr,
&dev_attr_mem_used_total.attr,