page_counter.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _LINUX_PAGE_COUNTER_H
  2. #define _LINUX_PAGE_COUNTER_H
  3. #include <linux/atomic.h>
  4. #include <linux/kernel.h>
  5. #include <asm/page.h>
  6. struct page_counter {
  7. atomic_long_t count;
  8. unsigned long limit;
  9. struct page_counter *parent;
  10. /* legacy */
  11. unsigned long watermark;
  12. unsigned long failcnt;
  13. };
  14. #if BITS_PER_LONG == 32
  15. #define PAGE_COUNTER_MAX LONG_MAX
  16. #else
  17. #define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE)
  18. #endif
  19. static inline void page_counter_init(struct page_counter *counter,
  20. struct page_counter *parent)
  21. {
  22. atomic_long_set(&counter->count, 0);
  23. counter->limit = PAGE_COUNTER_MAX;
  24. counter->parent = parent;
  25. }
  26. static inline unsigned long page_counter_read(struct page_counter *counter)
  27. {
  28. return atomic_long_read(&counter->count);
  29. }
  30. void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages);
  31. void page_counter_charge(struct page_counter *counter, unsigned long nr_pages);
  32. bool page_counter_try_charge(struct page_counter *counter,
  33. unsigned long nr_pages,
  34. struct page_counter **fail);
  35. void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
  36. int page_counter_limit(struct page_counter *counter, unsigned long limit);
  37. int page_counter_memparse(const char *buf, const char *max,
  38. unsigned long *nr_pages);
  39. static inline void page_counter_reset_watermark(struct page_counter *counter)
  40. {
  41. counter->watermark = page_counter_read(counter);
  42. }
  43. #endif /* _LINUX_PAGE_COUNTER_H */