Hard Disk Information

Source: Internet
Author: User
Tags types of tables

The smallest physical unit of a disk is a sector. The sector is the smallest block formed by a cylindrical disk and wire cutting from the center of the circle. The size is 512 bytes. In this way, there will be no more than one hard disk partition deleted, if the data volume is too large, the operating system cannot address it by sector (too many). Because the space length of Data Pointer storage is limited, the length of so many sectors cannot be saved, therefore, the operating system will combine several adjacent sectors to form a so-called "cluster". As a result, there will be several "clusters ", the number of "clusters" is equal to the total number of sectors divided by the sectors occupied by each "cluster. For Windows file systems, a "cluster" usually occupies 2, 4, 8, 16, 32 or 64 sectors, and the operating system is addressing based on the "cluster. For example, if my computer's file system is NTFS and the size of the "cluster" is 4 K, each "cluster" occupies eight sectors. Sometimes we call a "cluster" as a data block. If a file is smaller than 4 K, it will occupy a "cluster". If it is larger than 4 K, it will occupy several data blocks. That's why a TXT file is created on the computer, and only two words are saved in it, which also occupies 4 K.

The operating system reads one or more data blocks each time. Each block can only store one document data, as does Linux.

The block of the operating system is the block of the operating system, and the block of the Oracle is the block of the Oracle. The two cannot be confused, but they are associated.

For databases and Oracle, I am not familiar with Oracle, but I am not familiar with SQL Server and MySQL, so it is only for Oracle. However, the general principle of other databases should be similar to that of other databases. We usually say that the Oracle data block occupies n times the data block of the operating system, n is an even number (except 1), and the Oracle data block size can be 4 K, 8 K, 16 K, 32 K, 64 K, that is, the value of db_block_size, you can use the select value from V $ parameter where name = 'db _ block_size 'statement to query the data (which can be viewed only with DBA permission). On my machine, it is 8 KB, it is also the default block size of Oracle. Since it is 8 K, it is twice the size of the Operating System "cluster". What is the purpose of this operation? From the perspective of data query, Oracle reads at least one piece of data each time, and reads only one piece of data if it is not full. The read operations of this operating system are the same. We all know that the query is divided into two parts. One is to scan the whole table and read all the data in the whole table. In this way, to reduce the number of I/O operations, the larger the block, the better, the other is index query, because index query Io times are very small, we hope that the size of each read block is the same as the size of the operating system block (excluding massive data, A large amount of data requires Table Partitioning, and the block size cannot be too small or too small to index too many B-tree layers). This is very contradictory. in different situations, we sometimes want to be larger and sometimes smaller, therefore, the 8 K compromise is more appropriate.

A database block is also called a Database "page ". For example, for MySQL, the so-called Table lock, row lock, and page lock, the page of this page lock is the database block. Oracle does not have the concept of page lock. There are only table locks and row locks. Oracle's row locks are not the same as MySQL, and Oracle's row lock overhead is actually quite small. Unlike MySQL, which has a large row lock overhead, great competition, and many deadlocks. This also shows why Oracle technology is powerful.

The above situation is for general cases, but for tables of different purposes, we need to create tables of different block sizes. In general, crud tables are frequently changed and often queried through indexes. Therefore, we need a smaller block. For warehouse tables, they are used for data analysis, the statistical warehouse table (usually full table scan) is used as the log table (usually write data into the table without querying ), this type of table requires a relatively large block. After all, the larger the block size, the less I/O frequency. This is also an aspect of database optimization. The two types of tables are called OLAP and OLTP.

The blocks of the operating system and the Oracle database are explained respectively above. Next we will continue to talk about the blocks of the operating system. The block of the operating system is divided into two types based on the data stored at the beginning. One is the index block and the other is the data block. This is for the NTFS and Linux ext2 file systems. He stores file attributes and permissions (such as rwx permissions, owner, group, and time parameters in Linux) and data in the index block and data block respectively, the name is inode block and data block. inode stores the data block address. The inode can be found to address the data block, which is fast. If the data block is not continuous, it can also read out the discontinuous block content at a time, this is why the file system NTFs and ext2 are similar to the previous ones after fragmentation. Fat is not the same, so fat needs to fragment, because it does not read data through indexes, similar to the linked list structure. In fact, the two types of file systems in the operating system are not comprehensive enough. There is a super block at the beginning of the partition to store the information of the entire partition, such as the usage, remaining amount, and number of sectors. These three types are called inode, block, and super respectively. In addition, inode and block size are different. in Linux, inode is 128 bytes, while block can be divided into 1 K, 2 K, 4 K, and super is 1024 bytes, of course, depending on the situation, the score is too small, there will be read performance problems for large files inode, the score is too large, resulting in a waste of space for many small files. Inode uses a multi-level processing method to record the block numbers occupied by files. This super is not the MBR region starting with the disk. The MBR region stores the information of the entire disk. Super only stores the information of the current partition. The MBR (Master Boot Record) Master Boot Record is generally 512 bytes, and this region can be divided into two parts. The first part is pre-boot (pre-boot zone), accounting for 446 bytes; the second part is the Partition Table partition (Partition Table), accounting for 66 bytes, which is equivalent to a small program, the function is to determine which partition is marked as an active partition, read the startup partition of that partition, and run the code in this partition. It does not belong to any operating system, nor can it be read by disk operation commands provided by the operating system. But we can use the int13h 2 function provided in the ROM-BIOS to read the content of this sector, it can also be read by the software tool norton8.0 diskedit. EXE. When the file size is too large, the storage on the disk is quite scattered. Although the indexing technology can be read at one time, the distribution on the hard disk is too scattered, the mechanical arm moves greatly, which also affects reading performance.

Each document or directory occupies an inode to record all block addresses occupied by a file or directory. As mentioned above, inode stores the data block numbers hierarchically (the addresses are inaccurate.

In addition, database indexes, we call the index to find the root of the index structure and find the data layer by layer. How can we find the root, in fact, the index block of the file system is used to locate the heel block, and then the heel block is located layer by layer. You do not need to use indexes to find the next node block. Because it is not necessary, the address of the lower node is directly stored in the block.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.