* @brief Look up a page in the cache and load it if not found * * This function searches for a page at the specified position in the file's address space. * If the page isn't found, it preloads multiple pages (RT_PAGECACHE_PRELOAD count) next to the requested position. * It also triggers garbage collection when the cache reaches certain thresholds. * * @param[in] file Pointer to the file str
| 1478 | * NULL if the page couldn't be found or loaded |
| 1479 | */ |
| 1480 | static struct dfs_page *dfs_page_lookup(struct dfs_file *file, off_t pos) |
| 1481 | { |
| 1482 | struct dfs_page *page = RT_NULL; |
| 1483 | struct dfs_aspace *aspace = file->vnode->aspace; |
| 1484 | |
| 1485 | dfs_aspace_lock(aspace); |
| 1486 | page = dfs_page_search(aspace, pos); |
| 1487 | if (!page) |
| 1488 | { |
| 1489 | int count = RT_PAGECACHE_PRELOAD; |
| 1490 | struct dfs_page *tmp = RT_NULL; |
| 1491 | off_t fpos = pos / ARCH_PAGE_SIZE * ARCH_PAGE_SIZE; |
| 1492 | |
| 1493 | do |
| 1494 | { |
| 1495 | page = dfs_aspace_load_page(file, fpos); |
| 1496 | if (page) |
| 1497 | { |
| 1498 | if (tmp == RT_NULL) |
| 1499 | { |
| 1500 | tmp = page; |
| 1501 | } |
| 1502 | else |
| 1503 | { |
| 1504 | dfs_page_release(page); |
| 1505 | } |
| 1506 | } |
| 1507 | else |
| 1508 | { |
| 1509 | break; |
| 1510 | } |
| 1511 | |
| 1512 | fpos += ARCH_PAGE_SIZE; |
| 1513 | page = dfs_page_search(aspace, fpos); |
| 1514 | if (page) |
| 1515 | { |
| 1516 | dfs_page_release(page); |
| 1517 | } |
| 1518 | count --; |
| 1519 | |
| 1520 | } while (count && page == RT_NULL); |
| 1521 | |
| 1522 | page = tmp; |
| 1523 | if (page) |
| 1524 | { |
| 1525 | dfs_aspace_unlock(aspace); |
| 1526 | |
| 1527 | if (rt_atomic_load(&(__pcache.pages_count)) >= RT_PAGECACHE_COUNT) |
| 1528 | { |
| 1529 | dfs_pcache_limit_check(); |
| 1530 | } |
| 1531 | else if (rt_atomic_load(&(__pcache.pages_count)) >= RT_PAGECACHE_COUNT * RT_PAGECACHE_GC_WORK_LEVEL / 100) |
| 1532 | { |
| 1533 | dfs_pcache_mq_work(PCACHE_MQ_GC); |
| 1534 | } |
| 1535 | |
| 1536 | return page; |
| 1537 | } |
no test coverage detected