Hello Sergey, While I test this patch, I got this warning. I used attached script to reproduce it. You should run several copy of script to reproduce it like below.
#>./dynamic_remove.sh & #>./dynamic_remove.sh & Hope you investigate the problem. ... ... [74G[ OK ] * Starting MD monitoring service mdadm --monitor [80G [74G[ OK ] * Checking battery state... [80G grep: /sys/power/state: No such file or directory grep: /sys/power/state: No such file or directory grep: /sys/power/state: No such file or directory [74G[ OK ] [ 10.961394] init: plymouth-stop pre-start process (1441) terminated with status 1 [ 11.655424] random: nonblocking pool is initialized [ 98.106916] zram: Added device: zram1 [ 98.108124] zram1: detected capacity change from 0 to 20971520 [ 98.111037] zram: Added device: zram2 [ 98.112876] zram2: detected capacity change from 0 to 20971520 [ 98.118034] zram: Added device: zram3 [ 98.119691] zram3: detected capacity change from 0 to 20971520 [ 98.123948] zram: Added device: zram4 [ 98.125205] zram4: detected capacity change from 0 to 20971520 [ 98.129088] zram: Added device: zram5 [ 98.129998] zram5: detected capacity change from 0 to 20971520 [ 98.133486] zram: Added device: zram6 [ 98.134579] zram6: detected capacity change from 0 to 20971520 [ 98.138140] zram: Added device: zram7 [ 98.140175] zram7: detected capacity change from 0 to 20971520 [ 98.143433] zram: Added device: zram8 [ 98.144389] zram8: detected capacity change from 0 to 20971520 [ 98.147172] zram: Added device: zram9 [ 98.148574] zram9: detected capacity change from 0 to 20971520 [ 98.151807] zram: Added device: zram10 [ 98.153247] zram10: detected capacity change from 0 to 20971520 [ 98.158626] zram: Added device: zram11 [ 98.159785] zram11: detected capacity change from 0 to 20971520 [ 98.163183] zram: Added device: zram12 [ 98.165138] zram12: detected capacity change from 0 to 20971520 [ 98.168077] zram: Added device: zram13 [ 98.169060] zram13: detected capacity change from 0 to 20971520 [ 98.172264] zram: Added device: zram14 [ 98.173445] zram14: detected capacity change from 0 to 20971520 [ 98.176820] zram: Added device: zram15 [ 98.177804] zram15: detected capacity change from 0 to 20971520 [ 98.180816] zram: Added device: zram16 [ 98.182020] zram16: detected capacity change from 0 to 20971520 [ 98.185495] zram: Added device: zram17 [ 98.187245] zram17: detected capacity change from 0 to 20971520 [ 98.191791] zram: Added device: zram18 [ 98.192925] zram18: detected capacity change from 0 to 20971520 [ 98.196314] zram: Added device: zram19 [ 98.198937] zram19: detected capacity change from 0 to 20971520 [ 98.202523] zram: Added device: zram20 [ 98.203615] zram20: detected capacity change from 0 to 20971520 [ 98.207473] zram: Added device: zram21 [ 98.208529] zram21: detected capacity change from 0 to 20971520 [ 98.211940] zram: Added device: zram22 [ 98.212839] zram22: detected capacity change from 0 to 20971520 [ 98.216381] zram: Added device: zram23 [ 98.217278] zram23: detected capacity change from 0 to 20971520 [ 98.219953] zram: Added device: zram24 [ 98.222805] zram24: detected capacity change from 0 to 20971520 [ 98.226039] zram: Added device: zram25 [ 98.227008] zram25: detected capacity change from 0 to 20971520 [ 98.246547] zram: Removed device: zram4 [ 98.316665] zram: Removed device: zram8 [ 98.330010] zram: Removed device: zram1 [ 98.364826] zram: Removed device: zram3 [ 98.393897] zram: Removed device: zram5 [ 98.395801] zram: Removed device: zram6 [ 98.399364] zram: Removed device: zram7 [ 98.405376] zram: Removed device: zram11 [ 98.408452] zram: Removed device: zram12 [ 98.420747] zram: Removed device: zram14 [ 98.433739] zram: Removed device: zram15 [ 98.447536] zram: Removed device: zram16 [ 98.450580] zram: Removed device: zram17 [ 98.457826] zram: Removed device: zram18 [ 98.459562] zram: Removed device: zram19 [ 98.461362] zram: Removed device: zram20 [ 98.463272] zram: Removed device: zram21 [ 98.464454] zram: Removed device: zram22 [ 98.465547] zram: Removed device: zram23 [ 98.466794] zram: Removed device: zram24 [ 98.467938] zram: Removed device: zram25 [ 98.470475] zram: Removed device: zram2 [ 98.472080] zram: Removed device: zram9 [ 98.473410] zram: Removed device: zram10 [ 98.474974] zram: Removed device: zram13 [ 98.480408] zram: Added device: zram1 [ 98.481656] zram1: detected capacity change from 0 to 20971520 [ 98.484709] zram: Added device: zram2 [ 98.485533] zram2: detected capacity change from 0 to 20971520 [ 98.490166] zram: Added device: zram3 [ 98.491463] zram3: detected capacity change from 0 to 20971520 [ 98.495471] zram: Added device: zram4 [ 98.496793] zram4: detected capacity change from 0 to 20971520 [ 98.499398] zram: Added device: zram5 [ 98.500522] zram5: detected capacity change from 0 to 20971520 [ 98.507491] zram: Added device: zram6 [ 98.508370] zram6: detected capacity change from 0 to 20971520 [ 98.518639] zram: Added device: zram7 [ 98.519697] zram7: detected capacity change from 0 to 20971520 [ 98.522650] zram: Added device: zram8 [ 98.523507] zram8: detected capacity change from 0 to 20971520 [ 98.525985] zram: Added device: zram9 [ 98.527046] zram9: detected capacity change from 0 to 20971520 [ 98.531154] zram: Added device: zram10 [ 98.532390] zram10: detected capacity change from 0 to 20971520 [ 98.535335] zram: Added device: zram11 [ 98.536179] zram11: detected capacity change from 0 to 20971520 [ 98.538633] zram: Added device: zram12 [ 98.539812] zram12: detected capacity change from 0 to 20971520 [ 98.545105] zram: Added device: zram13 [ 98.546696] zram13: detected capacity change from 0 to 20971520 [ 98.550453] zram: Added device: zram14 [ 98.551394] zram14: detected capacity change from 0 to 20971520 [ 98.556193] zram: Added device: zram15 [ 98.557564] zram15: detected capacity change from 0 to 20971520 [ 98.561741] zram: Added device: zram16 [ 98.562799] zram16: detected capacity change from 0 to 20971520 [ 98.565537] zram: Added device: zram17 [ 98.566344] zram17: detected capacity change from 0 to 20971520 [ 98.569192] zram: Added device: zram18 [ 98.570437] zram18: detected capacity change from 0 to 20971520 [ 98.573588] zram: Added device: zram19 [ 98.574826] zram19: detected capacity change from 0 to 20971520 [ 98.578450] zram: Added device: zram20 [ 98.579623] zram20: detected capacity change from 0 to 20971520 [ 98.582528] zram: Added device: zram21 [ 98.584440] zram21: detected capacity change from 0 to 20971520 [ 98.587922] zram: Added device: zram22 [ 98.589239] zram22: detected capacity change from 0 to 20971520 [ 98.593854] zram: Added device: zram23 [ 98.595130] zram23: detected capacity change from 0 to 20971520 [ 98.598610] zram: Added device: zram24 [ 98.599953] zram24: detected capacity change from 0 to 20971520 [ 98.603456] zram: Added device: zram25 [ 98.604706] zram25: detected capacity change from 0 to 20971520 [ 98.631424] zram: Removed device: zram11 [ 98.639214] zram: Removed device: zram14 [ 98.647116] zram: Removed device: zram15 [ 98.756017] zram: Removed device: zram2 [ 98.757087] ------------[ cut here ]------------ [ 98.758349] WARNING: CPU: 5 PID: 2952 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x68/0x80() [ 98.760065] sysfs: cannot create duplicate filename '/devices/virtual/bdi/252:2' [ 98.761061] Modules linked in: [ 98.761530] CPU: 5 PID: 2952 Comm: cat Not tainted 4.1.0-rc2-next-20150505+ #1260 [ 98.762682] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 [ 98.764140] ffff88005d40f948 ffff88005d40f948 ffffffff8163d8d8 0000000000000000 [ 98.765614] ffff88005d40f998 ffff88005d40f988 ffffffff8105f02a 0000000000000000 [ 98.766815] ffff8800653c2000 ffff88007f526210 ffff88004b3aa1c8 ffff880065799360 [ 98.768980] Call Trace: [ 98.769643] [<ffffffff8163d8d8>] dump_stack+0x4c/0x65 [ 98.770431] [<ffffffff8105f02a>] warn_slowpath_common+0x8a/0xc0 [ 98.771353] [<ffffffff8105f0a6>] warn_slowpath_fmt+0x46/0x50 [ 98.772220] [<ffffffff8105f065>] ? warn_slowpath_fmt+0x5/0x50 [ 98.773099] [<ffffffff8126d748>] sysfs_warn_dup+0x68/0x80 [ 98.773903] [<ffffffff8126d6e5>] ? sysfs_warn_dup+0x5/0x80 [ 98.774750] [<ffffffff8126d7ee>] sysfs_create_dir_ns+0x8e/0xa0 [ 98.775794] [<ffffffff8126d765>] ? sysfs_create_dir_ns+0x5/0xa0 [ 98.776672] [<ffffffff813710d5>] kobject_add_internal+0xa5/0x2f0 [ 98.777737] [<ffffffff81644133>] ? __mutex_unlock_slowpath+0xb3/0x180 [ 98.778765] [<ffffffff81371500>] kobject_add+0x60/0xb0 [ 98.779598] [<ffffffff81465fe5>] ? get_device_parent+0x5/0x200 [ 98.780430] [<ffffffff81466552>] device_add+0x102/0x5b0 [ 98.780956] [<ffffffff81466455>] ? device_add+0x5/0x5b0 [ 98.781513] [<ffffffff81466c18>] device_create_groups_vargs+0xd8/0x100 [ 98.782119] [<ffffffff81466c45>] ? device_create_vargs+0x5/0x20 [ 98.782851] [<ffffffff81466c5c>] device_create_vargs+0x1c/0x20 [ 98.783464] [<ffffffff81198e37>] bdi_register+0x67/0x2a0 [ 98.784081] [<ffffffff81199075>] ? bdi_register_dev+0x5/0x30 [ 98.784609] [<ffffffff81199097>] bdi_register_dev+0x27/0x30 [ 98.785139] [<ffffffff81359f29>] add_disk+0x1b9/0x4e0 [ 98.785844] [<ffffffff8137a9a4>] ? snprintf+0x34/0x40 [ 98.786353] [<ffffffff814867cc>] zram_add+0x1ec/0x2f0 [ 98.786833] [<ffffffff814868f2>] zram_add_show+0x22/0x60 [ 98.787344] [<ffffffff81469edb>] class_attr_show+0x1b/0x30 [ 98.787848] [<ffffffff8126d1ff>] sysfs_kf_seq_show+0xcf/0x1d0 [ 98.788374] [<ffffffff8126b716>] kernfs_seq_show+0x26/0x30 [ 98.788880] [<ffffffff8120eaf5>] seq_read+0xf5/0x3a0 [ 98.789338] [<ffffffff8126c040>] ? kernfs_vma_page_mkwrite+0xa0/0xa0 [ 98.789917] [<ffffffff8126c165>] kernfs_fop_read+0x125/0x180 [ 98.790483] [<ffffffff811e5c98>] __vfs_read+0x28/0xe0 [ 98.790959] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.791476] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.791952] [<ffffffff811e62e6>] vfs_read+0x86/0x140 [ 98.792418] [<ffffffff81207fa7>] ? __fdget_pos+0x17/0x50 [ 98.792908] [<ffffffff811e7179>] SyS_read+0x49/0xb0 [ 98.793360] [<ffffffff81646f97>] system_call_fastpath+0x12/0x6f [ 98.793903] ---[ end trace e1035d8c51ec986c ]--- [ 98.794358] ------------[ cut here ]------------ [ 98.794783] WARNING: CPU: 5 PID: 2952 at lib/kobject.c:240 kobject_add_internal+0x284/0x2f0() [ 98.795999] kobject_add_internal failed for 252:2 with -EEXIST, don't try to register things with the same name in the same directory. [ 98.797097] Modules linked in: [ 98.797396] CPU: 5 PID: 2952 Comm: cat Tainted: G W 4.1.0-rc2-next-20150505+ #1260 [ 98.798173] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 [ 98.798951] ffff88005d40f9a8 ffff88005d40f9a8 ffffffff8163d8d8 0000000000000000 [ 98.799689] ffff88005d40f9f8 ffff88005d40f9e8 ffffffff8105f02a 0000000000000000 [ 98.800383] ffff88007f64a410 ffff880065799360 00000000ffffffef ffff880065799360 [ 98.801096] Call Trace: [ 98.801330] [<ffffffff8163d8d8>] dump_stack+0x4c/0x65 [ 98.801800] [<ffffffff8105f02a>] warn_slowpath_common+0x8a/0xc0 [ 98.802383] [<ffffffff8105f0a6>] warn_slowpath_fmt+0x46/0x50 [ 98.802908] [<ffffffff813708b6>] ? kobj_kset_leave+0x46/0x60 [ 98.803437] [<ffffffff8105f065>] ? warn_slowpath_fmt+0x5/0x50 [ 98.803967] [<ffffffff813712b4>] kobject_add_internal+0x284/0x2f0 [ 98.804662] [<ffffffff81644133>] ? __mutex_unlock_slowpath+0xb3/0x180 [ 98.805255] [<ffffffff81371500>] kobject_add+0x60/0xb0 [ 98.805734] [<ffffffff81465fe5>] ? get_device_parent+0x5/0x200 [ 98.806273] [<ffffffff81466552>] device_add+0x102/0x5b0 [ 98.806790] [<ffffffff81466455>] ? device_add+0x5/0x5b0 [ 98.807404] [<ffffffff81466c18>] device_create_groups_vargs+0xd8/0x100 [ 98.808039] [<ffffffff81466c45>] ? device_create_vargs+0x5/0x20 [ 98.808595] [<ffffffff81466c5c>] device_create_vargs+0x1c/0x20 [ 98.809120] [<ffffffff81198e37>] bdi_register+0x67/0x2a0 [ 98.809604] [<ffffffff81199075>] ? bdi_register_dev+0x5/0x30 [ 98.810101] [<ffffffff81199097>] bdi_register_dev+0x27/0x30 [ 98.810685] [<ffffffff81359f29>] add_disk+0x1b9/0x4e0 [ 98.811155] [<ffffffff8137a9a4>] ? snprintf+0x34/0x40 [ 98.811616] [<ffffffff814867cc>] zram_add+0x1ec/0x2f0 [ 98.812069] [<ffffffff814868f2>] zram_add_show+0x22/0x60 [ 98.812550] [<ffffffff81469edb>] class_attr_show+0x1b/0x30 [ 98.813076] [<ffffffff8126d1ff>] sysfs_kf_seq_show+0xcf/0x1d0 [ 98.813592] [<ffffffff8126b716>] kernfs_seq_show+0x26/0x30 [ 98.814069] [<ffffffff8120eaf5>] seq_read+0xf5/0x3a0 [ 98.814599] [<ffffffff8126c040>] ? kernfs_vma_page_mkwrite+0xa0/0xa0 [ 98.815179] [<ffffffff8126c165>] kernfs_fop_read+0x125/0x180 [ 98.815716] [<ffffffff811e5c98>] __vfs_read+0x28/0xe0 [ 98.816153] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.816601] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.817051] [<ffffffff811e62e6>] vfs_read+0x86/0x140 [ 98.817485] [<ffffffff81207fa7>] ? __fdget_pos+0x17/0x50 [ 98.817950] [<ffffffff811e7179>] SyS_read+0x49/0xb0 [ 98.818455] [<ffffffff81646f97>] system_call_fastpath+0x12/0x6f [ 98.818985] ---[ end trace e1035d8c51ec986d ]--- [ 98.819810] BUG: unable to handle kernel NULL pointer dereference at 0000000000000040 [ 98.820591] IP: [<ffffffff8126da50>] sysfs_do_create_link_sd.isra.2+0x40/0xd0 [ 98.821290] PGD 61669067 PUD 61553067 PMD 0 [ 98.821709] Oops: 0000 [#1] SMP [ 98.822047] Dumping ftrace buffer: [ 98.822425] (ftrace buffer empty) [ 98.822763] Modules linked in: [ 98.823056] CPU: 5 PID: 2952 Comm: cat Tainted: G W 4.1.0-rc2-next-20150505+ #1260 [ 98.823663] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 [ 98.823663] task: ffff880056942140 ti: ffff88005d40c000 task.ti: ffff88005d40c000 [ 98.823663] RIP: 0010:[<ffffffff8126da50>] [<ffffffff8126da50>] sysfs_do_create_link_sd.isra.2+0x40/0xd0 [ 98.823663] RSP: 0018:ffff88005d40fc28 EFLAGS: 00010292 [ 98.823663] RAX: ffff880056942140 RBX: 0000000000000040 RCX: 0000000006da06d9 [ 98.823663] RDX: 0000000006d906d9 RSI: 1ca0f28c302c6000 RDI: ffffffff81c82ca0 [ 98.823663] RBP: ffff88005d40fc58 R08: 0000000000000001 R09: 0000000000000000 [ 98.823663] R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff819f9187 [ 98.823663] R13: ffff880061ca2688 R14: 0000000000000001 R15: ffff88007f64c490 [ 98.823663] FS: 00007f1262ed4700(0000) GS:ffff880068140000(0000) knlGS:0000000000000000 [ 98.823663] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 98.823663] CR2: 0000000000000040 CR3: 000000005fc77000 CR4: 00000000000007e0 [ 98.823663] Stack: [ 98.823663] ffffffff8135931b ffff88007f64c400 ffff88007f64c4a0 ffff88005f889660 [ 98.823663] ffff88007f64c40c ffff88007f64c490 ffff88005d40fc68 ffffffff8126db05 [ 98.823663] ffff88005d40fcd8 ffffffff81359fc2 ffff88007f64c400 ffffffff8137a9a4 [ 98.823663] Call Trace: [ 98.823663] [<ffffffff8135931b>] ? disk_part_iter_next+0x2b/0x280 [ 98.823663] [<ffffffff8126db05>] sysfs_create_link+0x25/0x50 [ 98.823663] [<ffffffff81359fc2>] add_disk+0x252/0x4e0 [ 98.823663] [<ffffffff8137a9a4>] ? snprintf+0x34/0x40 [ 98.823663] [<ffffffff814867cc>] zram_add+0x1ec/0x2f0 [ 98.823663] [<ffffffff814868f2>] zram_add_show+0x22/0x60 [ 98.823663] [<ffffffff81469edb>] class_attr_show+0x1b/0x30 [ 98.823663] [<ffffffff8126d1ff>] sysfs_kf_seq_show+0xcf/0x1d0 [ 98.823663] [<ffffffff8126b716>] kernfs_seq_show+0x26/0x30 [ 98.823663] [<ffffffff8120eaf5>] seq_read+0xf5/0x3a0 [ 98.823663] [<ffffffff8126c040>] ? kernfs_vma_page_mkwrite+0xa0/0xa0 [ 98.823663] [<ffffffff8126c165>] kernfs_fop_read+0x125/0x180 [ 98.823663] [<ffffffff811e5c98>] __vfs_read+0x28/0xe0 [ 98.823663] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.823663] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.823663] [<ffffffff811e62e6>] vfs_read+0x86/0x140 [ 98.823663] [<ffffffff81207fa7>] ? __fdget_pos+0x17/0x50 [ 98.823663] [<ffffffff811e7179>] SyS_read+0x49/0xb0 [ 98.823663] [<ffffffff81646f97>] system_call_fastpath+0x12/0x6f [ 98.823663] Code: 48 83 ec 08 48 85 d2 0f 84 8e 00 00 00 48 85 ff 49 89 fd 0f 84 82 00 00 00 48 89 f3 48 c7 c7 a0 2c c8 81 41 89 ce e8 f0 89 3d 00 <48> 8b 1b 48 85 db 74 48 48 89 df e8 c0 bf ff ff 48 c7 c7 a0 2c [ 98.823663] RIP [<ffffffff8126da50>] sysfs_do_create_link_sd.isra.2+0x40/0xd0 [ 98.823663] RSP <ffff88005d40fc28> [ 98.823663] CR2: 0000000000000040 [ 98.823663] ---[ end trace e1035d8c51ec986e ]--- [ 98.823663] BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:21 [ 98.823663] in_atomic(): 1, irqs_disabled(): 1, pid: 2952, name: cat [ 98.823663] INFO: lockdep is turned off. [ 98.823663] irq event stamp: 3392 [ 98.823663] hardirqs last enabled at (3391): [<ffffffff81644133>] __mutex_unlock_slowpath+0xb3/0x180 [ 98.823663] hardirqs last disabled at (3392): [<ffffffff81648d33>] error_sti+0x5/0x6 [ 98.823663] softirqs last enabled at (0): [<ffffffff8105c6a9>] copy_process.part.35+0x4d9/0x1ce0 [ 98.823663] softirqs last disabled at (0): [< (null)>] (null) [ 98.823663] CPU: 5 PID: 2952 Comm: cat Tainted: G D W 4.1.0-rc2-next-20150505+ #1260 [ 98.823663] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 [ 98.823663] ffff88005d40f8c8 ffff88005d40f8c8 ffffffff8163d8d8 0000000000000000 [ 98.823663] 0000000000000000 ffff88005d40f8f8 ffffffff8108c18e ffffffff8108c005 [ 98.823663] ffffffff819ec8b3 0000000000000015 0000000000000000 ffff88005d40f928 [ 98.823663] Call Trace: [ 98.823663] [<ffffffff8163d8d8>] dump_stack+0x4c/0x65 [ 98.823663] [<ffffffff8108c18e>] ___might_sleep+0x18e/0x250 [ 98.823663] [<ffffffff8108c005>] ? ___might_sleep+0x5/0x250 [ 98.823663] [<ffffffff8108c29d>] __might_sleep+0x4d/0x90 [ 98.823663] [<ffffffff8108c255>] ? __might_sleep+0x5/0x90 [ 98.823663] [<ffffffff81644494>] down_read+0x24/0x70 [ 98.823663] [<ffffffff81644475>] ? down_read+0x5/0x70 [ 98.823663] [<ffffffff810722a4>] ? exit_signals+0x24/0x130 [ 98.823663] [<ffffffff810722a4>] exit_signals+0x24/0x130 [ 98.823663] [<ffffffff81072285>] ? exit_signals+0x5/0x130 [ 98.823663] [<ffffffff810606f8>] ? do_exit+0xb8/0xbc0 [ 98.823663] [<ffffffff810606f8>] do_exit+0xb8/0xbc0 [ 98.823663] [<ffffffff81060645>] ? do_exit+0x5/0xbc0 [ 98.823663] [<ffffffff810c4a79>] ? kmsg_dump+0x119/0x1a0 [ 98.823663] [<ffffffff810c4985>] ? kmsg_dump+0x25/0x1a0 [ 98.823663] [<ffffffff8100665e>] oops_end+0x8e/0xd0 [ 98.823663] [<ffffffff810065d5>] ? oops_end+0x5/0xd0 [ 98.823663] [<ffffffff81637f65>] no_context+0x2d9/0x33e [ 98.823663] [<ffffffff81637c91>] ? no_context+0x5/0x33e [ 98.823663] [<ffffffff81638042>] __bad_area_nosemaphore+0x78/0x1d1 [ 98.823663] [<ffffffff816381a0>] ? bad_area_nosemaphore+0x5/0x15 [ 98.823663] [<ffffffff816381ae>] bad_area_nosemaphore+0x13/0x15 [ 98.823663] [<ffffffff8104c4de>] __do_page_fault+0x9e/0x490 [ 98.823663] [<ffffffff8104c445>] ? __do_page_fault+0x5/0x490 [ 98.823663] [<ffffffff8104c8dc>] do_page_fault+0xc/0x10 [ 98.823663] [<ffffffff81648b62>] page_fault+0x22/0x30 [ 98.823663] [<ffffffff8126da50>] ? sysfs_do_create_link_sd.isra.2+0x40/0xd0 [ 98.823663] [<ffffffff8126da50>] ? sysfs_do_create_link_sd.isra.2+0x40/0xd0 [ 98.823663] [<ffffffff8135931b>] ? disk_part_iter_next+0x2b/0x280 [ 98.823663] [<ffffffff8126db05>] sysfs_create_link+0x25/0x50 [ 98.823663] [<ffffffff81359fc2>] add_disk+0x252/0x4e0 [ 98.823663] [<ffffffff8137a9a4>] ? snprintf+0x34/0x40 [ 98.823663] [<ffffffff814867cc>] zram_add+0x1ec/0x2f0 [ 98.823663] [<ffffffff814868f2>] zram_add_show+0x22/0x60 [ 98.823663] [<ffffffff81469edb>] class_attr_show+0x1b/0x30 [ 98.823663] [<ffffffff8126d1ff>] sysfs_kf_seq_show+0xcf/0x1d0 [ 98.823663] [<ffffffff8126b716>] kernfs_seq_show+0x26/0x30 [ 98.823663] [<ffffffff8120eaf5>] seq_read+0xf5/0x3a0 [ 98.823663] [<ffffffff8126c040>] ? kernfs_vma_page_mkwrite+0xa0/0xa0 [ 98.823663] [<ffffffff8126c165>] kernfs_fop_read+0x125/0x180 [ 98.823663] [<ffffffff811e5c98>] __vfs_read+0x28/0xe0 [ 98.823663] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.823663] [<ffffffff811e5c75>] ? __vfs_read+0x5/0xe0 [ 98.823663] [<ffffffff811e62e6>] vfs_read+0x86/0x140 [ 98.823663] [<ffffffff81207fa7>] ? __fdget_pos+0x17/0x50 [ 98.823663] [<ffffffff811e7179>] SyS_read+0x49/0xb0 [ 98.823663] [<ffffffff81646f97>] system_call_fastpath+0x12/0x6f [ 98.823663] note: cat[2952] exited with preempt_count 1 On Mon, May 04, 2015 at 03:57:13PM -0700, [email protected] wrote: > > The patch titled > Subject: zram: add dynamic device add/remove functionality > has been added to the -mm tree. Its filename is > zram-add-dynamic-device-add-remove-functionality.patch > > This patch should soon appear at > > http://ozlabs.org/~akpm/mmots/broken-out/zram-add-dynamic-device-add-remove-functionality.patch > and later at > > http://ozlabs.org/~akpm/mmotm/broken-out/zram-add-dynamic-device-add-remove-functionality.patch > > Before you just go and hit "reply", please: > a) Consider who else should be cc'ed > b) Prefer to cc a suitable mailing list as well > c) Ideally: find the original patch on the mailing list and do a > reply-to-all to that, adding suitable additional cc's > > *** Remember to use Documentation/SubmitChecklist when testing your code *** > > The -mm tree is included into linux-next and is updated > there every 3-4 working days > > ------------------------------------------------------ > From: Sergey Senozhatsky <[email protected]> > Subject: zram: add dynamic device add/remove functionality > > 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). IOW 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. > > [[email protected]: use zram->claim to avoid lockdep splat] > Signed-off-by: Sergey Senozhatsky <[email protected]> > Cc: Minchan Kim <[email protected]> > Cc: Nitin Gupta <[email protected]> > Signed-off-by: Andrew Morton <[email protected]> > --- > > Documentation/ABI/testing/sysfs-class-zram | 24 ++++ > Documentation/blockdev/zram.txt | 23 +++- > drivers/block/zram/zram_drv.c | 100 ++++++++++++++++++- > 3 files changed, 141 insertions(+), 6 deletions(-) > > diff -puN /dev/null Documentation/ABI/testing/sysfs-class-zram > --- /dev/null > +++ a/Documentation/ABI/testing/sysfs-class-zram > @@ -0,0 +1,24 @@ > +What: /sys/class/zram-control/ > +Date: August 2015 > +KernelVersion: 4.2 > +Contact: Sergey Senozhatsky <[email protected]> > +Description: > + The zram-control/ class sub-directory belongs to zram > + device class > + > +What: /sys/class/zram-control/zram_add > +Date: August 2015 > +KernelVersion: 4.2 > +Contact: Sergey Senozhatsky <[email protected]> > +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.2 > +Contact: Sergey Senozhatsky <[email protected]> > +Description: > + Remove a specific /dev/zramX device, where X is a device_id > + provided by user > diff -puN > Documentation/blockdev/zram.txt~zram-add-dynamic-device-add-remove-functionality > Documentation/blockdev/zram.txt > --- > a/Documentation/blockdev/zram.txt~zram-add-dynamic-device-add-remove-functionality > +++ a/Documentation/blockdev/zram.txt > @@ -99,7 +99,24 @@ size of the disk when not in use so a hu > 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 > + 1 > + > +To remove the existing /dev/zramX device (where X is a device id) > +execute > + echo X > /sys/class/zram-control/zram_remove > + > +8) Stats: > Per-device statistics are exported as various nodes under > /sys/block/zram<id>/ > > A brief description of exported device attritbutes. For more details please > @@ -174,11 +191,11 @@ line of text and contains the following > zero_pages > num_migrated > > -8) Deactivate: > +9) Deactivate: > swapoff /dev/zram0 > umount /dev/zram1 > > -9) Reset: > +10) Reset: > Write any positive value to 'reset' sysfs node > echo 1 > /sys/block/zram0/reset > echo 1 > /sys/block/zram1/reset > diff -puN > drivers/block/zram/zram_drv.c~zram-add-dynamic-device-add-remove-functionality > drivers/block/zram/zram_drv.c > --- > a/drivers/block/zram/zram_drv.c~zram-add-dynamic-device-add-remove-functionality > +++ a/drivers/block/zram/zram_drv.c > @@ -29,10 +29,14 @@ > #include <linux/vmalloc.h> > #include <linux/err.h> > #include <linux/idr.h> > +#include <linux/sysfs.h> > > #include "zram_drv.h" > > static DEFINE_IDR(zram_index_idr); > +/* idr index must be protected */ > +static DEFINE_MUTEX(zram_index_mutex); > + > static int zram_major; > static const char *default_compressor = "lzo"; > > @@ -1271,24 +1275,104 @@ out_free_dev: > return ret; > } > > -static void zram_remove(struct zram *zram) > +static int zram_remove(struct zram *zram) > { > - pr_info("Removed device: %s\n", zram->disk->disk_name); > + struct block_device *bdev; > + > + bdev = bdget_disk(zram->disk, 0); > + if (!bdev) > + return -ENOMEM; > + > + mutex_lock(&bdev->bd_mutex); > + if (bdev->bd_openers || zram->claim) { > + mutex_unlock(&bdev->bd_mutex); > + bdput(bdev); > + return -EBUSY; > + } > + > + zram->claim = true; > + mutex_unlock(&bdev->bd_mutex); > + > /* > * Remove sysfs first, so no one will perform a disksize > - * store while we destroy the devices > + * store while we destroy the devices. This also helps during > + * zram_remove() -- zram_reset_device() is the last holder of > + * ->init_lock, no later/concurrent disksize_store() or any > + * other sysfs handlers are possible. > */ > sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, > &zram_disk_attr_group); > > + /* Make sure all the pending I/O are finished */ > + fsync_bdev(bdev); > zram_reset_device(zram); > + bdput(bdev); > + > + pr_info("Removed device: %s\n", zram->disk->disk_name); > + > idr_remove(&zram_index_idr, zram->disk->first_minor); > blk_cleanup_queue(zram->disk->queue); > del_gendisk(zram->disk); > put_disk(zram->disk); > kfree(zram); > + return 0; > +} > + > +/* zram module control sysfs attributes */ > +static ssize_t zram_add_show(struct class *class, > + struct class_attribute *attr, > + char *buf) > +{ > + int ret; > + > + mutex_lock(&zram_index_mutex); > + ret = zram_add(); > + 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, > + size_t count) > +{ > + struct zram *zram; > + int ret, dev_id; > + > + /* dev_id is gendisk->first_minor, which is `int' */ > + ret = kstrtoint(buf, 10, &dev_id); > + if (ret) > + return ret; > + if (dev_id < 0) > + return -EINVAL; > + > + mutex_lock(&zram_index_mutex); > + > + zram = idr_find(&zram_index_idr, dev_id); > + if (zram) > + ret = zram_remove(zram); > + else > + ret = -ENODEV; > + > + mutex_unlock(&zram_index_mutex); > + return ret ? ret : count; > } > > +static struct class_attribute zram_control_class_attrs[] = { > + __ATTR_RO(zram_add), > + __ATTR_WO(zram_remove), > + __ATTR_NULL, > +}; > + > +static struct class zram_control_class = { > + .name = "zram-control", > + .owner = THIS_MODULE, > + .class_attrs = zram_control_class_attrs, > +}; > + > static int zram_remove_cb(int id, void *ptr, void *data) > { > zram_remove(ptr); > @@ -1297,6 +1381,7 @@ static int zram_remove_cb(int id, void * > > static void destroy_devices(void) > { > + class_unregister(&zram_control_class); > idr_for_each(&zram_index_idr, &zram_remove_cb, NULL); > idr_destroy(&zram_index_idr); > unregister_blkdev(zram_major, "zram"); > @@ -1306,14 +1391,23 @@ static int __init zram_init(void) > { > int ret; > > + ret = class_register(&zram_control_class); > + if (ret) { > + pr_warn("Unable to register zram-control class\n"); > + return ret; > + } > + > zram_major = register_blkdev(0, "zram"); > if (zram_major <= 0) { > pr_warn("Unable to get major number\n"); > + class_unregister(&zram_control_class); > return -EBUSY; > } > > while (num_devices != 0) { > + mutex_lock(&zram_index_mutex); > ret = zram_add(); > + mutex_unlock(&zram_index_mutex); > if (ret < 0) > goto out_error; > num_devices--; > _ > > Patches currently in -mm which might be from [email protected] are > > revert-zram-move-compact_store-to-sysfs-functions-area.patch > zram-add-compact-sysfs-entry-to-documentation.patch > zram-cosmetic-zram_attr_ro-code-formatting-tweak.patch > zram-use-idr-instead-of-zram_devices-array.patch > zram-reorganize-code-layout.patch > zram-remove-max_num_devices-limitation.patch > zram-report-every-added-and-removed-device.patch > zram-trivial-correct-flag-operations-comment.patch > zram-return-zram-device_id-from-zram_add.patch > zram-close-race-by-open-overriding.patch > zram-add-dynamic-device-add-remove-functionality.patch > -- Kind regards, Minchan Kim
dynamic_remove.sh
Description: Bourne shell script

