History

mm, memcg: decouple e{low,min} state mutations from protection checks

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]

Chris Down committed 6 years ago

Commit 45c7f7e1 parent 22f74963 files · +53 −45Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/memcontrol.h+42−11
@@ -47,12 +47,6 @@ enum memcg_memory_event { · 46 unmodified lines
47 MEMCG_NR_MEMORY_EVENTS,47 MEMCG_NR_MEMORY_EVENTS,
48};48};
49 49
50enum mem_cgroup_protection {
51 MEMCG_PROT_NONE,
52 MEMCG_PROT_LOW,
53 MEMCG_PROT_MIN,
54};
55
56struct mem_cgroup_reclaim_cookie {50struct mem_cgroup_reclaim_cookie {
57 pg_data_t *pgdat;51 pg_data_t *pgdat;
58 unsigned int generation;52 unsigned int generation;
@@ -405,8 +399,36 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *root, · 346 unmodified lines
405 READ_ONCE(memcg->memory.elow));399 READ_ONCE(memcg->memory.elow));
406}400}
407 401
408enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,402void mem_cgroup_calculate_protection(struct mem_cgroup *root,
409 struct mem_cgroup *memcg);403 struct mem_cgroup *memcg);
404
405static 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
415static 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
424static 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
411int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask);433int 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 return 0;957 return 0;
936}958}
937 959
938static inline enum mem_cgroup_protection mem_cgroup_protected(960static inline void mem_cgroup_calculate_protection(struct mem_cgroup *root,
939 struct mem_cgroup *root, struct mem_cgroup *memcg)961 struct mem_cgroup *memcg)
940{962{
941 return MEMCG_PROT_NONE;963}
964
965static inline bool mem_cgroup_below_low(struct mem_cgroup *memcg)
966{
967 return false;
968}
969
970static inline bool mem_cgroup_below_min(struct mem_cgroup *memcg)
971{
972 return false;
942}973}
943 974
944static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,975static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,