Home | History | Annotate | Line # | Download | only in uvm
uvm_pglist.h revision 1.8.60.2
      1       1.8  uebayasi /*	$NetBSD: uvm_pglist.h,v 1.8.60.2 2020/04/21 18:42:46 martin Exp $	*/
      2       1.1       mrg 
      3       1.1       mrg /*-
      4  1.8.60.1    martin  * 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.8.60.1    martin  * 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.8.60.1    martin #include <sys/param.h>
     36  1.8.60.1    martin 
     37       1.1       mrg /*
     38       1.1       mrg  * This defines the type of a page queue, e.g. active list, inactive
     39       1.1       mrg  * list, etc.
     40       1.1       mrg  */
     41       1.8  uebayasi struct vm_page;
     42       1.4       chs TAILQ_HEAD(pglist, vm_page);
     43       1.7        ad LIST_HEAD(pgflist, vm_page);
     44       1.1       mrg 
     45       1.1       mrg /*
     46  1.8.60.1    martin  * The global uvm.page_free list (uvm_page.c, uvm_pglist.c).  Free pages are
     47  1.8.60.1    martin  * stored according to freelist, bucket, and cache colour.
     48  1.8.60.1    martin  *
     49  1.8.60.1    martin  * pglist = &uvm.page_free[freelist].pgfl_buckets[bucket].pgb_color[color];
     50  1.8.60.1    martin  *
     51  1.8.60.1    martin  * Freelists provide a priority ordering of pages for allocation, based upon
     52  1.8.60.2    martin  * how valuable they are for special uses (e.g.  device driver DMA).  MD
     53  1.8.60.2    martin  * code decides the number and structure of these.  They are always arranged
     54  1.8.60.2    martin  * in descending order of allocation priority.
     55  1.8.60.1    martin  *
     56  1.8.60.1    martin  * Pages are then grouped in buckets according to some common factor, for
     57  1.8.60.1    martin  * example L2/L3 cache locality.  Each bucket has its own lock, and the
     58  1.8.60.1    martin  * locks are shared among freelists for the same numbered buckets.
     59  1.8.60.1    martin  *
     60  1.8.60.1    martin  * Inside each bucket, pages are further distributed by cache color.
     61  1.8.60.1    martin  *
     62  1.8.60.1    martin  * We want these data structures to occupy as few cache lines as possible,
     63  1.8.60.1    martin  * as they will be highly contended.
     64       1.1       mrg  */
     65       1.2   thorpej struct pgflbucket {
     66  1.8.60.1    martin 	uintptr_t	pgb_nfree;	/* total # free pages, all colors */
     67  1.8.60.1    martin 	struct pgflist	pgb_colors[1];	/* variable size array */
     68       1.2   thorpej };
     69       1.2   thorpej 
     70  1.8.60.1    martin /*
     71  1.8.60.1    martin  * 8 buckets should be enough to cover most all current x86 systems (2019),
     72  1.8.60.1    martin  * given the way package/core/smt IDs are structured on x86.  For systems
     73  1.8.60.1    martin  * that report high package counts despite having a single physical CPU
     74  1.8.60.2    martin  * package (e.g. Ampere eMAG) a little bit of sharing isn't going to hurt.
     75  1.8.60.1    martin  */
     76  1.8.60.1    martin #define	PGFL_MAX_BUCKETS	8
     77       1.1       mrg struct pgfreelist {
     78  1.8.60.1    martin 	struct pgflbucket	*pgfl_buckets[PGFL_MAX_BUCKETS];
     79  1.8.60.1    martin };
     80  1.8.60.1    martin 
     81  1.8.60.1    martin /*
     82  1.8.60.1    martin  * Lock for each bucket.
     83  1.8.60.1    martin  */
     84  1.8.60.1    martin union uvm_freelist_lock {
     85  1.8.60.1    martin         kmutex_t        lock;
     86  1.8.60.1    martin         uint8_t         padding[COHERENCY_UNIT];
     87       1.1       mrg };
     88  1.8.60.1    martin extern union uvm_freelist_lock	uvm_freelist_locks[PGFL_MAX_BUCKETS];
     89       1.1       mrg 
     90       1.5       chs #endif /* _UVM_UVM_PGLIST_H_ */
     91