]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/page_counter.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_PAGE_COUNTER_H
3 #define _LINUX_PAGE_COUNTER_H
5 #include <linux/atomic.h>
6 #include <linux/kernel.h>
12 struct page_counter
*parent
;
15 unsigned long watermark
;
16 unsigned long failcnt
;
19 #if BITS_PER_LONG == 32
20 #define PAGE_COUNTER_MAX LONG_MAX
22 #define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE)
25 static inline void page_counter_init(struct page_counter
*counter
,
26 struct page_counter
*parent
)
28 atomic_long_set(&counter
->count
, 0);
29 counter
->limit
= PAGE_COUNTER_MAX
;
30 counter
->parent
= parent
;
33 static inline unsigned long page_counter_read(struct page_counter
*counter
)
35 return atomic_long_read(&counter
->count
);
38 void page_counter_cancel(struct page_counter
*counter
, unsigned long nr_pages
);
39 void page_counter_charge(struct page_counter
*counter
, unsigned long nr_pages
);
40 bool page_counter_try_charge(struct page_counter
*counter
,
41 unsigned long nr_pages
,
42 struct page_counter
**fail
);
43 void page_counter_uncharge(struct page_counter
*counter
, unsigned long nr_pages
);
44 int page_counter_limit(struct page_counter
*counter
, unsigned long limit
);
45 int page_counter_memparse(const char *buf
, const char *max
,
46 unsigned long *nr_pages
);
48 static inline void page_counter_reset_watermark(struct page_counter
*counter
)
50 counter
->watermark
= page_counter_read(counter
);
53 #endif /* _LINUX_PAGE_COUNTER_H */