uvm_pglist.h revision 1.9
1/*	$NetBSD: uvm_pglist.h,v 1.9 2019/12/27 12:51:57 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/*
36 * This defines the type of a page queue, e.g. active list, inactive
37 * list, etc.
38 */
39struct vm_page;
40TAILQ_HEAD(pglist, vm_page);
41LIST_HEAD(pgflist, vm_page);
42
43/*
44 * The global uvm.page_free list (uvm_page.c, uvm_pglist.c).  Free pages are
45 * stored according to freelist, bucket, and cache colour.
46 *
47 * pglist = &uvm.page_free[freelist].pgfl_buckets[bucket].pgb_color[color];
48 *
49 * Freelists provide a priority ordering of pages for allocation, based upon
50 * how valuable they are for special uses (e.g. device driver DMA).
51 *
52 * Pages are then grouped in buckets according to some common factor, for
53 * example L2/L3 cache locality.  Each bucket has its own lock, and the
54 * locks are shared among freelists for the same numbered buckets.
55 *
56 * Inside each bucket, pages are further distributed by cache color.
57 *
58 * We want these data structures to occupy as few cache lines as possible,
59 * as they will be highly contended.
60 */
61struct pgflbucket {
62	uintptr_t	pgb_nfree;	/* total # free pages, all colors */
63	struct pgflist	pgb_colors[1];	/* variable size array */
64};
65
66/*
67 * At the root, the freelists.  MD code decides the number and structure of
68 * these.  They are always arranged in descending order of allocation
69 * priority.
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 * in the least.
76 */
77#define	PGFL_MAX_BUCKETS	8
78struct pgfreelist {
79	struct pgflbucket	*pgfl_buckets[PGFL_MAX_BUCKETS];
80};
81
82/*
83 * Lock for each bucket.
84 */
85union uvm_freelist_lock {
86        kmutex_t        lock;
87        uint8_t         padding[COHERENCY_UNIT];
88};
89extern union uvm_freelist_lock	uvm_freelist_locks[PGFL_MAX_BUCKETS];
90
91#endif /* _UVM_UVM_PGLIST_H_ */
92