Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0231c403 authored by Minchan Kim's avatar Minchan Kim Committed by Greg Kroah-Hartman
Browse files

zram: force disksize setting before using zram



Now zram document syas "set disksize is optional"
but partly it's wrong. When you try to use zram firstly after
booting, you must set disksize, otherwise zram can't work because
zram gendisk's size is 0. But once you do it, you can use zram freely
after reset because reset doesn't reset to zero paradoxically.
So in this time, disksize setting is optional.:(
It's inconsitent for user behavior and not straightforward.

This patch forces always setting disksize firstly before using zram.
Yes. It changes current behavior so someone could complain when
he upgrades zram. Apparently it could be a problem if zram is mainline
but it still lives in staging so behavior could be changed for right
way to go. Let them excuse.

Acked-by: default avatarJerome Marchand <jmarchand@redhat.com>
Acked-by: default avatarNitin Gupta <ngupta@vflare.org>
Acked-by: default avatarDan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: default avatarMinchan Kim <minchan@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7e5a5104
Loading
Loading
Loading
Loading
+14 −13
Original line number Original line Diff line number Diff line
@@ -23,17 +23,17 @@ Following shows a typical sequence of steps for using zram.
	This creates 4 devices: /dev/zram{0,1,2,3}
	This creates 4 devices: /dev/zram{0,1,2,3}
	(num_devices parameter is optional. Default: 1)
	(num_devices parameter is optional. Default: 1)


2) Set Disksize (Optional):
2) Set Disksize
	Set disk size by writing the value to sysfs node 'disksize'
        Set disk size by writing the value to sysfs node 'disksize'.
	(in bytes). If disksize is not given, default value of 25%
        The value can be either in bytes or you can use mem suffixes.
	of RAM is used.
        Examples:

            # Initialize /dev/zram0 with 50MB disksize
            # Initialize /dev/zram0 with 50MB disksize
            echo $((50*1024*1024)) > /sys/block/zram0/disksize
            echo $((50*1024*1024)) > /sys/block/zram0/disksize


	NOTE: disksize cannot be changed if the disk contains any
            # Using mem suffixes
	data. So, for such a disk, you need to issue 'reset' (see below)
            echo 256K > /sys/block/zram0/disksize
	before you can change its disksize.
            echo 512M > /sys/block/zram0/disksize
            echo 1G > /sys/block/zram0/disksize


3) Activate:
3) Activate:
	mkswap /dev/zram0
	mkswap /dev/zram0
@@ -65,8 +65,9 @@ Following shows a typical sequence of steps for using zram.
	echo 1 > /sys/block/zram0/reset
	echo 1 > /sys/block/zram0/reset
	echo 1 > /sys/block/zram1/reset
	echo 1 > /sys/block/zram1/reset


	(This frees all the memory allocated for the given device).
	This frees all the memory allocated for the given device and

	resets the disksize to zero. You must set the disksize again
	before reusing the device.


Please report any problems at:
Please report any problems at:
 - Mailing list: linux-mm-cc at laptop dot org
 - Mailing list: linux-mm-cc at laptop dot org
+18 −33
Original line number Original line Diff line number Diff line
@@ -94,34 +94,6 @@ static int page_zero_filled(void *ptr)
	return 1;
	return 1;
}
}


static void zram_set_disksize(struct zram *zram, size_t totalram_bytes)
{
	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);
	}

	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 >> 10);
	}

	zram->disksize &= PAGE_MASK;
}

static void zram_free_page(struct zram *zram, size_t index)
static void zram_free_page(struct zram *zram, size_t index)
{
{
	unsigned long handle = zram->table[index].handle;
	unsigned long handle = zram->table[index].handle;
@@ -497,6 +469,9 @@ void __zram_reset_device(struct zram *zram)
{
{
	size_t index;
	size_t index;


	if (!zram->init_done)
		return;

	zram->init_done = 0;
	zram->init_done = 0;


	/* Free various per-device buffers */
	/* Free various per-device buffers */
@@ -525,6 +500,7 @@ void __zram_reset_device(struct zram *zram)
	memset(&zram->stats, 0, sizeof(zram->stats));
	memset(&zram->stats, 0, sizeof(zram->stats));


	zram->disksize = 0;
	zram->disksize = 0;
	set_capacity(zram->disk, 0);
}
}


void zram_reset_device(struct zram *zram)
void zram_reset_device(struct zram *zram)
@@ -546,7 +522,19 @@ int zram_init_device(struct zram *zram)
		return 0;
		return 0;
	}
	}


	zram_set_disksize(zram, totalram_pages << PAGE_SHIFT);
	if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) {
		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_pages << PAGE_SHIFT) >> 10, zram->disksize >> 10
		);
	}


	zram->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
	zram->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
	if (!zram->compress_workmem) {
	if (!zram->compress_workmem) {
@@ -571,8 +559,6 @@ int zram_init_device(struct zram *zram)
		goto fail_no_table;
		goto fail_no_table;
	}
	}


	set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);

	/* zram devices sort of resembles non-rotational disks */
	/* zram devices sort of resembles non-rotational disks */
	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);


@@ -751,7 +737,6 @@ static void __exit zram_exit(void)
		zram = &zram_devices[i];
		zram = &zram_devices[i];


		destroy_device(zram);
		destroy_device(zram);
		if (zram->init_done)
		zram_reset_device(zram);
		zram_reset_device(zram);
	}
	}


+1 −4
Original line number Original line Diff line number Diff line
@@ -28,9 +28,6 @@ static const unsigned max_num_devices = 32;


/*-- Configurable parameters */
/*-- Configurable parameters */


/* Default zram disk size: 25% of total RAM */
static const unsigned default_disksize_perc_ram = 25;

/*
/*
 * Pages that compress to size greater than this are stored
 * Pages that compress to size greater than this are stored
 * uncompressed in memory.
 * uncompressed in memory.
@@ -115,6 +112,6 @@ extern struct attribute_group zram_disk_attr_group;
#endif
#endif


extern int zram_init_device(struct zram *zram);
extern int zram_init_device(struct zram *zram);
extern void __zram_reset_device(struct zram *zram);
extern void zram_reset_device(struct zram *zram);


#endif
#endif
+1 −5
Original line number Original line Diff line number Diff line
@@ -110,11 +110,7 @@ static ssize_t reset_store(struct device *dev,
	if (bdev)
	if (bdev)
		fsync_bdev(bdev);
		fsync_bdev(bdev);


	down_write(&zram->init_lock);
	zram_reset_device(zram);
	if (zram->init_done)
		__zram_reset_device(zram);
	up_write(&zram->init_lock);

	return len;
	return len;
}
}