mem_cgroup_protected currently is both used to set effective low and min and return a mem_cgroup_protection based on the result. As a user, this can be a little unexpected: it appears to be a simple predicate function, if not for the big warning in the comment above about the order in which it must be executed. This change makes it so that we separate the state mutations from the actual protection checks, which makes it more obvious where we need to be careful mutating internal state, and where we are simply checking and don't need to worry about that. [mhocko@suse.com - don't check protection on root memcgs]
Showing the changes to include/linux (1 of 3 files). Show all
Unified · Split
| @@ -47,12 +47,6 @@ enum memcg_memory_event { · 46 unmodified lines | ||
| 47 | 47 | MEMCG_NR_MEMORY_EVENTS, |
| 48 | 48 | }; |
| 49 | 49 | |
| 50 | −enum mem_cgroup_protection { | |
| 51 | − MEMCG_PROT_NONE, | |
| 52 | − MEMCG_PROT_LOW, | |
| 53 | − MEMCG_PROT_MIN, | |
| 54 | −}; | |
| 55 | − | |
| 56 | 50 | struct mem_cgroup_reclaim_cookie { |
| 57 | 51 | pg_data_t *pgdat; |
| 58 | 52 | unsigned int generation; |
| @@ -405,8 +399,36 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *root, · 346 unmodified lines | ||
| 405 | 399 | READ_ONCE(memcg->memory.elow)); |
| 406 | 400 | } |
| 407 | 401 | |
| 408 | −enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, | |
| 409 | − struct mem_cgroup *memcg); | |
| 402 | +void mem_cgroup_calculate_protection(struct mem_cgroup *root, | |
| 403 | + struct mem_cgroup *memcg); | |
| 404 | + | |
| 405 | +static inline bool mem_cgroup_supports_protection(struct mem_cgroup *memcg) | |
| 406 | +{ | |
| 407 | + /* | |
| 408 | + * The root memcg doesn't account charges, and doesn't support | |
| 409 | + * protection. | |
| 410 | + */ | |
| 411 | + return !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg); | |
| 412 | + | |
| 413 | +} | |
| 414 | + | |
| 415 | +static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg) | |
| 416 | +{ | |
| 417 | + if (!mem_cgroup_supports_protection(memcg)) | |
| 418 | + return false; | |
| 419 | + | |
| 420 | + return READ_ONCE(memcg->memory.elow) >= | |
| 421 | + page_counter_read(&memcg->memory); | |
| 422 | +} | |
| 423 | + | |
| 424 | +static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg) | |
| 425 | +{ | |
| 426 | + if (!mem_cgroup_supports_protection(memcg)) | |
| 427 | + return false; | |
| 428 | + | |
| 429 | + return READ_ONCE(memcg->memory.emin) >= | |
| 430 | + page_counter_read(&memcg->memory); | |
| 431 | +} | |
| 410 | 432 | |
| 411 | 433 | int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask); |
| 412 | 434 | |
| @@ -935,10 +957,19 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *root, · 522 unmodified lines | ||
| 935 | 957 | return 0; |
| 936 | 958 | } |
| 937 | 959 | |
| 938 | −static inline enum mem_cgroup_protection mem_cgroup_protected( | |
| 939 | − struct mem_cgroup *root, struct mem_cgroup *memcg) | |
| 960 | +static inline void mem_cgroup_calculate_protection(struct mem_cgroup *root, | |
| 961 | + struct mem_cgroup *memcg) | |
| 940 | 962 | { |
| 941 | − return MEMCG_PROT_NONE; | |
| 963 | +} | |
| 964 | + | |
| 965 | +static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg) | |
| 966 | +{ | |
| 967 | + return false; | |
| 968 | +} | |
| 969 | + | |
| 970 | +static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg) | |
| 971 | +{ | |
| 972 | + return false; | |
| 942 | 973 | } |
| 943 | 974 | |
| 944 | 975 | static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm, |