xref: /dflybsd-src/sys/dev/drm/include/linux/swap.h (revision f0bba3d1dd5ba7adfae61269b5424d4ad443ab97)
13a690f1eSFrançois Tigeot /*
2*f0bba3d1SFrançois Tigeot  * Copyright (c) 2015-2018 François Tigeot <ftigeot@wolfpond.org>
33a690f1eSFrançois Tigeot  * All rights reserved.
43a690f1eSFrançois Tigeot  *
53a690f1eSFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
63a690f1eSFrançois Tigeot  * modification, are permitted provided that the following conditions
73a690f1eSFrançois Tigeot  * are met:
83a690f1eSFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
93a690f1eSFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
103a690f1eSFrançois Tigeot  *    disclaimer.
113a690f1eSFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
123a690f1eSFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
133a690f1eSFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
143a690f1eSFrançois Tigeot  *
153a690f1eSFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
163a690f1eSFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
173a690f1eSFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
183a690f1eSFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
193a690f1eSFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
203a690f1eSFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
213a690f1eSFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223a690f1eSFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
233a690f1eSFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
243a690f1eSFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253a690f1eSFrançois Tigeot  */
263a690f1eSFrançois Tigeot 
273a690f1eSFrançois Tigeot #ifndef _LINUX_SWAP_H_
283a690f1eSFrançois Tigeot #define _LINUX_SWAP_H_
293a690f1eSFrançois Tigeot 
30*f0bba3d1SFrançois Tigeot #include <linux/spinlock.h>
31*f0bba3d1SFrançois Tigeot #include <linux/mmzone.h>
32082a822aSFrançois Tigeot #include <linux/list.h>
33*f0bba3d1SFrançois Tigeot #include <linux/sched.h>
34*f0bba3d1SFrançois Tigeot #include <linux/fs.h>
35*f0bba3d1SFrançois Tigeot #include <linux/atomic.h>
368b1a6a38SFrançois Tigeot #include <asm/page.h>
378b1a6a38SFrançois Tigeot 
38*f0bba3d1SFrançois Tigeot #include <vm/vm_page2.h>
39*f0bba3d1SFrançois Tigeot 
mark_page_accessed(struct page * m)40*f0bba3d1SFrançois Tigeot static inline void mark_page_accessed(struct page *m)
413a690f1eSFrançois Tigeot {
42*f0bba3d1SFrançois Tigeot 	vm_page_flag_set((struct vm_page *)m, PG_REFERENCED);
433a690f1eSFrançois Tigeot }
443a690f1eSFrançois Tigeot 
455c64209cSFrançois Tigeot /* from vm/swap_pager.h */
465c64209cSFrançois Tigeot #include <sys/conf.h>
475c64209cSFrançois Tigeot extern int nswdev;
485c64209cSFrançois Tigeot extern struct swdevt *swdevt;
495c64209cSFrançois Tigeot 
505c64209cSFrançois Tigeot static inline long
get_nr_swap_pages(void)515c64209cSFrançois Tigeot get_nr_swap_pages(void)
525c64209cSFrançois Tigeot {
535c64209cSFrançois Tigeot 	int n;
545c64209cSFrançois Tigeot 	struct swdevt *sp;
555c64209cSFrançois Tigeot 	long total_pages = 0;
565c64209cSFrançois Tigeot 	long used_pages = 0;
575c64209cSFrançois Tigeot 
585c64209cSFrançois Tigeot 	for (n = 0; n < nswdev; n++) {
595c64209cSFrançois Tigeot 		sp = &swdevt[n];
605c64209cSFrançois Tigeot 
615c64209cSFrançois Tigeot 		total_pages += sp->sw_nblks;
625c64209cSFrançois Tigeot 		used_pages  += sp->sw_nused;
635c64209cSFrançois Tigeot 	}
645c64209cSFrançois Tigeot 
655c64209cSFrançois Tigeot 	return (total_pages - used_pages);
665c64209cSFrançois Tigeot }
675c64209cSFrançois Tigeot 
683a690f1eSFrançois Tigeot #endif	/* _LINUX_SWAP_H_ */
69