was ist die maximale Anzahl an Loop-Geräten für den Linux-Kernel?

was ist die maximale Anzahl an Loop-Geräten für den Linux-Kernel?

ich kann ein Loop-Modul zur Unterstützung von Loop-Dateien einbinden. Das Loop-Modul unterstützt die Option max_loop. Ich habe Beispiele mit den Optionen loop max_loop 256 gefunden. Meine Frage: Was sind die maximal unterstützten Loop-Geräte? Ich kann es nicht glauben, 256 ist die harte Grenze und es ist unmöglich, mehr als 256 Loop-Geräte zu erstellen.

Aktualisieren:

Ich habe nichts Interessantes in der Datei gefundenhttps://elixir.bootlin.com/linux/v4.0/source/drivers/block/loop.c

Aber ich habe ein paar Experimente gemacht und modprobe max_loops=512 ausgeführt. Dann sehe ich genau die gleiche Anzahl von Loop-Block-Dateien im Verzeichnis /dev/, das als udev gemountet ist, nummeriert von loop0 bis loop511.

Ich habe es mit Linux-Kernel 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 gemacht

Antwort1

Vor Kernel 3.1 mussten Sie eine feste Anzahl von Loop-Geräten festlegen. Seit 3.1 gibt es /dev/loop-control, und Loop-Geräte werden dynamisch nach Bedarf zugewiesen, statt einer festen Anzahl. Anstatt also hundert Loop-Geräte zu haben, die Sie nie brauchten (nur für den Fall), beginnt es mit 0 Geräten (oder einer optionalen Mindestanzahl) und erstellt sie nur, wenn sie tatsächlich benötigt werden.

Ausman 4 loop:

/dev/loop-control
    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.

Der sehr schöne Quellcode (drivers/block/loop.c) beschreibt es:

    /*
     * 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.
     */

Es auchempfiehlt, es überhaupt nicht einzustellen:

     * 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.

Wie viele Loop-Geräte können dann realistischerweise verwendet werden? Die Grenze ist die maximale Anzahl von Nebengeräten für ein einziges Hauptgerät (da loopes ein einziges Hauptgerät gibt, Block 7), die begrenzt ist durchMINORBITS(also 2 20 , etwas mehr als eine Million).

Ich habe versucht, einige große Zahlen wie folgt zu erzwingen:

truncate -s 1M foobar
i=1
while losetup --show /dev/loop$(($i-1)) foobar
do
    i=$(($i*2))
done

...aber am Ende hat es einen Kernel Panic ausgelöst. ;-)

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.

Dies entspricht der Grenze von 2:20 .

verwandte Informationen