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