1
1
/*
2
- * Copyright (c) 2006-2023, RT-Thread Development Team
2
+ * Copyright (c) 2006-2025 RT-Thread Development Team
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*
@@ -29,72 +29,77 @@ struct dfs_vnode;
29
29
struct dfs_dentry ;
30
30
struct dfs_aspace ;
31
31
32
+ /* Memory mapping structure for page cache */
32
33
struct dfs_mmap
33
34
{
34
- rt_list_t mmap_node ;
35
- struct rt_aspace * aspace ;
36
- void * vaddr ;
35
+ rt_list_t mmap_node ; /* List node for address space's mmap list */
36
+ struct rt_aspace * aspace ; /* Address space this mapping belongs to */
37
+ void * vaddr ; /* Virtual address where the page is mapped */
37
38
};
38
39
40
+ /* Page structure for file system page cache */
39
41
struct dfs_page
40
42
{
41
- rt_list_t space_node ;
42
- rt_list_t dirty_node ;
43
- struct util_avl_struct avl_node ;
44
- rt_list_t mmap_head ;
43
+ rt_list_t space_node ; /* Node for address space's page list */
44
+ rt_list_t dirty_node ; /* Node for dirty page list */
45
+ struct util_avl_struct avl_node ; /* Node for AVL tree in address space */
46
+ rt_list_t mmap_head ; /* Head of memory mappings list */
45
47
46
- rt_atomic_t ref_count ;
48
+ rt_atomic_t ref_count ; /* Reference count for this page */
47
49
48
- void * page ;
49
- off_t fpos ;
50
- size_t size ;
51
- size_t len ;
52
- int is_dirty ;
53
- rt_tick_t tick_ms ;
50
+ void * page ; /* Pointer to physical page data */
51
+ off_t fpos ; /* File position this page represents */
52
+ size_t size ; /* Total size of the page */
53
+ size_t len ; /* Valid data length in the page */
54
+ int is_dirty ; /* Dirty flag indicating if page needs writeback */
55
+ rt_tick_t tick_ms ; /* Last access timestamp */
54
56
55
- struct dfs_aspace * aspace ;
57
+ struct dfs_aspace * aspace ; /* Address space this page belongs to */
56
58
};
57
59
60
+ /* Address space operations interface */
58
61
struct dfs_aspace_ops
59
62
{
60
- ssize_t (* read )(struct dfs_file * file , struct dfs_page * page );
61
- ssize_t (* write )(struct dfs_page * page );
63
+ ssize_t (* read )(struct dfs_file * file , struct dfs_page * page ); /* Read operation for page cache */
64
+ ssize_t (* write )(struct dfs_page * page ); /* Write operation for page cache */
62
65
};
63
66
67
+ /* Address space structure for page cache management */
64
68
struct dfs_aspace
65
69
{
66
- rt_list_t hash_node , cache_node ;
67
- char * fullpath , * pathname ;
68
- struct dfs_mnt * mnt ;
70
+ rt_list_t hash_node , cache_node ; /* Nodes for hash table and cache lists */
71
+ char * fullpath , * pathname ; /* Full path and relative path strings */
72
+ struct dfs_mnt * mnt ; /* Mount point this space belongs to */
69
73
70
- rt_list_t list_active , list_inactive ;
71
- rt_list_t list_dirty ;
72
- size_t pages_count ;
74
+ rt_list_t list_active , list_inactive ; /* Active and inactive page lists */
75
+ rt_list_t list_dirty ; /* Dirty page list */
76
+ size_t pages_count ; /* Total pages in this space */
73
77
74
- struct util_avl_root avl_root ;
75
- struct dfs_page * avl_page ;
78
+ struct util_avl_root avl_root ; /* AVL tree root for page lookup */
79
+ struct dfs_page * avl_page ; /* Current AVL tree page */
76
80
77
- rt_bool_t is_active ;
81
+ rt_bool_t is_active ; /* Active/inactive status flag */
78
82
79
- struct rt_mutex lock ;
80
- rt_atomic_t ref_count ;
83
+ struct rt_mutex lock ; /* Mutex for thread safety */
84
+ rt_atomic_t ref_count ; /* Reference counter */
81
85
82
- struct dfs_vnode * vnode ;
83
- const struct dfs_aspace_ops * ops ;
86
+ struct dfs_vnode * vnode ; /* Associated vnode */
87
+ const struct dfs_aspace_ops * ops ; /* Operations interface */
84
88
};
85
89
86
90
#ifndef RT_PAGECACHE_HASH_NR
87
91
#define RT_PAGECACHE_HASH_NR 1024
88
92
#endif
89
93
94
+ /* Global page cache management structure */
90
95
struct dfs_pcache
91
96
{
92
- rt_list_t head [RT_PAGECACHE_HASH_NR ];
93
- rt_list_t list_active , list_inactive ;
94
- rt_atomic_t pages_count ;
95
- struct rt_mutex lock ;
96
- struct rt_messagequeue * mqueue ;
97
- rt_tick_t last_time_wb ;
97
+ rt_list_t head [RT_PAGECACHE_HASH_NR ]; /* Hash table buckets for address spaces */
98
+ rt_list_t list_active , list_inactive ; /* Active and inactive space lists */
99
+ rt_atomic_t pages_count ; /* Total cached pages count */
100
+ struct rt_mutex lock ; /* Global lock for thread safety */
101
+ struct rt_messagequeue * mqueue ; /* Message queue for sending GC/WB command.*/
102
+ rt_tick_t last_time_wb ; /* Last writeback timestamp */
98
103
};
99
104
100
105
struct dfs_aspace * dfs_aspace_create (struct dfs_dentry * dentry , struct dfs_vnode * vnode , const struct dfs_aspace_ops * ops );
@@ -126,4 +131,4 @@ void dfs_pcache_clean(struct dfs_mnt *mnt);
126
131
127
132
#endif
128
133
129
- #endif
134
+ #endif
0 commit comments