1
0
Fork 0

percpu: update header to contain bitmap allocator explanation.

The other patches contain a lot of information, so adding this
information in a separate patch. It adds my copyright and a brief
explanation of how the bitmap allocator works. There is a minor typo as
well in the prior explanation so that is fixed.

Signed-off-by: Dennis Zhou <dennisszhou@gmail.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
hifive-unleashed-5.1
Dennis Zhou (Facebook) 2017-07-24 19:02:20 -04:00 committed by Tejun Heo
parent b4c2116cfa
commit 5e81ee3e6a
1 changed files with 17 additions and 13 deletions

View File

@ -4,6 +4,9 @@
* Copyright (C) 2009 SUSE Linux Products GmbH * Copyright (C) 2009 SUSE Linux Products GmbH
* Copyright (C) 2009 Tejun Heo <tj@kernel.org> * Copyright (C) 2009 Tejun Heo <tj@kernel.org>
* *
* Copyright (C) 2017 Facebook Inc.
* Copyright (C) 2017 Dennis Zhou <dennisszhou@gmail.com>
*
* This file is released under the GPLv2 license. * This file is released under the GPLv2 license.
* *
* The percpu allocator handles both static and dynamic areas. Percpu * The percpu allocator handles both static and dynamic areas. Percpu
@ -25,7 +28,7 @@
* *
* There is special consideration for the first chunk which must handle * There is special consideration for the first chunk which must handle
* the static percpu variables in the kernel image as allocation services * the static percpu variables in the kernel image as allocation services
* are not online yet. In short, the first chunk is structure like so: * are not online yet. In short, the first chunk is structured like so:
* *
* <Static | [Reserved] | Dynamic> * <Static | [Reserved] | Dynamic>
* *
@ -34,19 +37,20 @@
* percpu variables from kernel modules. Finally, the dynamic section * percpu variables from kernel modules. Finally, the dynamic section
* takes care of normal allocations. * takes care of normal allocations.
* *
* Allocation state in each chunk is kept using an array of integers * The allocator organizes chunks into lists according to free size and
* on chunk->map. A positive value in the map represents a free * tries to allocate from the fullest chunk first. Each chunk is managed
* region and negative allocated. Allocation inside a chunk is done * by a bitmap with metadata blocks. The allocation map is updated on
* by scanning this map sequentially and serving the first matching * every allocation and free to reflect the current state while the boundary
* entry. This is mostly copied from the percpu_modalloc() allocator. * map is only updated on allocation. Each metadata block contains
* Chunks can be determined from the address using the index field * information to help mitigate the need to iterate over large portions
* in the page struct. The index field contains a pointer to the chunk. * of the bitmap. The reverse mapping from page to chunk is stored in
* the page's index. Lastly, units are lazily backed and grow in unison.
* *
* These chunks are organized into lists according to free_size and * There is a unique conversion that goes on here between bytes and bits.
* tries to allocate from the fullest chunk first. Each chunk maintains * Each bit represents a fragment of size PCPU_MIN_ALLOC_SIZE. The chunk
* a maximum contiguous area size hint which is guaranteed to be equal * tracks the number of pages it is responsible for in nr_pages. Helper
* to or larger than the maximum contiguous area in the chunk. This * functions are used to convert from between the bytes, bits, and blocks.
* helps prevent the allocator from iterating over chunks unnecessarily. * All hints are managed in bits unless explicitly stated.
* *
* To use this allocator, arch code should do the following: * To use this allocator, arch code should do the following:
* *