Blame view

include/linux/page_counter.h 1.46 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
3e32cb2e0   Johannes Weiner   mm: memcontrol: l...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #ifndef _LINUX_PAGE_COUNTER_H
  #define _LINUX_PAGE_COUNTER_H
  
  #include <linux/atomic.h>
  #include <linux/kernel.h>
  #include <asm/page.h>
  
  struct page_counter {
  	atomic_long_t count;
  	unsigned long limit;
  	struct page_counter *parent;
  
  	/* legacy */
  	unsigned long watermark;
  	unsigned long failcnt;
  };
  
  #if BITS_PER_LONG == 32
  #define PAGE_COUNTER_MAX LONG_MAX
  #else
  #define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE)
  #endif
  
  static inline void page_counter_init(struct page_counter *counter,
  				     struct page_counter *parent)
  {
  	atomic_long_set(&counter->count, 0);
  	counter->limit = PAGE_COUNTER_MAX;
  	counter->parent = parent;
  }
  
  static inline unsigned long page_counter_read(struct page_counter *counter)
  {
  	return atomic_long_read(&counter->count);
  }
64f219938   Johannes Weiner   mm: memcontrol: r...
37
  void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages);
3e32cb2e0   Johannes Weiner   mm: memcontrol: l...
38
  void page_counter_charge(struct page_counter *counter, unsigned long nr_pages);
6071ca520   Johannes Weiner   mm: page_counter:...
39
40
41
  bool page_counter_try_charge(struct page_counter *counter,
  			     unsigned long nr_pages,
  			     struct page_counter **fail);
64f219938   Johannes Weiner   mm: memcontrol: r...
42
  void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
3e32cb2e0   Johannes Weiner   mm: memcontrol: l...
43
  int page_counter_limit(struct page_counter *counter, unsigned long limit);
650c5e565   Johannes Weiner   mm: page_counter:...
44
45
  int page_counter_memparse(const char *buf, const char *max,
  			  unsigned long *nr_pages);
3e32cb2e0   Johannes Weiner   mm: memcontrol: l...
46
47
48
49
50
51
52
  
  static inline void page_counter_reset_watermark(struct page_counter *counter)
  {
  	counter->watermark = page_counter_read(counter);
  }
  
  #endif /* _LINUX_PAGE_COUNTER_H */