History

mm: memcontrol: convert page cache to a new mem_cgroup_charge() API

The try/commit/cancel protocol that memcg uses dates back to when pages used to be uncharged upon removal from the page cache, and thus couldn't be committed before the insertion had succeeded. Nowadays, pages are uncharged when they are physically freed; it doesn't matter whether the insertion was successful or not. For the page cache, the transaction dance has become unnecessary. Introduce a mem_cgroup_charge() function that simply charges a newly allocated page to a cgroup and sets up page->mem_cgroup in one single step. If the insertion fails, the caller doesn't have to do anything but free/put the page. Then switch the page cache over to this new API. Subsequent patches will also convert anon pages, but it needs a bit more prep work. Right now, memcg depends on page->mapping being already set up at the time of charging, so that it can maintain its own MEMCG_CACHE and MEMCG_RSS counters. For anon, page->mapping is set under the same pte lock under which the page is publishd, so a single charge point that can block doesn't work there just yet. The following prep patches will replace the private memcg counters with the generic vmstat counters, thus removing the page->mapping dependency, then complete the transition to the new single-point charge API and delete the old transactional scheme. v2: leave shmem swapcache when charging fails to avoid double IO (Joonsoo) v3: rebase on preceeding shmem simplification patch

Johannes Weiner committed 6 years ago

Commit 3fea5a41 parent 6caa6a04 files · +77 −59Browse files

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

Unified · Split

include/linux/memcontrol.h+10−0
@@ -365,6 +365,10 @@ int mem_cgroup_try_charge_delay(struct page *page, struct mm_struct *mm, · 364 unmodified lines
365void mem_cgroup_commit_charge(struct page *page, struct mem_cgroup *memcg,365void mem_cgroup_commit_charge(struct page *page, struct mem_cgroup *memcg,
366 bool lrucare);366 bool lrucare);
367void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg);367void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg);
368
369int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask,
370 bool lrucare);
371
368void mem_cgroup_uncharge(struct page *page);372void mem_cgroup_uncharge(struct page *page);
369void mem_cgroup_uncharge_list(struct list_head *page_list);373void mem_cgroup_uncharge_list(struct list_head *page_list);
370 374
@@ -872,6 +876,12 @@ static inline void mem_cgroup_cancel_charge(struct page *page, · 501 unmodified lines
872{876{
873}877}
874 878
879static inline int mem_cgroup_charge(struct page *page, struct mm_struct *mm,
880 gfp_t gfp_mask, bool lrucare)
881{
882 return 0;
883}
884
875static inline void mem_cgroup_uncharge(struct page *page)885static inline void mem_cgroup_uncharge(struct page *page)
876{886{
877}887}