xref: /freebsd/sys/compat/linuxkpi/common/include/linux/swap.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1c3f4f28cSBen Widawsky /*-
2c3f4f28cSBen Widawsky  * Copyright (c) 2018 Intel Corporation
3c3f4f28cSBen Widawsky  *
4c3f4f28cSBen Widawsky  * Redistribution and use in source and binary forms, with or without
5c3f4f28cSBen Widawsky  * modification, are permitted provided that the following conditions are
6c3f4f28cSBen Widawsky  * met:
7c3f4f28cSBen Widawsky  * 1. Redistributions of source code must retain the above copyright
8c3f4f28cSBen Widawsky  *    notice, this list of conditions and the following disclaimer.
9c3f4f28cSBen Widawsky  * 2. Redistributions in binary form must reproduce the above copyright
10c3f4f28cSBen Widawsky  *    notice, this list of conditions and the following disclaimer in
11c3f4f28cSBen Widawsky  *    the documentation and/or other materials provided with the
12c3f4f28cSBen Widawsky  *    distribution.
13c3f4f28cSBen Widawsky  *
14c3f4f28cSBen Widawsky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15c3f4f28cSBen Widawsky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16c3f4f28cSBen Widawsky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17c3f4f28cSBen Widawsky  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18c3f4f28cSBen Widawsky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c3f4f28cSBen Widawsky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20c3f4f28cSBen Widawsky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21c3f4f28cSBen Widawsky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22c3f4f28cSBen Widawsky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23c3f4f28cSBen Widawsky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24c3f4f28cSBen Widawsky  * SUCH DAMAGE.
25c3f4f28cSBen Widawsky  */
26c3f4f28cSBen Widawsky 
27307f78f3SVladimir Kondratyev #ifndef	_LINUXKPI_LINUX_SWAP_H_
28307f78f3SVladimir Kondratyev #define	_LINUXKPI_LINUX_SWAP_H_
29c3f4f28cSBen Widawsky 
30*6d3d5653SEmmanuel Vadot #include <sys/param.h>
31*6d3d5653SEmmanuel Vadot #include <sys/domainset.h>
32*6d3d5653SEmmanuel Vadot #include <sys/queue.h>
33*6d3d5653SEmmanuel Vadot #include <sys/proc.h>
34*6d3d5653SEmmanuel Vadot #include <sys/pcpu.h>
35*6d3d5653SEmmanuel Vadot 
36*6d3d5653SEmmanuel Vadot #include <vm/vm.h>
37c3f4f28cSBen Widawsky #include <vm/swap_pager.h>
38c3f4f28cSBen Widawsky #include <vm/vm_pageout.h>
39c3f4f28cSBen Widawsky 
40c3f4f28cSBen Widawsky static inline long
get_nr_swap_pages(void)41c3f4f28cSBen Widawsky get_nr_swap_pages(void)
42c3f4f28cSBen Widawsky {
43c3f4f28cSBen Widawsky 	int i, j;
44c3f4f28cSBen Widawsky 
45c3f4f28cSBen Widawsky 	/* NB: This could be done cheaply by obtaining swap_total directly */
46c3f4f28cSBen Widawsky 	swap_pager_status(&i, &j);
47c3f4f28cSBen Widawsky 	return i - j;
48c3f4f28cSBen Widawsky }
49c3f4f28cSBen Widawsky 
50c3f4f28cSBen Widawsky static inline int
current_is_kswapd(void)51c3f4f28cSBen Widawsky current_is_kswapd(void)
52c3f4f28cSBen Widawsky {
53f82dd310SBen Widawsky 
54f82dd310SBen Widawsky 	return (curproc == pageproc);
55c3f4f28cSBen Widawsky }
56c3f4f28cSBen Widawsky 
57c3f4f28cSBen Widawsky #endif
58