![Linux 커널의 최대 루프 장치는 무엇입니까?](https://rvso.com/image/164715/Linux%20%EC%BB%A4%EB%84%90%EC%9D%98%20%EC%B5%9C%EB%8C%80%20%EB%A3%A8%ED%94%84%20%EC%9E%A5%EC%B9%98%EB%8A%94%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
루프 파일을 지원하기 위한 루프 모듈을 포함할 수 있습니다. 루프 모듈은 max_loop 옵션을 지원합니다. 옵션이 loop max_loop 256 인 예제를 찾았습니다. 내 질문은 최대 지원되는 루프 장치가 무엇입니까? 믿겨지지 않습니다. 256개는 하드 제한이고 256개 이상의 루프 장치를 만드는 것은 불가능합니다.
업데이트:
파일에서 흥미로운 내용을 찾지 못했습니다.https://elixir.bootlin.com/linux/v4.0/source/drivers/block/loop.c
하지만 몇 가지 실험을 하고 modprobe max_loops=512를 실행하면 udev로 마운트된 /dev/ 디렉토리에 loop0에서 loop511까지 번호가 매겨진 정확히 동일한 개수의 루프 블록 파일이 표시됩니다.
저는 리눅스 커널 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64로 했습니다.
답변1
커널 3.1 이전에는 고정된 수의 루프 장치를 설정해야 했습니다. 3.1부터 /dev/loop-control
루프 장치는 고정된 숫자가 아닌 필요에 따라 동적으로 할당됩니다. 따라서 만약을 대비해 전혀 필요하지 않은 100개의 루프 장치를 갖는 대신 0개의 장치(또는 선택적 최소 개수)로 시작하여 실제로 필요할 때만 생성합니다.
에서man 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.
매우 훌륭한 소스 코드(drivers/block/loop.c
)는 다음과 같이 설명합니다.
/*
* 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.
*/
* 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.
그렇다면 현실적으로 얼마나 많은 루프 장치를 사용할 수 있습니까? 제한은 단일 주요 장치에 대한 최대 부 장치 수입니다( loop
단일 주요 장치가 있으므로 블록 7).MINORBITS
(따라서 2 20 , 백만이 조금 넘습니다).
나는 다음과 같이 큰 숫자를 강제로 시도했습니다.
truncate -s 1M foobar
i=1
while losetup --show /dev/loop$(($i-1)) foobar
do
i=$(($i*2))
done
...하지만 결국 커널 패닉이 발생했습니다. ;-)
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.
이는 2 20 제한과 일치합니다.