* @brief Release a page from page cache when reference count reaches zero * * This function decrements the reference count of a page and performs cleanup * when the count reaches zero. It handles: * - Unmapping all virtual mappings of the page * - Writing back dirty pages to storage * - Freeing physical memory and page structure * * @param[in,out] page Pointer to the page structure to be r
| 1053 | * @param[in,out] page Pointer to the page structure to be released |
| 1054 | */ |
| 1055 | static void dfs_page_release(struct dfs_page *page) |
| 1056 | { |
| 1057 | struct dfs_aspace *aspace = page->aspace; |
| 1058 | |
| 1059 | dfs_aspace_lock(aspace); |
| 1060 | |
| 1061 | rt_atomic_sub(&(page->ref_count), 1); |
| 1062 | |
| 1063 | if (rt_atomic_load(&(page->ref_count)) == 0) |
| 1064 | { |
| 1065 | dfs_page_unmap(page); |
| 1066 | |
| 1067 | if (page->is_dirty == 1 && aspace->vnode) |
| 1068 | { |
| 1069 | if (aspace->vnode->size < page->fpos + page->size) |
| 1070 | { |
| 1071 | page->len = aspace->vnode->size - page->fpos; |
| 1072 | } |
| 1073 | else |
| 1074 | { |
| 1075 | page->len = page->size; |
| 1076 | } |
| 1077 | if (aspace->ops->write) |
| 1078 | { |
| 1079 | aspace->ops->write(page); |
| 1080 | } |
| 1081 | page->is_dirty = 0; |
| 1082 | } |
| 1083 | RT_ASSERT(page->is_dirty == 0); |
| 1084 | |
| 1085 | rt_pages_free(page->page, 0); |
| 1086 | page->page = RT_NULL; |
| 1087 | rt_free(page); |
| 1088 | } |
| 1089 | |
| 1090 | dfs_aspace_unlock(aspace); |
| 1091 | } |
| 1092 | |
| 1093 | /** |
| 1094 | * @brief Compare file positions for page alignment |
no test coverage detected