KernelVersion: 4.1
Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Description:
- Add a specific /dev/zramX device, where X is a device_id
- provided by user
+ RW attribuite. Write operation adds a specific /dev/zramX
+ device, where X is a device_id provided by user.
+ Read operation will automatically pick up avilable device_id
+ X, add /dev/zramX device and return that device_id X back to
+ user.
What: /sys/class/zram-control/zram_add
Date: March 2015
execute
echo X > /sys/class/zram-control/zram_remove
+Additionally, zram also handles automatic device_id generation and assignment.
+
+ cat /sys/class/zram-control/zram_add
+ 1
+ cat /sys/class/zram-control/zram_add
+ 2
+
+this will pick up available device_id X, add corresponding /dev/zramX
+device and return its device_id X back to user (or error code).
+
8) Stats:
Per-device statistics are exported as various nodes under
/sys/block/zram<id>/
if (!zram)
return ret;
- ret = idr_alloc(&zram_index_idr, zram, device_id,
- device_id + 1, GFP_KERNEL);
+ if (device_id < 0) {
+ /* generate new device_id */
+ ret = idr_alloc(&zram_index_idr, zram, 0, 0, GFP_KERNEL);
+ device_id = ret;
+ } else {
+ /* use provided device_id */
+ ret = idr_alloc(&zram_index_idr, zram, device_id,
+ device_id + 1, GFP_KERNEL);
+ }
if (ret < 0)
goto out_free_dev;
return ret ? ret : count;
}
+static ssize_t zram_add_show(struct class *class,
+ struct class_attribute *attr,
+ char *buf)
+{
+ int ret;
+
+ mutex_lock(&zram_index_mutex);
+ /* read operation on zram_add is - pick up device_id
+ * automatically, add corresponding device and return
+ * that device_id back to user */
+ ret = zram_add(-1);
+ mutex_unlock(&zram_index_mutex);
+
+ if (ret < 0)
+ return ret;
+ return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
+}
+
static ssize_t zram_remove_store(struct class *class,
struct class_attribute *attr,
const char *buf,
}
static struct class_attribute zram_control_class_attrs[] = {
- __ATTR_WO(zram_add),
+ __ATTR_RW(zram_add),
__ATTR_WO(zram_remove),
__ATTR_NULL,
};