@@ -764,8 +764,7 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
__count_vm_events(KSWAPD_INODESTEAL, reap);
else
__count_vm_events(PGINODESTEAL, reap);
- if (current->reclaim_state)
- current->reclaim_state->reclaimed_slab += reap;
+ current_reclaim_account_pages(reap);
}
iput(inode);
spin_lock(lru_lock);
@@ -324,9 +324,7 @@ xfs_buf_free(
__free_page(page);
}
- if (current->reclaim_state)
- current->reclaim_state->reclaimed_slab +=
- bp->b_page_count;
+ current_reclaim_account_pages(bp->b_page_count);
} else if (bp->b_flags & _XBF_KMEM)
kmem_free(bp->b_addr);
_xfs_buf_free_pages(bp);
@@ -126,12 +126,28 @@ union swap_header {
/*
* current->reclaim_state points to one of these when a task is running
- * memory reclaim
+ * memory reclaim. It is typically used by shrinkers to return reclaim
+ * information back to the main vmscan loop.
*/
struct reclaim_state {
- unsigned long reclaimed_slab;
+ unsigned long reclaimed_pages; /* pages freed by shrinkers */
};
+/*
+ * When code frees a page that may be run from a memory reclaim context, it
+ * needs to account for the pages it frees so memory reclaim can track them.
+ * Slab memory that is freed is accounted via this mechanism, so this is not
+ * necessary for slab or heap memory being freed. However, if the object being
+ * freed frees pages directly, then those pages should be accounted as well when
+ * in memory reclaim. This helper function takes care accounting for the pages
+ * being reclaimed when it is required.
+ */
+static inline void current_reclaim_account_pages(int nr_pages)
+{
+ if (current->reclaim_state)
+ current->reclaim_state->reclaimed_pages += nr_pages;
+}
+
#ifdef __KERNEL__
struct address_space;
@@ -1395,8 +1395,7 @@ static void kmem_freepages(struct kmem_cache *cachep, struct page *page)
page_mapcount_reset(page);
page->mapping = NULL;
- if (current->reclaim_state)
- current->reclaim_state->reclaimed_slab += 1 << order;
+ current_reclaim_account_pages(1 << order);
uncharge_slab_page(page, order, cachep);
__free_pages(page, order);
}
@@ -211,9 +211,7 @@ static void slob_free_pages(void *b, int order)
{
struct page *sp = virt_to_page(b);
- if (current->reclaim_state)
- current->reclaim_state->reclaimed_slab += 1 << order;
-
+ current_reclaim_account_pages(1 << order);
mod_node_page_state(page_pgdat(sp), NR_SLAB_UNRECLAIMABLE,
-(1 << order));
__free_pages(sp, order);
@@ -1746,8 +1746,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
__ClearPageSlab(page);
page->mapping = NULL;
- if (current->reclaim_state)
- current->reclaim_state->reclaimed_slab += pages;
+ current_reclaim_account_pages(pages);
uncharge_slab_page(page, order, s);
__free_pages(page, order);
}
@@ -2872,8 +2872,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
} while ((memcg = mem_cgroup_iter(root, memcg, NULL)));
if (reclaim_state) {
- sc->nr_reclaimed += reclaim_state->reclaimed_slab;
- reclaim_state->reclaimed_slab = 0;
+ sc->nr_reclaimed += reclaim_state->reclaimed_pages;
+ reclaim_state->reclaimed_pages = 0;
}
/* Record the subtree's reclaim efficiency */