source: trunk/kernel/mm/kcm.h @ 119

Last change on this file since 119 was 50, checked in by alain, 7 years ago

bloup

File size: 6.0 KB
Line 
1/*
2 * kcm.h - Per-cluster Kernel Cache Manager Interface
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
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 _KCM_H_
26#define _KCM_H_
27
28#include <list.h>
29#include <hal_types.h>
30#include <spinlock.h>
31#include <page.h>
32#include <bits.h>
33#include <kmem.h>
34
35/****************************************************************************************
36 * This structure defines a generic Kernel Cache Manager, that is a block allocator,
37 * for fixed size objects. It exists a specific KCM allocator for each object type.
38 * The actual allocated block size is the smallest multiple of the KCM slot, that
39 * contain one single object. The KCM slot is typically 64 bytes, as it must be large
40 * enough to store the kcm_page descriptor, defined below.
41 * The various KCM allocators themselves are not statically allocated in the cluster
42 * manager, but are dynamically allocated when required, using the embedded KCM
43 * allocator defined in the cluster manager, to allocate the other ones...
44 ***************************************************************************************/
45
46typedef struct kcm_s
47{
48        spinlock_t           lock;             /*! protect exclusive access to allocator   */
49        uint32_t             block_size;       /*! rounded block size (bytes)              */
50        uint32_t             blocks_nr;        /*! max number of blocks per page           */
51
52        list_entry_t         active_root;      /*! root of active pages list               */
53        list_entry_t         busy_root;        /*! root of busy pages list                 */
54        list_entry_t         free_root;        /*! root of free pages list                 */
55
56        uint32_t             free_pages_nr;    /*! number of free pages                    */
57        uint32_t             busy_pages_nr;    /*! number of busy pages                    */
58        uint32_t             active_pages_nr;  /*! number of active pages                  */
59
60    uint32_t             type;             /*! KCM type                                */
61}
62kcm_t;
63
64
65/****************************************************************************************
66 * This structure defines a KCM-page descriptor.
67 * A KCM-page contains at most (CONFIG_PPM_PAGE_SIZE / CONFIG_KCM_SLOT_SIZE) blocks.
68 * This kcm page descriptor is stored in the first slot of the page.
69 ***************************************************************************************/
70
71typedef struct kcm_page_s
72{
73        uint32_t        bitmap[2];             /*! at most 64 blocks in a single page      */
74        list_entry_t    list;                  /*! [active / busy / free] list member      */
75    kcm_t         * kcm;                   /*! pointer on kcm allocator                */ 
76        page_t        * page;                  /*! pointer on the physical page descriptor */
77        uint32_t        count;                 /*! number of allocated blocks              */
78        uint32_t        busy;                  /*! page busy if non zero                   */
79        uint32_t        active;                /*! page active if non zero                 */
80}
81kcm_page_t;
82
83/****************************************************************************************
84 * This function initializes a generic Kernel Cache Manager.
85 ****************************************************************************************
86 * @ kcm      : pointer on KCM manager to initialize.
87 * @ type     : KCM allocator type.
88 ***************************************************************************************/
89void kcm_init( kcm_t    * kcm,
90                   uint32_t   type );
91
92/****************************************************************************************
93 * This function releases all memory allocated to a generic Kernel Cache Manager.
94 ****************************************************************************************
95 * @ kcm      : pointer on KCM manager to destroy.
96 ***************************************************************************************/
97void kcm_destroy( kcm_t  * kcm );
98
99/****************************************************************************************
100 * This function allocates one single object in a Kernel Cache Manager
101 * The object size must be smaller than one page size.
102 ****************************************************************************************
103 * @ kcm      :  pointer on the selected KCM allocator
104 * @ return pointer on allocated block if success / return NULL if failure
105 ***************************************************************************************/
106void * kcm_alloc( kcm_t * kcm );
107
108/****************************************************************************************
109 * This function releases a previouly allocated block containing one object.
110 ****************************************************************************************
111 * @ ptr   : local pointer on the allocated buffer.
112 ***************************************************************************************/
113void  kcm_free( void * ptr );
114
115/****************************************************************************************
116 * This function prints KCM allocator state (for debug only).
117 ****************************************************************************************
118 * @ kcm   : local pointer on the selected KCM allocator.
119 ***************************************************************************************/
120void kcm_print( kcm_t * kcm );
121
122
123
124#endif  /* _KCM_H_ */
Note: See TracBrowser for help on using the repository browser.