source: trunk/kernel/mm/mapper.h @ 1

Last change on this file since 1 was 1, checked in by alain, 5 years ago

First import

File size: 11.2 KB
Line 
1/*
2 * mapper.h - Map memory, file or device in process virtual address space.
3 *
4 * Authors   Mohamed Lamine Karaoui (2015)
5 *           Alain Greiner (2016)
6 *
7 * Copyright (c)  UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _MAPPER_H_
26#define _MAPPER_H_
27
28#include <hal_types.h>
29#include <hal_atomic.h>
30#include <xlist.h>
31#include <grdxt.h>
32#include <rwlock.h>
33
34/****  Forward declarations ****/
35
36struct page_s;
37struct vfs_inode_s;
38
39/*******************************************************************************************
40 * The mapper implement the kernel cache for a given file or directory.
41 * There is one mapper per file. It is implemented as a three levels radix tree,
42 * entirely stored in the same cluster as the inode representing the file/dir.
43 * - The fast retrieval key is the page index in the file.
44 *   The ix1_width, ix2_width, ix3_width sub-indexes are configuration parameters.
45 * - The leaves are pointers on physical page descriptors, dynamically allocated
46 *   in the local cluster.
47 * - In a given cluster, a mapper is a "private" structure: a thread accessing the mapper
48 *   must be running in the cluster containing it (can be a local thread or a RPC thread).
49 * - The mapper is protected by a blocking "rwlock", to support several simultaneous
50 *   readers, and only one writer. This lock implement a busy waiting policy.
51 * - The two functions mapper_sync_page() and mapper_updt_page() define the generic API
52 *   used to move pages to or from the relevant file system on IOC device.
53 * - the mapper_move fragments() function is used to move data to or from a distributed
54 *   user buffer.
55 * - The mapper_get_page() function that return a page descriptor pointer from a page
56 *   index in file is in charge of handling the miss on the mapper cache.
57 * - In the present implementation the cache size increases on demand, and the
58 *   allocated memory is only released when the mapper is destroyed.
59 ******************************************************************************************/
60
61
62/*******************************************************************************************
63 * This structure defines the mapper descriptor.
64 ******************************************************************************************/
65
66typedef struct mapper_s
67{
68        struct vfs_inode_s * inode;           /*! owner file inode                                */
69        grdxt_t              radix;           /*! pages cache implemented as a radix tree         */
70        rwlock_t             lock;        /*! several readers / only one writer               */
71        uint32_t                 refcount;    /*! several vsegs can refer the same file           */
72        xlist_entry_t        vsegs_root;  /*! root of list of vsegs refering this mapper      */
73        xlist_entry_t        wait_root;   /*! root of list of threads waiting on mapper       */
74    list_entry_t         dirty_root;  /*! root of list of dirty pages                     */
75}
76mapper_t;
77
78/*******************************************************************************************
79 * This structure defines a "fragment". It is used to move data between the kernel mapper,
80 * and an user buffer, that can be split in several distributed physical pages located
81 * in different clusters. A fragment is a set of contiguous bytes in the file.
82 * - It can be stored in one single physical page in the user buffer.
83 * - It can spread two successive physical pages in the kernel mapper.
84 ******************************************************************************************/
85
86typedef struct fragment_s
87{
88    uint32_t    file_offset;         /*! offset of fragment in file (i.e. in mapper)      */
89    uint32_t    size;                /*! number of bytes in fragment                      */
90    cxy_t       buf_cxy;             /*! user buffer cluster identifier                   */
91    uint8_t   * buf_ptr;             /*! local pointer on first byte in user buffer       */
92}
93fragment_t;
94
95/*******************************************************************************************
96 * This function allocates physical memory for a mapper descriptor, and inititalizes it
97 * (refcount <= 0) / inode <= NULL).
98 * It must be executed by a thread running in the cluster containing the mapper.
99 *******************************************************************************************
100 * @ return pointer on created mapper if success / return NULL if no memory
101 ******************************************************************************************/
102mapper_t * mapper_create();
103
104/*******************************************************************************************
105 * This function releases all physical pages allocated for the mapper.
106 * It synchronizes all dirty pages (i.e. update the file on disk) if required.
107 * The mapper descriptor and the radix three themselve are released.
108 * It must be executed by a thread running in the cluster containing the mapper.
109 *******************************************************************************************
110 * @ mapper      : target mapper.
111 * @ return 0 if success / return EIO if a dirty page cannot be updated on device.
112 ******************************************************************************************/
113error_t mapper_destroy( mapper_t * mapper );
114
115/*******************************************************************************************
116 * This function moves all fragments covering a distributed user buffer between
117 * a mapper (associated to a local inode), and the user buffer.
118 * [See the fragment definition in the mapper.h file]
119 * It must be executed by a thread running in the cluster containing the mapper.
120 * The lock protecting the mapper must have been taken in WRITE_MODE or READ_MODE
121 * by the caller thread, depending on the transfer direction.
122 * In case of write, the dirty bit is set for all pages written in the mapper.
123 * The offset in the file descriptor is not modified by this function.
124 * Implementation note:
125 * For each fragment, this function makes ONE hal_remote_memcpy() when the fragment is
126 * fully contained in one single page of the mapper. It makes TWO hal_remote_memcpy()
127 * if the fragment spread on two contiguous pages in the mapper.
128 *******************************************************************************************
129 * @ mapper    : local pointer on the local mapper.
130 * @ to_buffer : mapper to buffer if true / buffer to mapper if false.
131 * @ nb_frags  : number of fragments covering the user buffer (one per page).
132 * @ frags_xp  : extended pointer on array of fragments.
133FAT * returns O if success / returns EINVAL if error.
134 ******************************************************************************************/
135error_t mapper_move_fragments( mapper_t * mapper,
136                               bool_t     to_buffer,
137                               uint32_t   nb_frags,
138                               xptr_t     frags_xp );
139
140
141/*******************************************************************************************
142 * This function removes a physical page from the mapper, update the FS if the page
143 * is dirty, and releases the page to PPM. It is called by the mapper_destroy() function.
144 * It must be executed by a thread running in the cluster containing the mapper.
145 * It takes both the page lock and the mapper lock in WRITE_MODE to release the page.
146 *******************************************************************************************
147 * @ mapper     : local pointer on the mapper.
148 * @ index      : page index in file
149 * @ page       : pointer on page to remove.
150 * @ return 0 if success / return EIO if a dirty page cannot be copied to FS.
151 ******************************************************************************************/
152error_t mapper_release_page( mapper_t      * mapper,
153                             uint32_t        index,
154                             struct page_s * page );
155
156/*******************************************************************************************
157 * This function search a physical page descriptor from its index in mapper.
158 * It must be executed by a thread running in the cluster containing the mapper.
159 * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
160 * page from device to the mapper, and release the mapper lock.
161 *******************************************************************************************
162 * @ mapper     : local pointer on the mapper.
163 * @ index      : page index in file
164 * @ returns pointer on page descriptor if success / return NULL if error.
165 ******************************************************************************************/
166struct page_s * mapper_get_page( mapper_t * mapper,
167                                 uint32_t   index );
168
169/*******************************************************************************************
170 * This function makes an I/O operation to move one page from FS to mapper.
171 * Depending on the file system type, it calls the proper, FS specific function.
172 * It must be executed by a thread running in the cluster containing the mapper.
173 *******************************************************************************************
174 * @ mapper     : local pointer on the mapper.
175 * @ index      : page index in file.
176 * @ page   : local pointer on the page descriptor in mapper.
177 * @ returns 0 if success / return EINVAL if it cannot access the device.
178 ******************************************************************************************/
179error_t mapper_updt_page( mapper_t      * mapper,
180                          uint32_t        index,
181                          struct page_s * page );       
182             
183/*******************************************************************************************
184 * This function makes an I/0 operation to move one page from mapper to FS.
185 * Depending on the file system type, it calls the proper, FS specific function.
186 * It must be executed by a thread running in the cluster containing the mapper.
187 * It does nothing if the page is not dirty. If the page is dirty, it takes
188 * the page lock before launching the IO operation, clear the page dirty bit,
189 * and remove the page from the PPM dirty list. It does nothing if the page is not dirty.
190 *******************************************************************************************
191 * @ mapper     : local pointer on the mapper.
192 * @ index      : page index in file.
193 * @ page   : local pointer on the page descriptor in mapper.
194 * @ returns 0 if success / return EINVAL if it cannot access the device.
195 ******************************************************************************************/
196error_t mapper_sync_page( mapper_t      * mapper,
197                          uint32_t        index,
198                          struct page_s * page );       
199
200#endif /* _MAPPER_H_ */
Note: See TracBrowser for help on using the repository browser.