Re: [PATCHv2 10/10] zram: add dynamic device add/remove functionality

From: Minchan Kim
Date: Wed Apr 22 2015 - 23:12:34 EST


On Thu, Apr 23, 2015 at 12:06 PM, Minchan Kim <minchan@xxxxxxxxxx> wrote:
> On Thu, Apr 16, 2015 at 08:55:56PM +0900, Sergey Senozhatsky wrote:
>> We currently don't support on-demand device creation. The one and only way
>> to have N zram devices is to specify num_devices module parameter (default
>> value 1). That means that if, for some reason, at some point, user wants
>> to have N + 1 devies he/she must umount all the existing devices, unload
>> the module, load the module passing num_devices equals to N + 1. And do
>> this again, if needed.
>>
>> This patch introduces zram control sysfs class, which has two sysfs
>> attrs:
>> - zram_add -- add a new zram device
>> - zram_remove -- remove a specific (device_id) zram device
>>
>> zram_add sysfs attr is read-only and has only automatic device id assignment
>> mode (as requested by Minchan Kim). read operation performed on this attr
>> creates a new zram device and returns back its device_id or error status.
>>
>> Usage example:
>> # add a new specific zram device
>> cat /sys/class/zram-control/zram_add
>> 2
>>
>> # remove a specific zram device
>> echo 4 > /sys/class/zram-control/zram_remove
>>
>> Returning zram_add() error code back to user (-ENOMEM in this case)
>>
>> cat /sys/class/zram-control/zram_add
>> cat: /sys/class/zram-control/zram_add: Cannot allocate memory
>>
>> NOTE, there might be users who already depend on the fact that at
>> least zram0 device gets always created by zram_init(). Preserve this
>> behavior.
>>
>> [Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>: fix comment layout]
>> Reported-by: Minchan Kim <minchan@xxxxxxxxxx>
>> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
>> ---
>> Documentation/ABI/testing/sysfs-class-zram | 24 ++++++
>> Documentation/blockdev/zram.txt | 23 +++++-
>> drivers/block/zram/zram_drv.c | 124 ++++++++++++++++++++++++++++-
>> 3 files changed, 166 insertions(+), 5 deletions(-)
>> create mode 100644 Documentation/ABI/testing/sysfs-class-zram
>>
>> diff --git a/Documentation/ABI/testing/sysfs-class-zram b/Documentation/ABI/testing/sysfs-class-zram
>> new file mode 100644
>> index 0000000..6f62ef5
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-class-zram
>> @@ -0,0 +1,24 @@
>> +What: /sys/class/zram-control/
>> +Date: August 2015
>> +KernelVersion: 4.1
>> +Contact: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
>> +Description:
>> + The zram-control/ class sub-directory belongs to zram
>> + device class
>> +
>> +What: /sys/class/zram-control/zram_add
>> +Date: August 2015
>> +KernelVersion: 4.1
>> +Contact: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
>> +Description:
>> + RO attribute. Read operation will cause zram to add a new
>> + device and return its device id back to user (so one can
>> + use /dev/zram<id>), or error code.
>> +
>> +What: /sys/class/zram-control/zram_add
>> +Date: August 2015
>> +KernelVersion: 4.1
>> +Contact: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
>> +Description:
>> + Remove a specific /dev/zramX device, where X is a device_id
>> + provided by user
>> diff --git a/Documentation/blockdev/zram.txt b/Documentation/blockdev/zram.txt
>> index 2ccc741..44b1a77 100644
>> --- a/Documentation/blockdev/zram.txt
>> +++ b/Documentation/blockdev/zram.txt
>> @@ -99,7 +99,24 @@ size of the disk when not in use so a huge zram is wasteful.
>> mkfs.ext4 /dev/zram1
>> mount /dev/zram1 /tmp
>>
>> -7) Stats:
>> +7) Add/remove zram devices
>> +
>> +zram provides a control interface, which enables dynamic (on-demand) device
>> +addition and removal.
>> +
>> +In order to add a new /dev/zramX device, perform read operation on zram_add
>> +attribute. This will return either new device's device id (meaning that you
>> +can use /dev/zram<id>) or error code.
>> +
>> +Example:
>> + cat /sys/class/zram-control/zram_add
>
> Why do we put zram-contol there rather than /sys/block/zram

Forget this. I tried to remove the comment but sent by mistake.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/