From fc4f0ddddb50da826b527b7791028a67539f34c8 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Thu, 22 Sep 2016 10:13:31 -0700 Subject: gpu: nvgpu: SLAB allocation for page allocator Add the ability to do "SLAB" allocation in the page allocator. This is generally useful since the allocator manages 64K pages but often we only need 4k chunks (for example when allocating memory for page table entries). Bug 1799159 JIRA DNVGPU-100 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1225322 (cherry picked from commit 299a5639243e44be504391d9155b4ae17d914aa2) Change-Id: Ib3a8558d40ba16bd3a413f4fd38b146beaa3c66b Reviewed-on: http://git-master/r/1227924 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/gk20a/page_allocator_priv.h | 69 +++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/page_allocator_priv.h') diff --git a/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h b/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h index 3d4e3c43..7d7f43c2 100644 --- a/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h +++ b/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h @@ -19,12 +19,63 @@ #include #include -#include #include "gk20a_allocator.h" struct gk20a_allocator; +/* + * This allocator implements the ability to do SLAB style allocation since the + * GPU has two page sizes available - 4k and 64k/128k. When the default + * granularity is the large page size (64k/128k) small allocations become very + * space inefficient. This is most notable in PDE and PTE blocks which are 4k + * in size. + * + * Thus we need the ability to suballocate in 64k pages. The way we do this for + * the GPU is as follows. We have several buckets for sub-64K allocations: + * + * B0 - 4k + * B1 - 8k + * B3 - 16k + * B4 - 32k + * B5 - 64k (for when large pages are 128k) + * + * When an allocation comes in for less than the large page size (from now on + * assumed to be 64k) the allocation is satisfied by one of the buckets. + */ +struct page_alloc_slab { + struct list_head empty; + struct list_head partial; + struct list_head full; + + int nr_empty; + int nr_partial; + int nr_full; + + u32 slab_size; +}; + +enum slab_page_state { + SP_EMPTY, + SP_PARTIAL, + SP_FULL, + SP_NONE +}; + +struct page_alloc_slab_page { + unsigned long bitmap; + u64 page_addr; + u32 slab_size; + + u32 nr_objects; + u32 nr_objects_alloced; + + enum slab_page_state state; + + struct page_alloc_slab *owner; + struct list_head list_entry; +}; + struct page_alloc_chunk { struct list_head list_entry; @@ -34,7 +85,7 @@ struct page_alloc_chunk { /* * Struct to handle internal management of page allocation. It holds a list - * of the chunks of page that make up the overall allocation - much like a + * of the chunks of pages that make up the overall allocation - much like a * scatter gather table. */ struct gk20a_page_alloc { @@ -44,13 +95,20 @@ struct gk20a_page_alloc { u64 length; /* - * Only useful for the RB tree - since the alloc will have discontiguous + * Only useful for the RB tree - since the alloc may have discontiguous * pages the base is essentially irrelevant except for the fact that it * is guarenteed to be unique. */ u64 base; struct rb_node tree_entry; + + /* + * Set if this is a slab alloc. Points back to the slab page that owns + * this particular allocation. nr_chunks will always be 1 if this is + * set. + */ + struct page_alloc_slab_page *slab_page; }; struct gk20a_page_allocator { @@ -73,6 +131,9 @@ struct gk20a_page_allocator { struct rb_root allocs; /* Outstanding allocations. */ + struct page_alloc_slab *slabs; + int nr_slabs; + u64 flags; /* @@ -82,6 +143,8 @@ struct gk20a_page_allocator { u64 nr_frees; u64 nr_fixed_allocs; u64 nr_fixed_frees; + u64 nr_slab_allocs; + u64 nr_slab_frees; u64 pages_alloced; u64 pages_freed; }; -- cgit v1.2.2