Commit d134b00b9acca3fb054d7c88a5f5d562ecbb42d1
Committed by
Jens Axboe
1 parent
770fe30a46
Exists in
master
and in
20 other branches
loop: add BLK_DEV_LOOP_MIN_COUNT=%i to allow distros 0 pre-allocated loop devices
Instead of unconditionally creating a fixed number of dead loop devices which need to be investigated by storage handling services, even when they are never used, we allow distros start with 0 loop devices and have losetup(8) and similar switch to the dynamic /dev/loop-control interface instead of searching /dev/loop%i for free devices. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Showing 3 changed files with 31 additions and 20 deletions Side-by-side Diff
Documentation/kernel-parameters.txt
... | ... | @@ -1340,9 +1340,12 @@ |
1340 | 1340 | it is equivalent to "nosmp", which also disables |
1341 | 1341 | the IO APIC. |
1342 | 1342 | |
1343 | - max_loop= [LOOP] Maximum number of loopback devices that can | |
1344 | - be mounted | |
1345 | - Format: <1-256> | |
1343 | + max_loop= [LOOP] The number of loop block devices that get | |
1344 | + (loop.max_loop) unconditionally pre-created at init time. The default | |
1345 | + number is configured by BLK_DEV_LOOP_MIN_COUNT. Instead | |
1346 | + of statically allocating a predefined number, loop | |
1347 | + devices can be requested on-demand with the | |
1348 | + /dev/loop-control interface. | |
1346 | 1349 | |
1347 | 1350 | mcatest= [IA-64] |
1348 | 1351 |
drivers/block/Kconfig
... | ... | @@ -256,6 +256,21 @@ |
256 | 256 | |
257 | 257 | Most users will answer N here. |
258 | 258 | |
259 | +config BLK_DEV_LOOP_MIN_COUNT | |
260 | + int "Number of loop devices to pre-create at init time" | |
261 | + depends on BLK_DEV_LOOP | |
262 | + default 8 | |
263 | + help | |
264 | + Static number of loop devices to be unconditionally pre-created | |
265 | + at init time. | |
266 | + | |
267 | + This default value can be overwritten on the kernel command | |
268 | + line or with module-parameter loop.max_loop. | |
269 | + | |
270 | + The historic default is 8. If a late 2011 version of losetup(8) | |
271 | + is used, it can be set to 0, since needed loop devices can be | |
272 | + dynamically allocated with the /dev/loop-control interface. | |
273 | + | |
259 | 274 | config BLK_DEV_CRYPTOLOOP |
260 | 275 | tristate "Cryptoloop Support" |
261 | 276 | select CRYPTO |
drivers/block/loop.c
... | ... | @@ -1793,21 +1793,6 @@ |
1793 | 1793 | struct loop_device *lo; |
1794 | 1794 | int err; |
1795 | 1795 | |
1796 | - /* | |
1797 | - * loop module now has a feature to instantiate underlying device | |
1798 | - * structure on-demand, provided that there is an access dev node. | |
1799 | - * However, this will not work well with user space tool that doesn't | |
1800 | - * know about such "feature". In order to not break any existing | |
1801 | - * tool, we do the following: | |
1802 | - * | |
1803 | - * (1) if max_loop is specified, create that many upfront, and this | |
1804 | - * also becomes a hard limit. | |
1805 | - * (2) if max_loop is not specified, create 8 loop device on module | |
1806 | - * load, user can further extend loop device by create dev node | |
1807 | - * themselves and have kernel automatically instantiate actual | |
1808 | - * device on-demand. | |
1809 | - */ | |
1810 | - | |
1811 | 1796 | err = misc_register(&loop_misc); |
1812 | 1797 | if (err < 0) |
1813 | 1798 | return err; |
1814 | 1799 | |
... | ... | @@ -1833,11 +1818,19 @@ |
1833 | 1818 | if (max_loop > 1UL << (MINORBITS - part_shift)) |
1834 | 1819 | return -EINVAL; |
1835 | 1820 | |
1821 | + /* | |
1822 | + * If max_loop is specified, create that many devices upfront. | |
1823 | + * This also becomes a hard limit. If max_loop is not specified, | |
1824 | + * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module | |
1825 | + * init time. Loop devices can be requested on-demand with the | |
1826 | + * /dev/loop-control interface, or be instantiated by accessing | |
1827 | + * a 'dead' device node. | |
1828 | + */ | |
1836 | 1829 | if (max_loop) { |
1837 | 1830 | nr = max_loop; |
1838 | 1831 | range = max_loop << part_shift; |
1839 | 1832 | } else { |
1840 | - nr = 8; | |
1833 | + nr = CONFIG_BLK_DEV_LOOP_MIN_COUNT; | |
1841 | 1834 | range = 1UL << MINORBITS; |
1842 | 1835 | } |
1843 | 1836 | |
... | ... | @@ -1847,7 +1840,7 @@ |
1847 | 1840 | blk_register_region(MKDEV(LOOP_MAJOR, 0), range, |
1848 | 1841 | THIS_MODULE, loop_probe, NULL, NULL); |
1849 | 1842 | |
1850 | - /* pre-create number devices of devices given by config or max_loop */ | |
1843 | + /* pre-create number of devices given by config or max_loop */ | |
1851 | 1844 | mutex_lock(&loop_index_mutex); |
1852 | 1845 | for (i = 0; i < nr; i++) |
1853 | 1846 | loop_add(&lo, i); |