NMVe SSD Fedora 吞吐量測試過高

NMVe SSD Fedora 吞吐量測試過高

我正在測試使用 NVMe 協定的三星 950 Pro SSD 卡的吞吐量。我目前的測試方法是在分割區上掛載檔案系統,並將大小為X位元組的檔案寫入檔案系統。透過記錄執行此操作所需的時間,可以計算位元組/秒。

在我的測試中,我有一個 while 循環,它將以可變區塊大小寫入 X 位元組,一次一個區塊,由更高層級的 for 循環指定。除此之外,我還有另一個循環,它將並行運行 N 個應用程序,每個應用程式寫入 SSD 的不同分區。

目前,我看到的讀取和寫入速度略快於三星 950 Pro 資料表指定的理論最大傳輸速度。三星指定 950 Pro 的最大順序寫入速度為 1.5 GB/s,最大順序讀取速度為 2.5 GB/s。

https://www.samsung.com/us/computing/memory-storage/solid-state-drives/ssd-950-pro-nvme-512gb-mz-v5p512bw/#specs

以下是 bash 腳本的主要功能,它循環運行的應用程式數量和區塊大小:

appInstances=1
while [ $appInstances -le 4 ]
do
    for blocksize in 4096 32768 131072 524288 1048576 67108864 268435456 1073741824
    do
       # Run the test
       datetime
       echo "[$datetime_v]: Test blocksize: $blocksize appInstances: $appInstances"
       run_single_perf_test $blocksize

    done

    appInstances=`expr $appInstances \* 2`

done
exit 0

這是 run_perf_test 的寫入部分。這部分之後還有一個讀取部分,其中包括寫入吞吐速度測試。在測試之間,我卸載了 SSD 的所有分區並重新安裝它們,以允許所有 NVMe 事務完成並防止寫入作業的任何快取影響讀取操作的吞吐量測量。

instCnt=1
childpids=""
while [ $instCnt -le $appInstances ]
do
fsrw -w $blocksize /fsmnt/fs${instCnt}/usernumber1/j.j &

# Save the process ID
childpids="$childpids $!"

# Increment the instace count.
instCnt=`expr $instCnt + 1`
done

fsrw 是一個 C++ 應用程序,它基於第一個參數“-r”或“-w”、第二個參數(塊大小)和第三個參數(SSD 分區上的文件名)構建一個字串並嘗試開啟SSD 分割區上的檔案並將字串寫入其中。這是 write 函數的實現,當提供“-w”作為第一個參數時調用該函數。

/*! \fn perform_writeop()
 *  \brief The function returns true when the write operation completes successfully. 
 *
 *  The function will run until the read is complete or a 35 second timeout is reached.
 *  It will record the time before the write begins, then also record the time afterward.
 *  If the timeout is reached this should be about 35 seconds
 */
bool perform_writeop ()
{
    // File descriptor.
    int32_t fd = -1;

    // Function status.
    bool status = false;

    // Zero writes
    int zero_writes = 0;

    // Buffer fill index.
    int32_t bfidx = 0;

    // Character value.
    int8_t cv = 33;

    // Fill the buffer with printable characters.
    for (; bfidx < blocksize; bfidx++, cv++)
    {
        // Verify the character value is in range.
        if (cv >= 127)
        {
            cv = 33;
        }
        else
        {
            // Add to the buffer.
            buf[bfidx] = cv;
        }
    }

    // Open the file.
    fd = open (fname.c_str (), O_WRONLY | O_CREAT, 0660);

    // Verify the file has been opened.
    if (fd == -1)
    {
        cout << get_datetime_string() << "Write open of " << fname 
        << " failed.  Errno: " << errno << endl;
    }
    else
    {
        // Total bytes written.
        uint64_t written = 0;

        // Notify the start of the test.
        cout << get_datetime_string() << "Write test started" << endl;

        // Elapsed time.
        struct timeval tv = { 0 };
        get_elapsed_time (&tv);
        struct timeval write_tv = tv;

        // Run until it is time for the test to stop.
        while (written < READ_LIMIT && zero_writes < 10)
        {
            ssize_t writesize = write (fd, &buf[0], blocksize);
            if (writesize == -1)
            {
                cout << get_datetime_string << "Write failure.  Errno: " << errno << endl;
                zero_writes = 10;
            }
            else if (0 == writesize)
            {
                cout << get_datetime_string() << "Zero bytes written" << endl;
                zero_writes++;
            }
            else
            {
                written += writesize;
            }
        }

    string flush_command = "nvme flush /dev/nvme0n1p";
    flush_command += fname[9];
    system(flush_command.c_str());


    // Get the elapsed time.
    get_elapsed_time (&write_tv);

    // Report the number of bytes written.
    cout << get_datetime_string() << "Write " << written << " bytes in "
     << write_tv.tv_sec << "." << write_tv.tv_usec
     << " seconds" << endl;

    // Close the file.
    close (fd);

    // Get the elapsed time.
    get_elapsed_time (&tv);

    // Report the number of bytes read.
    cout << get_datetime_string() << "Write closed.  " << written 
    << " Bytes written in " << tv.tv_sec << "." << tv.tv_usec 
    << " seconds" << endl;

    // Report the number of bytes per second.
    cout << get_datetime_string() << "Bytes per second " 
    << bytes_per_second (&tv, written) << endl;

    // Report the cache flush time.
    struct timeval flush_tv = { 0 };
    timersub (&tv, &write_tv, &flush_tv);
    cout << get_datetime_string() << "System cache flush completed in " 
    << flush_tv.tv_sec << "." << flush_tv.tv_usec << "seconds" << endl;

    // Set the function return status when all write operations have
    // been successful.
    if (zero_writes < 10)
    {
      status = true;
    }
  }
  return status;
}

我得到的數據看起來像這樣 在此輸入影像描述

這些數字接近三星 950 Pro 的最大理論吞吐量,但有些數字太高,這讓我很困擾。為什麼我得到的數字可能高於 Samsung 950 Pro 的理論最大吞吐量?

相關內容