[PATCH] afs: Fix double add page to memcg when afs_readpages
Zhang Xiaoxu
zhangxiaoxu5 at huawei.com
Mon Jun 22 07:15:01 EDT 2020
Since commit 3fea5a499d57 ("mm: memcontrol: convert page cache to a new
mem_cgroup_charge() API") not uncharge the page, the page maybe double
add to memcg, then VM_BUG_ON_PAGE in commit_charge because the page's
memcg not NULL.
So, if add page cache failed, stop the read pages and let caller to
free the pages.
Reported-by: Hulk Robot <hulkci at huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5 at huawei.com>
---
fs/afs/file.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/fs/afs/file.c b/fs/afs/file.c
index 6f6ed1605cfe..aea73e9520d1 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -448,7 +448,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
struct page *first, *page;
struct key *key = afs_file_key(file);
pgoff_t index;
- int ret, n, i;
+ int ret, n, i, err;
/* Count the number of contiguous pages at the front of the list. Note
* that the list goes prev-wards rather than next-wards.
@@ -488,8 +488,9 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
page = lru_to_page(pages);
list_del(&page->lru);
index = page->index;
- if (add_to_page_cache_lru(page, mapping, index,
- readahead_gfp_mask(mapping))) {
+ err = add_to_page_cache_lru(page, mapping, index,
+ readahead_gfp_mask(mapping));
+ if (err) {
#ifdef CONFIG_AFS_FSCACHE
fscache_uncache_page(vnode->cache, page);
#endif
@@ -503,7 +504,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
if (req->nr_pages == 0) {
kfree(req);
- return 0;
+ return err;
}
ret = afs_fetch_data(vnode, key, req);
@@ -512,7 +513,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
task_io_account_read(PAGE_SIZE * req->nr_pages);
afs_put_read(req);
- return 0;
+ return err;
error:
if (ret == -ENOENT) {
--
2.25.4
More information about the linux-afs
mailing list