Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to avoid IO hang implementation for Linux

Shulou Source: shulou.com Published: 2022-06-01 13:19:49 10月03日 Update

This article is about how Linux can avoid IO hang implementation. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

For DB Server, dropping large tables can be tricky. If you delete a large table, you can create a hard link to the original table's.ibd file. When multiple file names point to the same Node, deleting any file name is fast, because the directly connected physical file is not deleted, just a pointer is deleted. When the Node reference number is 1, deleting the file requires deleting all the data blocks associated with the file.

If we use the above method to create a hard link file, then delete the large file, how to avoid IO hang?

The answer is the truncate tool in the coreutils toolset

truncate shrinks or extends a file to a specified size

Syntax: truncate option... file ...

If the file doesn't exist, it's created.

If the size of a file is larger than the specified size, the file will be truncated to lose some data, if the size is smaller than the specified size, then it will be filled with 0 bytes.

option:

-c

--no-create If there is no file, it will not be created.

-o

--io-blocks Size of files treated as I/O blocks

-r rfile

--reference=file Base the size of each file on the size of rfile

-s size

--size=size Adjust file size according to options below

KB=> 1000 (KiloBytes)

K=> 1024 (KibiBytes)

MB => 1000*1000 (MegaBytes)

M => 1024*1024 (MebiBytes)

GB => 1000*1000*1000 (GigaBytes)

G => 1024*1024*1024 (GibiBytes)

or T, P, E, Z, something like that.

According to the symbols below, resize them according to their own size

+ extended

- narrow

< 至多 >

least

/Multiple of rounding down

Multiples of % Up

A simple example:

touch abc

truncate -s +1KB abc

truncate -s +1KB abc

ll abc

-rwxrwxrwx 1 root root 2000 November 28 05:31 abc

Thank you for reading! About "Linux how to avoid IO hang implementation" This article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: File size multiples content tools data time more articles links facets adjustments good practical tricky units just name multiple bytes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS Shulou Information vpn Docker