i can include loop module for supporting loop files. loop module supports max_loop option. I've found examples with options loop max_loop 256 . My question, what is maximal supported loop devices? I can't belive, 256 is the hard limit, and creating more than 256 loop devices is impossible.


I didn't found nothing interesting in file https://elixir.bootlin.com/linux/v4.0/source/drivers/block/loop.c

But I made some experiment, and run modprobe max_loops=512 then I see exactly the same count loop block files in /dev/ directory mounted as udev, numbered from loop0 to loop511

I did it with linux kernel 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64


Before kernel 3.1, you had to set a fixed number of loop devices. Since 3.1 there is /dev/loop-control, and loop devices are allocated dynamically as needed, rather than a fixed number. So rather than having a hundred loop devices you never needed (just in case), it starts out with 0 devices (or an optional min count) and only creates them when actually required.

From man 4 loop:

    Since Linux 3.1, the kernel provides the /dev/loop-control device,
    which permits an application to dynamically find a free device, and to
    add and remove loop devices from the system.

The very fine source code (drivers/block/loop.c) describes it:

     * If max_loop is specified, create that many devices upfront.
     * This also becomes a hard limit. If max_loop is not specified,
     * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
     * init time. Loop devices can be requested on-demand with the
     * /dev/loop-control interface, or be instantiated by accessing
     * a 'dead' device node.

It also recommends not setting it at all:

     * Note: Global-for-all-devices, set-only-at-init, read-only module
     * parameteters like 'max_loop' and 'max_part' make things needlessly
     * complicated, are too static, inflexible and may surprise
     * userspace tools. Parameters like this in general should be avoided.

How many loop devices can realistically be used then? The limit is the maximum number of minor devices for a single major device (since loop has a single major, block 7), which is limited by MINORBITS (so 220, just over a million).

I tried to force some large numbers like this:

truncate -s 1M foobar
while losetup --show /dev/loop$(($i-1)) foobar

...but it triggered a kernel panic in the end. ;-)

sysfs: cannot create duplicate filename '/devices/virtual/bdi/7:1048575'
kobject_add_internal failed for 7:1048575 with -EEXIST, don't try to register things with the same name in the same directory.

This matches the 220 limit.

  • 2
    Thank You, it's the best answer whenever I've seen :) I look into minor/major numbers. far far before, both were single bytes, then major and minor were limited from 0 to 255. Actually there assigned probably 4 bytes (C dword under C x86 compiler), then limitations are increased. But question is, this value is used with or without sign :) But it is very goot news, next limitation has been broken. ps: for /etc/loop511 I have major=7, minor=511 as a special block file :)
    – Znik
    Nov 28 '19 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.