更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
fs_cache_proc.c 文件参考

浏览源代码.

函数

static char * VnodeTypeToStr (enum VnodeType type)
 
static int VnodeListProcess (struct SeqBuf *buf, LIST_HEAD *list)
 
static int PathCacheListProcess (struct SeqBuf *buf)
 
static int PageCacheEntryProcess (struct SeqBuf *buf, struct page_mapping *mapping)
 
static int PageCacheMapProcess (struct SeqBuf *buf)
 
static int FsCacheInfoFill (struct SeqBuf *buf, void *arg)
 
static int FsCacheClear (struct ProcFile *pf, const char *buffer, size_t buflen, loff_t *ppos)
 
void ProcFsCacheInit (void)
 

变量

static const struct ProcFileOperations FS_CACHE_PROC_FOPS
 

函数说明

◆ FsCacheClear()

static int FsCacheClear ( struct ProcFile pf,
const char *  buffer,
size_t  buflen,
loff_t *  ppos 
)
static

在文件 fs_cache_proc.c180 行定义.

181{
182 if (buffer == NULL || buflen < sizeof(CLEAR_ALL_CACHE)) {
183 return -EINVAL;
184 }
185 int vnodeCount = 0;
186 int pageCount = 0;
187
188 if (!strcmp(buffer, CLEAR_ALL_CACHE)) {
189 vnodeCount = VnodeClearCache();
190 pageCount = OsTryShrinkMemory(VM_FILEMAP_MAX_SCAN);
191 } else if (!strcmp(buffer, CLEAR_PAGE_CACHE)) {
192 pageCount = OsTryShrinkMemory(VM_FILEMAP_MAX_SCAN);
193 } else if (!strcmp(buffer, CLEAR_PATH_CACHE)) {
194 vnodeCount = VnodeClearCache();
195 } else {
196 return -EINVAL;
197 }
198
199 PRINTK("%d vnodes and related pathcaches cleared\n%d pages cleared\n", vnodeCount, pageCount);
200 return buflen;
201}
int OsTryShrinkMemory(size_t nPage)
Definition: los_vm_scan.c:340
int VnodeClearCache(void)
Definition: vnode.c:741
函数调用图:

◆ FsCacheInfoFill()

static int FsCacheInfoFill ( struct SeqBuf buf,
void arg 
)
static

在文件 fs_cache_proc.c137 行定义.

138{
139 int vnodeFree;
140 int vnodeActive;
141 int vnodeVirtual;
142 int vnodeTotal;
143
144 int pathCacheTotal;
145 int pathCacheTotalTry = 0;
146 int pathCacheTotalHit = 0;
147
148 int pageCacheTotal;
149 int pageCacheTotalTry = 0;
150 int pageCacheTotalHit = 0;
151
152 ResetPathCacheHitInfo(&pathCacheTotalHit, &pathCacheTotalTry);
153 ResetPageCacheHitInfo(&pageCacheTotalTry, &pageCacheTotalHit);
154
155 VnodeHold();
156 LosBufPrintf(buf, "\n=================================================================\n");
157 LosBufPrintf(buf, "VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n");
158 vnodeVirtual = VnodeListProcess(buf, GetVnodeVirtualList());
159 vnodeFree = VnodeListProcess(buf, GetVnodeFreeList());
160 vnodeActive = VnodeListProcess(buf, GetVnodeActiveList());
161 vnodeTotal = vnodeVirtual + vnodeFree + vnodeActive;
162
163 LosBufPrintf(buf, "\n=================================================================\n");
164 LosBufPrintf(buf, "No. CacheAddr ParentAddr ChildAddr HitCount Name\n");
165 pathCacheTotal = PathCacheListProcess(buf);
166
167 LosBufPrintf(buf, "\n=================================================================\n");
168 pageCacheTotal = PageCacheMapProcess(buf);
169
170 LosBufPrintf(buf, "\n=================================================================\n");
171 LosBufPrintf(buf, "PathCache Total:%d Try:%d Hit:%d\n",
172 pathCacheTotal, pathCacheTotalTry, pathCacheTotalHit);
173 LosBufPrintf(buf, "Vnode Total:%d Free:%d Virtual:%d Active:%d\n",
174 vnodeTotal, vnodeFree, vnodeVirtual, vnodeActive);
175 LosBufPrintf(buf, "PageCache total:%d Try:%d Hit:%d\n", pageCacheTotal, pageCacheTotalTry, pageCacheTotalHit);
176 VnodeDrop();
177 return 0;
178}
static int PageCacheMapProcess(struct SeqBuf *buf)
static int VnodeListProcess(struct SeqBuf *buf, LIST_HEAD *list)
Definition: fs_cache_proc.c:67
static int PathCacheListProcess(struct SeqBuf *buf)
Definition: fs_cache_proc.c:83
int LosBufPrintf(struct SeqBuf *seqBuf, const char *fmt,...)
支持可变参数 写 buf
Definition: los_seq_buf.c:133
VOID ResetPageCacheHitInfo(int *try, int *hit)
void ResetPathCacheHitInfo(int *hit, int *try)
Definition: path_cache.c:46
LIST_HEAD * GetVnodeVirtualList(void)
Definition: vnode.c:731
int VnodeDrop(void)
归还锁
Definition: vnode.c:292
int VnodeHold(void)
拿锁,封装互斥量
Definition: vnode.c:283
LIST_HEAD * GetVnodeFreeList(void)
Definition: vnode.c:726
LIST_HEAD * GetVnodeActiveList(void)
Definition: vnode.c:736
函数调用图:

◆ PageCacheEntryProcess()

static int PageCacheEntryProcess ( struct SeqBuf buf,
struct page_mapping mapping 
)
static

在文件 fs_cache_proc.c102 行定义.

103{
104 int total = 0;
105 LosFilePage *fpage = NULL;
106
107 if (mapping->nrpages == 0) {
108 LosBufPrintf(buf, "null]\n");
109 return total;
110 }
111
112 LOS_DL_LIST_FOR_EACH_ENTRY(fpage, &mapping->page_list, LosFilePage, node) {
113 LosBufPrintf(buf, "%d,", fpage->pgoff);
114 total++;
115 }
116 LosBufPrintf(buf, "]\n");
117 return total;
118}
文件页结构体
VM_OFFSET_T pgoff
页标,文件被切成一页一页读到内存
unsigned long nrpages
LOS_DL_LIST page_list
函数调用图:
这是这个函数的调用关系图:

◆ PageCacheMapProcess()

static int PageCacheMapProcess ( struct SeqBuf buf)
static

在文件 fs_cache_proc.c120 行定义.

121{
122 LIST_HEAD *vnodeList = GetVnodeActiveList();
123 struct page_mapping *mapping = NULL;
124 struct Vnode *vnode = NULL;
125 int total = 0;
126
127 VnodeHold();
128 LOS_DL_LIST_FOR_EACH_ENTRY(vnode, vnodeList, struct Vnode, actFreeEntry) {
129 mapping = &vnode->mapping;
130 LosBufPrintf(buf, "%p, %s:[", vnode, vnode->filePath);
131 total += PageCacheEntryProcess(buf, mapping);
132 }
133 VnodeDrop();
134 return total;
135}
static int PageCacheEntryProcess(struct SeqBuf *buf, struct page_mapping *mapping)
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
struct page_mapping mapping
Definition: vnode.h:183
char * filePath
Definition: vnode.h:182
LIST_ENTRY actFreeEntry
Definition: vnode.h:179
函数调用图:
这是这个函数的调用关系图:

◆ PathCacheListProcess()

static int PathCacheListProcess ( struct SeqBuf buf)
static

在文件 fs_cache_proc.c83 行定义.

84{
85 int count = 0;
86 LIST_HEAD* bucketList = GetPathCacheList();
87
88 for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
89 struct PathCache *pc = NULL;
90 LIST_HEAD *list = &bucketList[i];
91
92 LOS_DL_LIST_FOR_EACH_ENTRY(pc, list, struct PathCache, hashEntry) {
93 LosBufPrintf(buf, "%-3d %-10p %-11p %-10p %-9d %s\n", i, pc,
94 pc->parentVnode, pc->childVnode, pc->hit, pc->name);
95 count++;
96 }
97 }
98
99 return count;
100}
LIST_HEAD * GetPathCacheList(void)
Definition: path_cache.c:208
struct Vnode * childVnode
Definition: path_cache.h:40
char name[0]
Definition: path_cache.h:48
LIST_ENTRY hashEntry
Definition: path_cache.h:43
struct Vnode * parentVnode
Definition: path_cache.h:39
函数调用图:
这是这个函数的调用关系图:

◆ ProcFsCacheInit()

void ProcFsCacheInit ( void  )

在文件 fs_cache_proc.c207 行定义.

208{
209 struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0, NULL);
210 if (pde == NULL) {
211 PRINT_ERR("create fs_cache error!\n");
212 return;
213 }
214
216}
static const struct ProcFileOperations FS_CACHE_PROC_FOPS
struct ProcDirEntry * CreateProcEntry(const char *name, mode_t mode, struct ProcDirEntry *parent)
create a proc node
Definition: proc_file.c:364
proc 目录/文件项, @notethinking 直接叫 ProcEntry不香吗 ? 操作 /proc的 真正结构体
Definition: proc_fs.h:101
const struct ProcFileOperations * procFileOps
驱动程序,每个 /proc 下目录的驱动程序都不一样
Definition: proc_fs.h:106
函数调用图:
这是这个函数的调用关系图:

◆ VnodeListProcess()

static int VnodeListProcess ( struct SeqBuf buf,
LIST_HEAD list 
)
static

在文件 fs_cache_proc.c67 行定义.

68{
69 int count = 0;
70 struct Vnode *item = NULL;
71 struct Vnode *nextItem = NULL;
72
73 LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, list, struct Vnode, actFreeEntry) {
74 LosBufPrintf(buf, "%-10p %-10p %-10p %10p 0x%08x %-3d %-4s %-3d %-3d %-8o\t%s\n",
75 item, item->parent, item->data, item->vop, item->hash, item->useCount,
76 VnodeTypeToStr(item->type), item->gid, item->uid, item->mode, item->filePath);
77 count++;
78 }
79
80 return count;
81}
static char * VnodeTypeToStr(enum VnodeType type)
Definition: fs_cache_proc.c:43
uint32_t hash
Definition: vnode.h:167
uint gid
Definition: vnode.h:169
enum VnodeType type
Definition: vnode.h:165
struct VnodeOps * vop
Definition: vnode.h:174
mode_t mode
Definition: vnode.h:170
int useCount
Definition: vnode.h:166
void * data
Definition: vnode.h:176
uint uid
Definition: vnode.h:168
struct Vnode * parent
Definition: vnode.h:173
函数调用图:
这是这个函数的调用关系图:

◆ VnodeTypeToStr()

static char * VnodeTypeToStr ( enum VnodeType  type)
static

在文件 fs_cache_proc.c43 行定义.

44{
45 switch (type) {
47 return "UKN";
48 case VNODE_TYPE_REG:
49 return "REG";
50 case VNODE_TYPE_DIR:
51 return "DIR";
52 case VNODE_TYPE_BLK:
53 return "BLK";
54 case VNODE_TYPE_CHR:
55 return "CHR";
56 case VNODE_TYPE_BCHR:
57 return "BCH";
58 case VNODE_TYPE_FIFO:
59 return "FIF";
60 case VNODE_TYPE_LNK:
61 return "LNK";
62 default:
63 return "BAD";
64 }
65}
@ VNODE_TYPE_LNK
Definition: vnode.h:142
@ VNODE_TYPE_DIR
Definition: vnode.h:137
@ VNODE_TYPE_FIFO
Definition: vnode.h:141
@ VNODE_TYPE_CHR
Definition: vnode.h:139
@ VNODE_TYPE_BLK
Definition: vnode.h:138
@ VNODE_TYPE_UNKNOWN
Definition: vnode.h:135
@ VNODE_TYPE_REG
Definition: vnode.h:136
@ VNODE_TYPE_BCHR
Definition: vnode.h:140
这是这个函数的调用关系图:

变量说明

◆ FS_CACHE_PROC_FOPS

const struct ProcFileOperations FS_CACHE_PROC_FOPS
static
初始值:
= {
.read = FsCacheInfoFill,
.write = FsCacheClear,
}
static int FsCacheClear(struct ProcFile *pf, const char *buffer, size_t buflen, loff_t *ppos)
static int FsCacheInfoFill(struct SeqBuf *buf, void *arg)

在文件 fs_cache_proc.c202 行定义.