MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_slab_page_alloc

Function rt_slab_page_alloc

src/slab.c:216–246  ·  view source on GitHub ↗

* @brief Alloc memory size by page. * * @param m the slab memory management object. * * @param npages the number of pages. */

Source from the content-addressed store, hash-verified

214 * @param npages the number of pages.
215 */
216void *rt_slab_page_alloc(rt_slab_t m, rt_size_t npages)
217{
218 struct rt_slab_page *b, *n;
219 struct rt_slab_page **prev;
220 struct rt_slab *slab = (struct rt_slab *)m;
221
222 if (npages == 0)
223 return RT_NULL;
224
225 for (prev = &slab->page_list; (b = *prev) != RT_NULL; prev = &(b->next))
226 {
227 if (b->page > npages)
228 {
229 /* splite pages */
230 n = b + npages;
231 n->next = b->next;
232 n->page = b->page - npages;
233 *prev = n;
234 break;
235 }
236
237 if (b->page == npages)
238 {
239 /* this node fit, remove this node */
240 *prev = b->next;
241 break;
242 }
243 }
244
245 return b;
246}
247
248/**
249 * @brief Free memory by page.

Callers 3

rt_page_allocFunction · 0.85
rt_slab_initFunction · 0.85
rt_slab_allocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected