Configure tcm_loop device parameters

更新时间:
复制 MD 格式

When you use the Target Core Module in Userspace (TCMU) framework to implement userspace Internet Small Computer Systems Interface (iSCSI) targets, the default tcm_loop module parameters may not deliver optimal I/O performance for your workload. This document explains how to view and configure tcm_loop device parameters in Alibaba Cloud Linux 3 to tune I/O throughput in collaboration with the userspace backend.

Prerequisites

Before you begin, make sure that you have:

  • Alibaba Cloud Linux 3 as the operating system

  • Kernel version 5.10.134-17 or later

tcm_loop device parameters

The tcm_loop module exposes four parameters that control I/O queue depth and scatter-gather behavior. Parameter configurations apply to all tcm_loop devices.

ParameterDescriptionDefault value
nr_hw_queuesNumber of hardware queues of a tcm_loop device1
can_queueQueue depth of each hardware queue1024
cmd_per_lunMaximum number of commands a Small Computer System Interface (SCSI) device can run per logical unit number (LUN)1024
sg_tablesizeMaximum size of the scatter-gather table for a tcm_loop device256

View tcm_loop device parameters

  1. Load the tcm_loop module.

    sudo modprobe tcm_loop
  2. Read the current parameter values from sysfs.

    cat /sys/module/tcm_loop/parameters/nr_hw_queues
    cat /sys/module/tcm_loop/parameters/can_queue
    cat /sys/module/tcm_loop/parameters/cmd_per_lun
    cat /sys/module/tcm_loop/parameters/sg_tablesize

Configure tcm_loop device parameters

There are two ways to configure tcm_loop device parameters:

  • Method 1: Pass parameters when loading the module

  • Method 2: Use a configuration file

Method 1: Pass parameters when loading the module

  1. If the tcm_loop module is already loaded, remove it first.

    sudo modprobe -r tcm_loop
  2. Load the module with the parameter values you want.

    Replace the placeholders with the values you want to set.

    sudo modprobe tcm_loop nr_hw_queues=<nr_hw_queues> can_queue=<can_queue> cmd_per_lun=<cmd_per_lun> sg_tablesize=<sg_tablesize>

    Example — set nr_hw_queues to 4, can_queue to 2048, cmd_per_lun to 2048, and sg_tablesize to 512:

    sudo modprobe tcm_loop nr_hw_queues=4 can_queue=2048 cmd_per_lun=2048 sg_tablesize=512

Verify

Confirm that the parameter values have taken effect.

cat /sys/module/tcm_loop/parameters/nr_hw_queues
cat /sys/module/tcm_loop/parameters/can_queue
cat /sys/module/tcm_loop/parameters/cmd_per_lun
cat /sys/module/tcm_loop/parameters/sg_tablesize

Method 2: Use a configuration file

  1. If the tcm_loop module is already loaded, remove it first.

    sudo modprobe -r tcm_loop
  2. Create a configuration file in /etc/modprobe.d/.

    Replace the placeholders with the values you want to set. The file must have a .conf extension.

    sudo bash -c "cat > /etc/modprobe.d/<tcm_loop.conf> << EOF
    options tcm_loop nr_hw_queues=<nr_hw_queues> can_queue=<can_queue> cmd_per_lun=<cmd_per_lun> sg_tablesize=<sg_tablesize>
    EOF"

    Example — create /etc/modprobe.d/tcm_loop.conf with nr_hw_queues=4, can_queue=2048, cmd_per_lun=2048, and sg_tablesize=512:

    sudo bash -c "cat > /etc/modprobe.d/tcm_loop.conf << EOF
    options tcm_loop nr_hw_queues=4 can_queue=2048 cmd_per_lun=2048 sg_tablesize=512
    EOF"
  3. Load the tcm_loop module.

    sudo modprobe tcm_loop

Verify

Confirm that the parameter values have taken effect.

cat /sys/module/tcm_loop/parameters/nr_hw_queues
cat /sys/module/tcm_loop/parameters/can_queue
cat /sys/module/tcm_loop/parameters/cmd_per_lun
cat /sys/module/tcm_loop/parameters/sg_tablesize