]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/page_counter.h
ACPI: fix acpi_find_child_device() invocation in acpi_preset_companion()
[mirror_ubuntu-bionic-kernel.git] / include / linux / page_counter.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
3e32cb2e
JW
2#ifndef _LINUX_PAGE_COUNTER_H
3#define _LINUX_PAGE_COUNTER_H
4
5#include <linux/atomic.h>
6#include <linux/kernel.h>
7#include <asm/page.h>
8
9struct page_counter {
10 atomic_long_t count;
11 unsigned long limit;
12 struct page_counter *parent;
13
14 /* legacy */
15 unsigned long watermark;
16 unsigned long failcnt;
17};
18
19#if BITS_PER_LONG == 32
20#define PAGE_COUNTER_MAX LONG_MAX
21#else
22#define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE)
23#endif
24
25static inline void page_counter_init(struct page_counter *counter,
26 struct page_counter *parent)
27{
28 atomic_long_set(&counter->count, 0);
29 counter->limit = PAGE_COUNTER_MAX;
30 counter->parent = parent;
31}
32
33static inline unsigned long page_counter_read(struct page_counter *counter)
34{
35 return atomic_long_read(&counter->count);
36}
37
64f21993 38void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages);
3e32cb2e 39void page_counter_charge(struct page_counter *counter, unsigned long nr_pages);
6071ca52
JW
40bool page_counter_try_charge(struct page_counter *counter,
41 unsigned long nr_pages,
42 struct page_counter **fail);
64f21993 43void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
3e32cb2e 44int page_counter_limit(struct page_counter *counter, unsigned long limit);
650c5e56
JW
45int page_counter_memparse(const char *buf, const char *max,
46 unsigned long *nr_pages);
3e32cb2e
JW
47
48static inline void page_counter_reset_watermark(struct page_counter *counter)
49{
50 counter->watermark = page_counter_read(counter);
51}
52
53#endif /* _LINUX_PAGE_COUNTER_H */