~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/page_counter.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_PAGE_COUNTER_H
  3 #define _LINUX_PAGE_COUNTER_H
  4 
  5 #include <linux/atomic.h>
  6 #include <linux/cache.h>
  7 #include <linux/limits.h>
  8 #include <asm/page.h>
  9 
 10 struct page_counter {
 11         /*
 12          * Make sure 'usage' does not share cacheline with any other field. The
 13          * memcg->memory.usage is a hot member of struct mem_cgroup.
 14          */
 15         atomic_long_t usage;
 16         CACHELINE_PADDING(_pad1_);
 17 
 18         /* effective memory.min and memory.min usage tracking */
 19         unsigned long emin;
 20         atomic_long_t min_usage;
 21         atomic_long_t children_min_usage;
 22 
 23         /* effective memory.low and memory.low usage tracking */
 24         unsigned long elow;
 25         atomic_long_t low_usage;
 26         atomic_long_t children_low_usage;
 27 
 28         unsigned long watermark;
 29         unsigned long failcnt;
 30 
 31         /* Keep all the read most fields in a separete cacheline. */
 32         CACHELINE_PADDING(_pad2_);
 33 
 34         unsigned long min;
 35         unsigned long low;
 36         unsigned long high;
 37         unsigned long max;
 38         struct page_counter *parent;
 39 } ____cacheline_internodealigned_in_smp;
 40 
 41 #if BITS_PER_LONG == 32
 42 #define PAGE_COUNTER_MAX LONG_MAX
 43 #else
 44 #define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE)
 45 #endif
 46 
 47 static inline void page_counter_init(struct page_counter *counter,
 48                                      struct page_counter *parent)
 49 {
 50         atomic_long_set(&counter->usage, 0);
 51         counter->max = PAGE_COUNTER_MAX;
 52         counter->parent = parent;
 53 }
 54 
 55 static inline unsigned long page_counter_read(struct page_counter *counter)
 56 {
 57         return atomic_long_read(&counter->usage);
 58 }
 59 
 60 void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages);
 61 void page_counter_charge(struct page_counter *counter, unsigned long nr_pages);
 62 bool page_counter_try_charge(struct page_counter *counter,
 63                              unsigned long nr_pages,
 64                              struct page_counter **fail);
 65 void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
 66 void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages);
 67 void page_counter_set_low(struct page_counter *counter, unsigned long nr_pages);
 68 
 69 static inline void page_counter_set_high(struct page_counter *counter,
 70                                          unsigned long nr_pages)
 71 {
 72         WRITE_ONCE(counter->high, nr_pages);
 73 }
 74 
 75 int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages);
 76 int page_counter_memparse(const char *buf, const char *max,
 77                           unsigned long *nr_pages);
 78 
 79 static inline void page_counter_reset_watermark(struct page_counter *counter)
 80 {
 81         counter->watermark = page_counter_read(counter);
 82 }
 83 
 84 void page_counter_calculate_protection(struct page_counter *root,
 85                                        struct page_counter *counter,
 86                                        bool recursive_protection);
 87 
 88 #endif /* _LINUX_PAGE_COUNTER_H */
 89 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php