xref: /netbsd/sys/uvm/uvm_pglist.h (revision f1153f97)
1 /*	$NetBSD: uvm_pglist.h,v 1.11 2020/04/13 15:16:14 ad Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000, 2001, 2008, 2019 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe, and by Andrew Doran.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _UVM_UVM_PGLIST_H_
33 #define _UVM_UVM_PGLIST_H_
34 
35 #include <sys/param.h>
36 
37 /*
38  * This defines the type of a page queue, e.g. active list, inactive
39  * list, etc.
40  */
41 struct vm_page;
42 TAILQ_HEAD(pglist, vm_page);
43 LIST_HEAD(pgflist, vm_page);
44 
45 /*
46  * The global uvm.page_free list (uvm_page.c, uvm_pglist.c).  Free pages are
47  * stored according to freelist, bucket, and cache colour.
48  *
49  * pglist = &uvm.page_free[freelist].pgfl_buckets[bucket].pgb_color[color];
50  *
51  * Freelists provide a priority ordering of pages for allocation, based upon
52  * how valuable they are for special uses (e.g.  device driver DMA).  MD
53  * code decides the number and structure of these.  They are always arranged
54  * in descending order of allocation priority.
55  *
56  * Pages are then grouped in buckets according to some common factor, for
57  * example L2/L3 cache locality.  Each bucket has its own lock, and the
58  * locks are shared among freelists for the same numbered buckets.
59  *
60  * Inside each bucket, pages are further distributed by cache color.
61  *
62  * We want these data structures to occupy as few cache lines as possible,
63  * as they will be highly contended.
64  */
65 struct pgflbucket {
66 	uintptr_t	pgb_nfree;	/* total # free pages, all colors */
67 	struct pgflist	pgb_colors[1];	/* variable size array */
68 };
69 
70 /*
71  * 8 buckets should be enough to cover most all current x86 systems (2019),
72  * given the way package/core/smt IDs are structured on x86.  For systems
73  * that report high package counts despite having a single physical CPU
74  * package (e.g. Ampere eMAG) a little bit of sharing isn't going to hurt.
75  */
76 #define	PGFL_MAX_BUCKETS	8
77 struct pgfreelist {
78 	struct pgflbucket	*pgfl_buckets[PGFL_MAX_BUCKETS];
79 };
80 
81 /*
82  * Lock for each bucket.
83  */
84 union uvm_freelist_lock {
85         kmutex_t        lock;
86         uint8_t         padding[COHERENCY_UNIT];
87 };
88 extern union uvm_freelist_lock	uvm_freelist_locks[PGFL_MAX_BUCKETS];
89 
90 #endif /* _UVM_UVM_PGLIST_H_ */
91