* @brief Page cache management thread * * This is the main worker thread for page cache management. It handles: * - Garbage collection (GC) requests to free up memory * - Write-back (WB) requests to flush dirty pages to storage * * @param[in] parameter Thread parameter (unused) * * @note The thread runs in an infinite loop processing messages from the cache message queue: * - For GC comma
| 310 | * - Processes up to 4 dirty pages per WB command to prevent thread starvation |
| 311 | */ |
| 312 | static void dfs_pcache_thread(void *parameter) |
| 313 | { |
| 314 | struct dfs_pcache_mq_obj work; |
| 315 | |
| 316 | while (1) |
| 317 | { |
| 318 | if (rt_mq_recv(__pcache.mqueue, &work, sizeof(work), RT_WAITING_FOREVER) == sizeof(work)) |
| 319 | { |
| 320 | if (work.cmd == PCACHE_MQ_GC) |
| 321 | { |
| 322 | dfs_pcache_limit_check(); |
| 323 | } |
| 324 | else if (work.cmd == PCACHE_MQ_WB) |
| 325 | { |
| 326 | int count = 0; |
| 327 | rt_list_t *node; |
| 328 | struct dfs_page *page = 0; |
| 329 | |
| 330 | while (1) |
| 331 | { |
| 332 | /* try to get dirty page */ |
| 333 | dfs_pcache_lock(); |
| 334 | page = 0; |
| 335 | rt_list_for_each(node, &__pcache.list_active) |
| 336 | { |
| 337 | if (node != &__pcache.list_inactive) |
| 338 | { |
| 339 | struct dfs_aspace *aspace = rt_list_entry(node, struct dfs_aspace, cache_node); |
| 340 | dfs_aspace_lock(aspace); |
| 341 | if (aspace->list_dirty.next != &aspace->list_dirty) |
| 342 | { |
| 343 | page = rt_list_entry(aspace->list_dirty.next, struct dfs_page, dirty_node); |
| 344 | dfs_page_ref(page); |
| 345 | dfs_aspace_unlock(aspace); |
| 346 | break; |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | page = RT_NULL; |
| 351 | } |
| 352 | dfs_aspace_unlock(aspace); |
| 353 | } |
| 354 | } |
| 355 | dfs_pcache_unlock(); |
| 356 | |
| 357 | if (page) |
| 358 | { |
| 359 | struct dfs_aspace *aspace = page->aspace; |
| 360 | |
| 361 | dfs_aspace_lock(aspace); |
| 362 | if (page->is_dirty == 1 && aspace->vnode) |
| 363 | { |
| 364 | if (rt_tick_get_millisecond() - page->tick_ms >= 500) |
| 365 | { |
| 366 | if (aspace->vnode->size < page->fpos + page->size) |
| 367 | { |
| 368 | page->len = aspace->vnode->size - page->fpos; |
| 369 | } |
nothing calls this directly
no test coverage detected