A synchronous IO can be identified by the current process id (pid) because the process will be blocked when a synchronous IO occurs.
**Weakness:** 如果一个进程发起了一个同步 IO 操作,然后该进程退出,并且其进程 ID 被一个新的进程复用,那么可能会出现两个不同的 IO 操作具有相同的 "标识符"。(理论上存在,但在实际情况中几乎不可能出现])
In Linux 5.15.1, there are three important branches in vfs_read() as follows:
```c
if(file->f_op->read)
ret=file->f_op->read(file,buf,count,pos);
elseif(file->f_op->read_iter)
ret=new_sync_read(file,buf,count,pos);
else
ret=-EINVAL;
```
For example, if the file operating locates in ext4 file system, it will choose the second branch if all goes on well. Because the `file->f_op->read` has no definition in `ext4_file_operations` .
We first choose ext4 file system to analyze:
The functions called by a synchronous IO are as follows (for ext4 fs):
```
------------------------------------------ File System Layer ------------------------------------------------------
|-- vfs_read
|--- file->op->read (×)
|--- new_sync_read
|-- call_read_iter
|-- file->op->read_iter (ext4_file_read_iter)
|-- ext4_dax_read_iter (DAX)
|-- ext4_dio_read_iter (Direct IO)
|--
|-- generic_file_read_iter
|-- Direct IO (to avoid: some fs have no its own direct io process function)
|-- filemap_read (read data from page cache)
|-- filemap_get_pages
|-- filemap_get_read_batch
|-- page_cache_get_speculative
|-- __page_cache_add_speculative
|-- page_cache_sync_readahead
|-- page_cache_sync_ra
|-- force_page_cache_ra
|-- ext4_readahead
......
|-- ondemand_readahead
|-- do_page_cache_ra
|-- page_cache_ra_unbounded
|-- read_pages
|-- ext4_readahead
|-- ext4_mpage_readpages
|-- filemap_create_page
|-- filemap_read_page
|-- mapping->a_ops->readpage (ext4_readpage)
|-- ext4_readpage_inline
|-- ext4_mpage_readpages
|-- submit_bio
------------------------------------------ File System Layer ------------------------------------------------------