7월, 2025의 게시물 표시

리눅스 커널 파일 시스템 [5] Write

리눅스 커널 파일 시스템 Read [1] 리눅스 커널 파일 시스템 Read [2] 리눅스 커널 파일 시스템 Read [3] 리눅스 커널 파일 시스템 Read [4] Now, let's take a look at the write process. We'll examine what happens when a write system call is invoked and which kernel functions are called along the way. 나중에 영어로 바꾸는 작업을 해야겠다. 자 이제 write 시스템콜이 불렸을 때 커널의 어떤 함수들이 호출되는지 알아보자. 여전히 ext4 기준으로 살펴볼 것이다. SYSCALL_DEFINE3(write, ...) --> ksys_write() --> vfs_write() --> rw_verify_area() (유저 포인터 유효성, 파일 모드 검사) -- file->f_op->write_iter 가 있는지 검사 여기서 잠깐 write()가 있고 write_iter()가 있다. 무슨 차이일까? write()는 전통적인 방식이며 write_iter()는 보다 일반화되고 유연한 인터페이스이다. 비동기 I/O (AIO, 즉 write가 끝날 때까지 기다리지 않고 다음 작업 수행하도록 함), vectored I/O (scatter/gather I/O) 등을 지원한다. ext4에서는 write에 해당하는 함수가 없기 때문에 write_iter()가 불릴 것이다. 하지만 그 전에 다양한 I/O를 지원하기 위해 new_sync_write() 함수가 먼저 불려 AIO, vectored I/O 등을 위한 준비를 한다. -- new_sync_write() (중간 레이어) --> file->f_op->write_iter() == ext4_file_write_iter() --> ext4_buffered_write_iter() --> generic_perform_...

리눅스 커널 파일 시스템 [4] 정리 - Read

리눅스 커널 파일 시스템 Read [1] 리눅스 커널 파일 시스템 Read [2] 리눅스 커널 파일 시스템 Read [3] 1. 시스템콜이 vfs를 거쳐 각 파일시스템으로 간다. 2. 각 파일시스템에서 read를 어떻게 처리할지 결정 (Storage에서 바로 읽을지, Page cache에서 읽을지) 3. (Page cache에서 읽을 경우) mm/filemap.c의 generic_file_read_iter()로 간다. 디렉토리 명 (mm == memory management)에서 볼수 있듯이 이제 메인 메모리의 영역이다. Page cache는 메인 메모리에 저장되어 있다. 4. Storage의 해당 데이터가 메인 메모리에 있는지 살펴본다 (즉, 해당 데이터에 대한 page cache 가 존재하는지 살펴본다.) (이 단계는 filemap_get_pages()의 filemap_get_read_batch()에 의해 수행된다. page cache가 struct address_space *mapping에 존재하는지 살펴본다. 이때 xarray가 사용되는데 (xas_load, xas_next 같은 함수들), xarray는 매우 큰 인덱스 공간을 빠르게 탐색하는 동적 인덱싱 자료구조이다. 기존 radix tree를 대체한다.). 5. 해당 데이터에 대한 Page cache가 없다면 Storage로부터 Page cache에 데이터를 읽어온다 (filemap_read()를 통해 ext_readahead 까지 가게 된다.). 6. Page cache의 데이터를 사용자 공간으로 복사한다 (copy_folio_to_iter()). iocb->ki_pos에 업데이트된 file offset (파일 내에 I/O가 읽거나 쓸 위치)이 저장된다. 아래 함수 흐름을 살펴보자. read system call --> ksys_read() --> vfs_read() --> new_sync_read() --> ext4_file_read_iter() --> generi...

[OPIC] 추가 감정 표현

1. Happiness & Joy I feel happy when I spend time doing my favorite hobby. Paintng makes me feel joyful and relaxed. I was on cloud nine (하늘에 날아오를 듯한) when I finished my project successfully. I always feel upbeat (긍정적인, 낙관적인)after a good workout. I get so much enjoyment from reading a good book. 2. Calm & Relaxation I feel at peace when I listen to music. Yoga helps me feel peaceful and calm. This hobby gives me a blissful state of mind. Whenever I meditate, I feel completely tranquil. 3. Satisfaction, Pride & Accomplishment I feel fulfilled after volunteering at the local shelter. Completing a challenging puzzle gives me a sense of accomplishment. I feel proud of myself when I learn something new. I enjoy the sense of achievement my work brings me (내 일이 나에게 가져다주는 성취감). 4. Excitement & Anticipation I'm excited to start a new hobby. I always look forward to my weekend plans. I get butterflies in my stomach (긴장하거나 떨리다, 가슴이 조마조마하다) before trying something new. I was pu...

[OPIC] 기분/감정 표현

1. 평화로움/편안함 (Feeling Peaceful/Relaxed) I feel at peace when I'm floating on the water. Being in nature always makes me feel calm and relaxed. Swimming helps me clear my mind and forget about stress. I love the tranquil(고요한/평온한) atmosphere at the pool. 2. 행복/즐거움 (Feeling Happy/Joyful) I feel so happy when I spend time with my friends. It's always fun to try new activities. I get excited whenever I go swimming. I feel a sense of joy when I achieve somthing new. 3. 스트레스 해소/기분 전환 (Relieving Stress/Refreshing) Swimming is a great way for me to relieve stress. After exercising, I feel refreshed and energized. When I'm stressed out, I go for a swim to clear my head. 4. 자신감/성취감 (Confidence/Achievement) I feel proud of myslef when I learn a new skill. Completing a difficult workout gives me a sense of accomplishment. I gain confidence every time I improve my swimming skills. 5. 아쉬움/실망 (Disappointment/Regret) I feel disappointed when I can't go swimming because of the weather. So...

[OPIC] 문장 구조

 1. 원인 - 결과 구조 (Cause and Effect) I started swimming because I wanted to stay healthy. Since I began this hobby, I have felt much happier. 2. 비교, 대조 구조 (Comparison/Constrast) Swimming is more relaxing than running. Unlike other sports, swimming helps me clear my mind. 3. 경험 설명 구조 (Experience/Storytelling) One time , I forgot my swimsuit, so I had to borrow one from a friend. I remember the first time I learned how to float on water. 4. 의견 제시 구조 (Giving Opinions) In my opinion , swimminig is the best exercise. I believe that everyone should learn how to swim. 5. 조건문 (Conditional Sentences) If I have free time , I usually go swimming. If I hadn't learned to swim, I would have missed out on many fun experiences. 6. 이유 설명 구조 (Explaining Reasons) The reason I enjoy swimming is that it helps me relax after a long day. I like outdoor pools because I can enjoy the sunshine. 7. 과거와 현재 비교 (Past vs. Present) When I was younger , I was afraid of water. Now, I love swimming. In the pas...

리눅스 커널 파일 시스템 [3] 코드 분석 - page_cache_sync_ra()

리눅스 커널 파일 시스템 Read [1] 리눅스 커널 파일 시스템 Read [2] 리눅스 커널 파일 시스템 Read [3] 리눅스 커널 파일 시스템 Read [4]   이전 게시물 void page_cache_sync_ra(struct readahead_control *ractl, unsigned long req_count) { pgoff_t index = readahead_index(ractl); bool do_forced_ra = ractl->file && (ractl->file->f_mode & FMODE_RANDOM); struct file_ra_state *ra = ractl->ra; unsigned long max_pages, contig_count; pgoff_t prev_index, miss; /* * Even if readahead is disabled, issue this request as readahead * as we'll need it to satisfy the requested range. The forced * readahead will do the right thing and limit the read to just the * requested range, which we'll set to 1 page for this case. */ if (!ra->ra_pages || blk_cgroup_congested()) { if (!ractl->file) return; req_count = 1; do_forced_ra = true; } /* be dumb */ if (do_forced_ra) { force_page_cache_ra(ractl, req_count); return; } max_pages = ractl_max_pages(ractl, req_count); prev_index = (unsig...

리눅스 커널 파일 시스템 - F2FS

F2FS Flash Friendly File System (F2FS), Embedded Linux Conference  (2013-02-22) 위 발표자료를 보면서 공부해보자. Log-structured File System (LFS) fits well to FTL devices. data와 metadata를 연속적으로 "쓰기"한다. 논문을 봐야 이해가 될 것 같다. 논문은 2015년이다. https://www.usenix.org/system/files/conference/fast15/fast15-paper-lee.pdf 문제점: Frequent random writes --> internal fragmentation --> I/O latency, device lifetime에 악영향 해결책: Log-structured file system (LFS) 과 copy-on-write (CoW) 결합 예를 들어 BTRFS파일시스템은 NAND flash SSD에서 성능이 잘 나올 것임 - 하지만 Flash storage에 대한 고려가 부족하여 성능과 lifetime이 아주 좋지는 않을 것임. LFS 기존 데이터를 덮어쓰지 않고 새로운 공간에 기록 후 추후 Garbage Collection (GC) 한다. random/sequential write에는 잘 맞지만 sequential read 시에는 성능 떨어질 수 있음. CoW 수정이 일어나면 기존 데이터를 덮어쓰지 않고, 새로 복사본을 만들어 그 복사본에 수정하는 기법. 데이터 일관성 유지 (crash 나도 기존 데이터 존재함)에 도움이 된다. 그리고 overwrite에 취약한 SSD에 좋다. (예시: Btrfs) 일관성 유지 측면: 1. 파일 A가 block #100 ~ #110 차지 2. 파일 A 일부 수정 요청 3. 파일 시스템은 block #100 덮어쓰지 않음 4. 대신 block #200에 새로 쓴 뒤, inode를 block #200으로 바꿈 5. crash 나도 block...