# Slab Allocation

_Peios Kernel / Internals / Memory management_

> Reference for Slab Allocation.

<a id="rst-slab-allocation"></a>

<a id="rst-functions-and-structures"></a>

## Functions and structures

<!-- SPDX-License-Identifier: GPL-2.0 -->


#### <a id="c-slab_folio"></a>`slab_folio()`

```c
slab_folio(s)
```

The folio allocated for a slab

**Parameters**

- `s`: The slab.

**Description**

Slabs are allocated as folios that contain the individual objects and are
using some fields in the first struct page of the folio - those fields are
now accessed by struct slab. It is occasionally necessary to convert back to
a folio in order to communicate with the rest of the mm.  Please use this
helper function instead of casting yourself, as the implementation may change
in the future.

#### <a id="c-page_slab"></a>`page_slab()`

```c
struct slab * page_slab(const struct page *page)
```

Converts from struct page to its slab.

**Parameters**

- `const struct page *page`: A page which may or may not belong to a slab.

**Return**

The slab which contains this page or NULL if the page does
not belong to a slab.  This includes pages returned from large kmalloc.

#### <a id="c-slab_page"></a>`slab_page()`

```c
slab_page(s)
```

The first struct page allocated for a slab

**Parameters**

- `s`: The slab.

**Description**

A convenience wrapper for converting slab to the first struct page of the
underlying folio, to communicate with code not yet converted to folio or
struct slab.



#### <a id="c-enum-slab_flags"></a>`enum slab_flags`

How the slab flags bits are used.

**Constants**

- `SL_locked`: Is locked with `slab_lock()`
- `SL_partial`: On the per-node partial list
- `SL_pfmemalloc`: Was allocated from PF_MEMALLOC reserves

**Description**

The slab flags share space with the page flags but some bits have
different interpretations.  The high bits are used for information
like zone/node/section.
