MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / fs_trim_cache

Function fs_trim_cache

tinyemu/fs_net.c:670–697  ·  view source on GitHub ↗

remove elements in the cache considering that 'added_size' will be added */

Source from the content-addressed store, hash-verified

668/* remove elements in the cache considering that 'added_size' will be
669 added */
670static void fs_trim_cache(FSDevice *fs1, int64_t added_size)
671{
672 FSDeviceMem *fs = (FSDeviceMem *)fs1;
673 struct list_head *el, *el1;
674 FSINode *n;
675
676 if ((fs->inode_cache_size + added_size) <= fs->inode_cache_size_limit)
677 return;
678 list_for_each_prev_safe(el, el1, &fs->inode_cache_list) {
679 n = list_entry(el, FSINode, u.reg.link);
680 assert(n->u.reg.state == REG_STATE_LOADED);
681 /* cannot remove open files */
682 // printf("open_count=%d\n", n->open_count);
683 if (n->open_count != 0)
684 continue;
685#ifdef DEBUG_CACHE
686 printf("fs_trim_cache: remove '%s' size=%ld\n",
687 n->u.reg.filename, (long)n->u.reg.size);
688#endif
689 file_buffer_reset(&n->u.reg.fbuf);
690 n->u.reg.state = REG_STATE_UNLOADED;
691 list_del(&n->u.reg.link);
692 fs->inode_cache_size -= n->u.reg.size;
693 assert(fs->inode_cache_size >= 0);
694 if ((fs->inode_cache_size + added_size) <= fs->inode_cache_size_limit)
695 break;
696 }
697}
698
699static void fs_open_end(FSOpenInfo *oi)
700{

Callers 1

fs_open_wgetFunction · 0.85

Calls 2

file_buffer_resetFunction · 0.85
list_delFunction · 0.85

Tested by

no test coverage detected