MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_page_lookup

Function dfs_page_lookup

components/dfs/dfs_v2/src/dfs_pcache.c:1480–1542  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

1478 * NULL if the page couldn't be found or loaded
1479 */
1480static 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 }

Callers 3

dfs_aspace_readFunction · 0.85
dfs_aspace_writeFunction · 0.85
dfs_aspace_mmapFunction · 0.85

Calls 7

dfs_aspace_lockFunction · 0.85
dfs_page_searchFunction · 0.85
dfs_aspace_load_pageFunction · 0.85
dfs_page_releaseFunction · 0.85
dfs_aspace_unlockFunction · 0.85
dfs_pcache_limit_checkFunction · 0.85
dfs_pcache_mq_workFunction · 0.85

Tested by

no test coverage detected