2014-04-03 23:47:51 +02:00
|
|
|
/*
|
|
|
|
* Workingset detection
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Red Hat, Inc., Johannes Weiner
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/memcontrol.h>
|
|
|
|
#include <linux/writeback.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/atomic.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Double CLOCK lists
|
|
|
|
*
|
|
|
|
* Per zone, two clock lists are maintained for file pages: the
|
|
|
|
* inactive and the active list. Freshly faulted pages start out at
|
|
|
|
* the head of the inactive list and page reclaim scans pages from the
|
|
|
|
* tail. Pages that are accessed multiple times on the inactive list
|
|
|
|
* are promoted to the active list, to protect them from reclaim,
|
|
|
|
* whereas active pages are demoted to the inactive list when the
|
|
|
|
* active list grows too big.
|
|
|
|
*
|
|
|
|
* fault ------------------------+
|
|
|
|
* |
|
|
|
|
* +--------------+ | +-------------+
|
|
|
|
* reclaim <- | inactive | <-+-- demotion | active | <--+
|
|
|
|
* +--------------+ +-------------+ |
|
|
|
|
* | |
|
|
|
|
* +-------------- promotion ------------------+
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Access frequency and refault distance
|
|
|
|
*
|
|
|
|
* A workload is thrashing when its pages are frequently used but they
|
|
|
|
* are evicted from the inactive list every time before another access
|
|
|
|
* would have promoted them to the active list.
|
|
|
|
*
|
|
|
|
* In cases where the average access distance between thrashing pages
|
|
|
|
* is bigger than the size of memory there is nothing that can be
|
|
|
|
* done - the thrashing set could never fit into memory under any
|
|
|
|
* circumstance.
|
|
|
|
*
|
|
|
|
* However, the average access distance could be bigger than the
|
|
|
|
* inactive list, yet smaller than the size of memory. In this case,
|
|
|
|
* the set could fit into memory if it weren't for the currently
|
|
|
|
* active pages - which may be used more, hopefully less frequently:
|
|
|
|
*
|
|
|
|
* +-memory available to cache-+
|
|
|
|
* | |
|
|
|
|
* +-inactive------+-active----+
|
|
|
|
* a b | c d e f g h i | J K L M N |
|
|
|
|
* +---------------+-----------+
|
|
|
|
*
|
|
|
|
* It is prohibitively expensive to accurately track access frequency
|
|
|
|
* of pages. But a reasonable approximation can be made to measure
|
|
|
|
* thrashing on the inactive list, after which refaulting pages can be
|
|
|
|
* activated optimistically to compete with the existing active pages.
|
|
|
|
*
|
|
|
|
* Approximating inactive page access frequency - Observations:
|
|
|
|
*
|
|
|
|
* 1. When a page is accessed for the first time, it is added to the
|
|
|
|
* head of the inactive list, slides every existing inactive page
|
|
|
|
* towards the tail by one slot, and pushes the current tail page
|
|
|
|
* out of memory.
|
|
|
|
*
|
|
|
|
* 2. When a page is accessed for the second time, it is promoted to
|
|
|
|
* the active list, shrinking the inactive list by one slot. This
|
|
|
|
* also slides all inactive pages that were faulted into the cache
|
|
|
|
* more recently than the activated page towards the tail of the
|
|
|
|
* inactive list.
|
|
|
|
*
|
|
|
|
* Thus:
|
|
|
|
*
|
|
|
|
* 1. The sum of evictions and activations between any two points in
|
|
|
|
* time indicate the minimum number of inactive pages accessed in
|
|
|
|
* between.
|
|
|
|
*
|
|
|
|
* 2. Moving one inactive page N page slots towards the tail of the
|
|
|
|
* list requires at least N inactive page accesses.
|
|
|
|
*
|
|
|
|
* Combining these:
|
|
|
|
*
|
|
|
|
* 1. When a page is finally evicted from memory, the number of
|
|
|
|
* inactive pages accessed while the page was in cache is at least
|
|
|
|
* the number of page slots on the inactive list.
|
|
|
|
*
|
|
|
|
* 2. In addition, measuring the sum of evictions and activations (E)
|
|
|
|
* at the time of a page's eviction, and comparing it to another
|
|
|
|
* reading (R) at the time the page faults back into memory tells
|
|
|
|
* the minimum number of accesses while the page was not cached.
|
|
|
|
* This is called the refault distance.
|
|
|
|
*
|
|
|
|
* Because the first access of the page was the fault and the second
|
|
|
|
* access the refault, we combine the in-cache distance with the
|
|
|
|
* out-of-cache distance to get the complete minimum access distance
|
|
|
|
* of this page:
|
|
|
|
*
|
|
|
|
* NR_inactive + (R - E)
|
|
|
|
*
|
|
|
|
* And knowing the minimum access distance of a page, we can easily
|
|
|
|
* tell if the page would be able to stay in cache assuming all page
|
|
|
|
* slots in the cache were available:
|
|
|
|
*
|
|
|
|
* NR_inactive + (R - E) <= NR_inactive + NR_active
|
|
|
|
*
|
|
|
|
* which can be further simplified to
|
|
|
|
*
|
|
|
|
* (R - E) <= NR_active
|
|
|
|
*
|
|
|
|
* Put into words, the refault distance (out-of-cache) can be seen as
|
|
|
|
* a deficit in inactive list space (in-cache). If the inactive list
|
|
|
|
* had (R - E) more page slots, the page would not have been evicted
|
|
|
|
* in between accesses, but activated instead. And on a full system,
|
|
|
|
* the only thing eating into inactive list space is active pages.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Activating refaulting pages
|
|
|
|
*
|
|
|
|
* All that is known about the active list is that the pages have been
|
|
|
|
* accessed more than once in the past. This means that at any given
|
|
|
|
* time there is actually a good chance that pages on the active list
|
|
|
|
* are no longer in active use.
|
|
|
|
*
|
|
|
|
* So when a refault distance of (R - E) is observed and there are at
|
|
|
|
* least (R - E) active pages, the refaulting page is activated
|
|
|
|
* optimistically in the hope that (R - E) active pages are actually
|
|
|
|
* used less frequently than the refaulting page - or even not used at
|
|
|
|
* all anymore.
|
|
|
|
*
|
|
|
|
* If this is wrong and demotion kicks in, the pages which are truly
|
|
|
|
* used more frequently will be reactivated while the less frequently
|
|
|
|
* used once will be evicted from memory.
|
|
|
|
*
|
|
|
|
* But if this is right, the stale pages will be pushed out of memory
|
|
|
|
* and the used pages get to stay in cache.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Implementation
|
|
|
|
*
|
|
|
|
* For each zone's file LRU lists, a counter for inactive evictions
|
|
|
|
* and activations is maintained (zone->inactive_age).
|
|
|
|
*
|
|
|
|
* On eviction, a snapshot of this counter (along with some bits to
|
|
|
|
* identify the zone) is stored in the now empty page cache radix tree
|
|
|
|
* slot of the evicted page. This is called a shadow entry.
|
|
|
|
*
|
|
|
|
* On cache misses for which there are shadow entries, an eligible
|
|
|
|
* refault distance will immediately activate the refaulting page.
|
|
|
|
*/
|
|
|
|
|
2016-03-15 22:57:07 +01:00
|
|
|
#define EVICTION_SHIFT (RADIX_TREE_EXCEPTIONAL_ENTRY + \
|
2016-03-15 22:57:16 +01:00
|
|
|
ZONES_SHIFT + NODES_SHIFT + \
|
|
|
|
MEM_CGROUP_ID_SHIFT)
|
2016-03-15 22:57:07 +01:00
|
|
|
#define EVICTION_MASK (~0UL >> EVICTION_SHIFT)
|
|
|
|
|
mm: workingset: eviction buckets for bigmem/lowbit machines
For per-cgroup thrash detection, we need to store the memcg ID inside
the radix tree cookie as well. However, on 32 bit that doesn't leave
enough bits for the eviction timestamp to cover the necessary range of
recently evicted pages. The radix tree entry would look like this:
[ RADIX_TREE_EXCEPTIONAL(2) | ZONEID(2) | MEMCGID(16) | EVICTION(12) ]
12 bits means 4096 pages, means 16M worth of recently evicted pages.
But refaults are actionable up to distances covering half of memory. To
not miss refaults, we have to stretch out the range at the cost of how
precisely we can tell when a page was evicted. This way we can shave
off lower bits from the eviction timestamp until the necessary range is
covered. E.g. grouping evictions into 1M buckets (256 pages) will
stretch the longest representable refault distance to 4G.
This patch implements eviction buckets that are automatically sized
according to the available bits and the necessary refault range, in
preparation for per-cgroup thrash detection.
The maximum actionable distance is currently half of memory, but to
support memory hotplug of up to 200% of boot-time memory, we size the
buckets to cover double the distance. Beyond that, thrashing won't be
detectable anymore.
During boot, the kernel will print out the exact parameters, like so:
[ 0.113929] workingset: timestamp_bits=12 max_order=18 bucket_order=6
In this example, there are 12 radix entry bits available for the
eviction timestamp, to cover a maximum distance of 2^18 pages (this is a
1G machine). Consequently, evictions must be grouped into buckets of
2^6 pages, or 256K.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-15 22:57:13 +01:00
|
|
|
/*
|
|
|
|
* Eviction timestamps need to be able to cover the full range of
|
|
|
|
* actionable refaults. However, bits are tight in the radix tree
|
|
|
|
* entry, and after storing the identifier for the lruvec there might
|
|
|
|
* not be enough left to represent every single actionable refault. In
|
|
|
|
* that case, we have to sacrifice granularity for distance, and group
|
|
|
|
* evictions into coarser buckets by shaving off lower timestamp bits.
|
|
|
|
*/
|
|
|
|
static unsigned int bucket_order __read_mostly;
|
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
static void *pack_shadow(int memcgid, struct zone *zone, unsigned long eviction)
|
2014-04-03 23:47:51 +02:00
|
|
|
{
|
mm: workingset: eviction buckets for bigmem/lowbit machines
For per-cgroup thrash detection, we need to store the memcg ID inside
the radix tree cookie as well. However, on 32 bit that doesn't leave
enough bits for the eviction timestamp to cover the necessary range of
recently evicted pages. The radix tree entry would look like this:
[ RADIX_TREE_EXCEPTIONAL(2) | ZONEID(2) | MEMCGID(16) | EVICTION(12) ]
12 bits means 4096 pages, means 16M worth of recently evicted pages.
But refaults are actionable up to distances covering half of memory. To
not miss refaults, we have to stretch out the range at the cost of how
precisely we can tell when a page was evicted. This way we can shave
off lower bits from the eviction timestamp until the necessary range is
covered. E.g. grouping evictions into 1M buckets (256 pages) will
stretch the longest representable refault distance to 4G.
This patch implements eviction buckets that are automatically sized
according to the available bits and the necessary refault range, in
preparation for per-cgroup thrash detection.
The maximum actionable distance is currently half of memory, but to
support memory hotplug of up to 200% of boot-time memory, we size the
buckets to cover double the distance. Beyond that, thrashing won't be
detectable anymore.
During boot, the kernel will print out the exact parameters, like so:
[ 0.113929] workingset: timestamp_bits=12 max_order=18 bucket_order=6
In this example, there are 12 radix entry bits available for the
eviction timestamp, to cover a maximum distance of 2^18 pages (this is a
1G machine). Consequently, evictions must be grouped into buckets of
2^6 pages, or 256K.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-15 22:57:13 +01:00
|
|
|
eviction >>= bucket_order;
|
2016-03-15 22:57:16 +01:00
|
|
|
eviction = (eviction << MEM_CGROUP_ID_SHIFT) | memcgid;
|
2014-04-03 23:47:51 +02:00
|
|
|
eviction = (eviction << NODES_SHIFT) | zone_to_nid(zone);
|
|
|
|
eviction = (eviction << ZONES_SHIFT) | zone_idx(zone);
|
|
|
|
eviction = (eviction << RADIX_TREE_EXCEPTIONAL_SHIFT);
|
|
|
|
|
|
|
|
return (void *)(eviction | RADIX_TREE_EXCEPTIONAL_ENTRY);
|
|
|
|
}
|
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
static void unpack_shadow(void *shadow, int *memcgidp, struct zone **zonep,
|
2016-03-15 22:57:10 +01:00
|
|
|
unsigned long *evictionp)
|
2014-04-03 23:47:51 +02:00
|
|
|
{
|
|
|
|
unsigned long entry = (unsigned long)shadow;
|
2016-03-15 22:57:16 +01:00
|
|
|
int memcgid, nid, zid;
|
2014-04-03 23:47:51 +02:00
|
|
|
|
|
|
|
entry >>= RADIX_TREE_EXCEPTIONAL_SHIFT;
|
|
|
|
zid = entry & ((1UL << ZONES_SHIFT) - 1);
|
|
|
|
entry >>= ZONES_SHIFT;
|
|
|
|
nid = entry & ((1UL << NODES_SHIFT) - 1);
|
|
|
|
entry >>= NODES_SHIFT;
|
2016-03-15 22:57:16 +01:00
|
|
|
memcgid = entry & ((1UL << MEM_CGROUP_ID_SHIFT) - 1);
|
|
|
|
entry >>= MEM_CGROUP_ID_SHIFT;
|
2014-04-03 23:47:51 +02:00
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
*memcgidp = memcgid;
|
2016-03-15 22:57:10 +01:00
|
|
|
*zonep = NODE_DATA(nid)->node_zones + zid;
|
mm: workingset: eviction buckets for bigmem/lowbit machines
For per-cgroup thrash detection, we need to store the memcg ID inside
the radix tree cookie as well. However, on 32 bit that doesn't leave
enough bits for the eviction timestamp to cover the necessary range of
recently evicted pages. The radix tree entry would look like this:
[ RADIX_TREE_EXCEPTIONAL(2) | ZONEID(2) | MEMCGID(16) | EVICTION(12) ]
12 bits means 4096 pages, means 16M worth of recently evicted pages.
But refaults are actionable up to distances covering half of memory. To
not miss refaults, we have to stretch out the range at the cost of how
precisely we can tell when a page was evicted. This way we can shave
off lower bits from the eviction timestamp until the necessary range is
covered. E.g. grouping evictions into 1M buckets (256 pages) will
stretch the longest representable refault distance to 4G.
This patch implements eviction buckets that are automatically sized
according to the available bits and the necessary refault range, in
preparation for per-cgroup thrash detection.
The maximum actionable distance is currently half of memory, but to
support memory hotplug of up to 200% of boot-time memory, we size the
buckets to cover double the distance. Beyond that, thrashing won't be
detectable anymore.
During boot, the kernel will print out the exact parameters, like so:
[ 0.113929] workingset: timestamp_bits=12 max_order=18 bucket_order=6
In this example, there are 12 radix entry bits available for the
eviction timestamp, to cover a maximum distance of 2^18 pages (this is a
1G machine). Consequently, evictions must be grouped into buckets of
2^6 pages, or 256K.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-15 22:57:13 +01:00
|
|
|
*evictionp = entry << bucket_order;
|
2014-04-03 23:47:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* workingset_eviction - note the eviction of a page from memory
|
|
|
|
* @mapping: address space the page was backing
|
|
|
|
* @page: the page being evicted
|
|
|
|
*
|
|
|
|
* Returns a shadow entry to be stored in @mapping->page_tree in place
|
|
|
|
* of the evicted @page so that a later refault can be detected.
|
|
|
|
*/
|
|
|
|
void *workingset_eviction(struct address_space *mapping, struct page *page)
|
|
|
|
{
|
2016-03-15 22:57:16 +01:00
|
|
|
struct mem_cgroup *memcg = page_memcg(page);
|
2014-04-03 23:47:51 +02:00
|
|
|
struct zone *zone = page_zone(page);
|
2016-03-15 22:57:16 +01:00
|
|
|
int memcgid = mem_cgroup_id(memcg);
|
2014-04-03 23:47:51 +02:00
|
|
|
unsigned long eviction;
|
2016-03-15 22:57:16 +01:00
|
|
|
struct lruvec *lruvec;
|
2014-04-03 23:47:51 +02:00
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
/* Page is fully exclusive and pins page->mem_cgroup */
|
|
|
|
VM_BUG_ON_PAGE(PageLRU(page), page);
|
|
|
|
VM_BUG_ON_PAGE(page_count(page), page);
|
|
|
|
VM_BUG_ON_PAGE(!PageLocked(page), page);
|
|
|
|
|
|
|
|
lruvec = mem_cgroup_zone_lruvec(zone, memcg);
|
|
|
|
eviction = atomic_long_inc_return(&lruvec->inactive_age);
|
|
|
|
return pack_shadow(memcgid, zone, eviction);
|
2014-04-03 23:47:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* workingset_refault - evaluate the refault of a previously evicted page
|
|
|
|
* @shadow: shadow entry of the evicted page
|
|
|
|
*
|
|
|
|
* Calculates and evaluates the refault distance of the previously
|
|
|
|
* evicted page in the context of the zone it was allocated in.
|
|
|
|
*
|
|
|
|
* Returns %true if the page should be activated, %false otherwise.
|
|
|
|
*/
|
|
|
|
bool workingset_refault(void *shadow)
|
|
|
|
{
|
|
|
|
unsigned long refault_distance;
|
2016-03-15 22:57:16 +01:00
|
|
|
unsigned long active_file;
|
|
|
|
struct mem_cgroup *memcg;
|
2016-03-15 22:57:10 +01:00
|
|
|
unsigned long eviction;
|
2016-03-15 22:57:16 +01:00
|
|
|
struct lruvec *lruvec;
|
2016-03-15 22:57:10 +01:00
|
|
|
unsigned long refault;
|
2014-04-03 23:47:51 +02:00
|
|
|
struct zone *zone;
|
2016-03-15 22:57:16 +01:00
|
|
|
int memcgid;
|
2014-04-03 23:47:51 +02:00
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
unpack_shadow(shadow, &memcgid, &zone, &eviction);
|
2016-03-15 22:57:10 +01:00
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
rcu_read_lock();
|
|
|
|
/*
|
|
|
|
* Look up the memcg associated with the stored ID. It might
|
|
|
|
* have been deleted since the page's eviction.
|
|
|
|
*
|
|
|
|
* Note that in rare events the ID could have been recycled
|
|
|
|
* for a new cgroup that refaults a shared page. This is
|
|
|
|
* impossible to tell from the available data. However, this
|
|
|
|
* should be a rare and limited disturbance, and activations
|
|
|
|
* are always speculative anyway. Ultimately, it's the aging
|
|
|
|
* algorithm's job to shake out the minimum access frequency
|
|
|
|
* for the active cache.
|
|
|
|
*
|
|
|
|
* XXX: On !CONFIG_MEMCG, this will always return NULL; it
|
|
|
|
* would be better if the root_mem_cgroup existed in all
|
|
|
|
* configurations instead.
|
|
|
|
*/
|
|
|
|
memcg = mem_cgroup_from_id(memcgid);
|
|
|
|
if (!mem_cgroup_disabled() && !memcg) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lruvec = mem_cgroup_zone_lruvec(zone, memcg);
|
|
|
|
refault = atomic_long_read(&lruvec->inactive_age);
|
|
|
|
active_file = lruvec_lru_size(lruvec, LRU_ACTIVE_FILE);
|
|
|
|
rcu_read_unlock();
|
2016-03-15 22:57:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The unsigned subtraction here gives an accurate distance
|
|
|
|
* across inactive_age overflows in most cases.
|
|
|
|
*
|
|
|
|
* There is a special case: usually, shadow entries have a
|
|
|
|
* short lifetime and are either refaulted or reclaimed along
|
|
|
|
* with the inode before they get too old. But it is not
|
|
|
|
* impossible for the inactive_age to lap a shadow entry in
|
|
|
|
* the field, which can then can result in a false small
|
|
|
|
* refault distance, leading to a false activation should this
|
|
|
|
* old entry actually refault again. However, earlier kernels
|
|
|
|
* used to deactivate unconditionally with *every* reclaim
|
|
|
|
* invocation for the longest time, so the occasional
|
|
|
|
* inappropriate activation leading to pressure on the active
|
|
|
|
* list is not a problem.
|
|
|
|
*/
|
|
|
|
refault_distance = (refault - eviction) & EVICTION_MASK;
|
|
|
|
|
2014-04-03 23:47:51 +02:00
|
|
|
inc_zone_state(zone, WORKINGSET_REFAULT);
|
|
|
|
|
2016-03-15 22:57:16 +01:00
|
|
|
if (refault_distance <= active_file) {
|
2014-04-03 23:47:51 +02:00
|
|
|
inc_zone_state(zone, WORKINGSET_ACTIVATE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* workingset_activation - note a page activation
|
|
|
|
* @page: page that is being activated
|
|
|
|
*/
|
|
|
|
void workingset_activation(struct page *page)
|
|
|
|
{
|
2016-03-15 22:57:16 +01:00
|
|
|
struct lruvec *lruvec;
|
|
|
|
|
2016-03-15 22:57:22 +01:00
|
|
|
lock_page_memcg(page);
|
2016-03-15 22:57:16 +01:00
|
|
|
/*
|
|
|
|
* Filter non-memcg pages here, e.g. unmap can call
|
|
|
|
* mark_page_accessed() on VDSO pages.
|
|
|
|
*
|
|
|
|
* XXX: See workingset_refault() - this should return
|
|
|
|
* root_mem_cgroup even for !CONFIG_MEMCG.
|
|
|
|
*/
|
2016-03-15 22:57:22 +01:00
|
|
|
if (!mem_cgroup_disabled() && !page_memcg(page))
|
2016-03-15 22:57:16 +01:00
|
|
|
goto out;
|
2016-03-15 22:57:22 +01:00
|
|
|
lruvec = mem_cgroup_zone_lruvec(page_zone(page), page_memcg(page));
|
2016-03-15 22:57:16 +01:00
|
|
|
atomic_long_inc(&lruvec->inactive_age);
|
|
|
|
out:
|
2016-03-15 22:57:22 +01:00
|
|
|
unlock_page_memcg(page);
|
2014-04-03 23:47:51 +02:00
|
|
|
}
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Shadow entries reflect the share of the working set that does not
|
|
|
|
* fit into memory, so their number depends on the access pattern of
|
|
|
|
* the workload. In most cases, they will refault or get reclaimed
|
|
|
|
* along with the inode, but a (malicious) workload that streams
|
|
|
|
* through files with a total size several times that of available
|
|
|
|
* memory, while preventing the inodes from being reclaimed, can
|
|
|
|
* create excessive amounts of shadow nodes. To keep a lid on this,
|
|
|
|
* track shadow nodes and reclaim them when they grow way past the
|
|
|
|
* point where they would still be useful.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct list_lru workingset_shadow_nodes;
|
|
|
|
|
|
|
|
static unsigned long count_shadow_nodes(struct shrinker *shrinker,
|
|
|
|
struct shrink_control *sc)
|
|
|
|
{
|
|
|
|
unsigned long shadow_nodes;
|
|
|
|
unsigned long max_nodes;
|
|
|
|
unsigned long pages;
|
|
|
|
|
|
|
|
/* list_lru lock nests inside IRQ-safe mapping->tree_lock */
|
|
|
|
local_irq_disable();
|
list_lru: introduce list_lru_shrink_{count,walk}
Kmem accounting of memcg is unusable now, because it lacks slab shrinker
support. That means when we hit the limit we will get ENOMEM w/o any
chance to recover. What we should do then is to call shrink_slab, which
would reclaim old inode/dentry caches from this cgroup. This is what
this patch set is intended to do.
Basically, it does two things. First, it introduces the notion of
per-memcg slab shrinker. A shrinker that wants to reclaim objects per
cgroup should mark itself as SHRINKER_MEMCG_AWARE. Then it will be
passed the memory cgroup to scan from in shrink_control->memcg. For
such shrinkers shrink_slab iterates over the whole cgroup subtree under
the target cgroup and calls the shrinker for each kmem-active memory
cgroup.
Secondly, this patch set makes the list_lru structure per-memcg. It's
done transparently to list_lru users - everything they have to do is to
tell list_lru_init that they want memcg-aware list_lru. Then the
list_lru will automatically distribute objects among per-memcg lists
basing on which cgroup the object is accounted to. This way to make FS
shrinkers (icache, dcache) memcg-aware we only need to make them use
memcg-aware list_lru, and this is what this patch set does.
As before, this patch set only enables per-memcg kmem reclaim when the
pressure goes from memory.limit, not from memory.kmem.limit. Handling
memory.kmem.limit is going to be tricky due to GFP_NOFS allocations, and
it is still unclear whether we will have this knob in the unified
hierarchy.
This patch (of 9):
NUMA aware slab shrinkers use the list_lru structure to distribute
objects coming from different NUMA nodes to different lists. Whenever
such a shrinker needs to count or scan objects from a particular node,
it issues commands like this:
count = list_lru_count_node(lru, sc->nid);
freed = list_lru_walk_node(lru, sc->nid, isolate_func,
isolate_arg, &sc->nr_to_scan);
where sc is an instance of the shrink_control structure passed to it
from vmscan.
To simplify this, let's add special list_lru functions to be used by
shrinkers, list_lru_shrink_count() and list_lru_shrink_walk(), which
consolidate the nid and nr_to_scan arguments in the shrink_control
structure.
This will also allow us to avoid patching shrinkers that use list_lru
when we make shrink_slab() per-memcg - all we will have to do is extend
the shrink_control structure to include the target memcg and make
list_lru_shrink_{count,walk} handle this appropriately.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Suggested-by: Dave Chinner <david@fromorbit.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Greg Thelen <gthelen@google.com>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-02-12 23:58:47 +01:00
|
|
|
shadow_nodes = list_lru_shrink_count(&workingset_shadow_nodes, sc);
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
local_irq_enable();
|
|
|
|
|
2016-03-17 22:18:42 +01:00
|
|
|
if (memcg_kmem_enabled())
|
|
|
|
pages = mem_cgroup_node_nr_lru_pages(sc->memcg, sc->nid,
|
|
|
|
LRU_ALL_FILE);
|
|
|
|
else
|
|
|
|
pages = node_page_state(sc->nid, NR_ACTIVE_FILE) +
|
|
|
|
node_page_state(sc->nid, NR_INACTIVE_FILE);
|
2016-03-17 22:18:39 +01:00
|
|
|
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
/*
|
|
|
|
* Active cache pages are limited to 50% of memory, and shadow
|
|
|
|
* entries that represent a refault distance bigger than that
|
|
|
|
* do not have any effect. Limit the number of shadow nodes
|
|
|
|
* such that shadow entries do not exceed the number of active
|
|
|
|
* cache pages, assuming a worst-case node population density
|
|
|
|
* of 1/8th on average.
|
|
|
|
*
|
|
|
|
* On 64-bit with 7 radix_tree_nodes per page and 64 slots
|
|
|
|
* each, this will reclaim shadow entries when they consume
|
|
|
|
* ~2% of available memory:
|
|
|
|
*
|
|
|
|
* PAGE_SIZE / radix_tree_nodes / node_entries / PAGE_SIZE
|
|
|
|
*/
|
|
|
|
max_nodes = pages >> (1 + RADIX_TREE_MAP_SHIFT - 3);
|
|
|
|
|
|
|
|
if (shadow_nodes <= max_nodes)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return shadow_nodes - max_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum lru_status shadow_lru_isolate(struct list_head *item,
|
2015-02-12 23:59:35 +01:00
|
|
|
struct list_lru_one *lru,
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
spinlock_t *lru_lock,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
struct address_space *mapping;
|
|
|
|
struct radix_tree_node *node;
|
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Page cache insertions and deletions synchroneously maintain
|
|
|
|
* the shadow node LRU under the mapping->tree_lock and the
|
|
|
|
* lru_lock. Because the page cache tree is emptied before
|
|
|
|
* the inode can be destroyed, holding the lru_lock pins any
|
|
|
|
* address_space that has radix tree nodes on the LRU.
|
|
|
|
*
|
|
|
|
* We can then safely transition to the mapping->tree_lock to
|
|
|
|
* pin only the address_space of the particular node we want
|
|
|
|
* to reclaim, take the node off-LRU, and drop the lru_lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
node = container_of(item, struct radix_tree_node, private_list);
|
|
|
|
mapping = node->private_data;
|
|
|
|
|
|
|
|
/* Coming from the list, invert the lock order */
|
|
|
|
if (!spin_trylock(&mapping->tree_lock)) {
|
|
|
|
spin_unlock(lru_lock);
|
|
|
|
ret = LRU_RETRY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-02-12 23:59:35 +01:00
|
|
|
list_lru_isolate(lru, item);
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
spin_unlock(lru_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The nodes should only contain one or more shadow entries,
|
|
|
|
* no pages, so we expect to be able to remove them all and
|
|
|
|
* delete and free the empty node afterwards.
|
|
|
|
*/
|
|
|
|
|
|
|
|
BUG_ON(!node->count);
|
|
|
|
BUG_ON(node->count & RADIX_TREE_COUNT_MASK);
|
|
|
|
|
|
|
|
for (i = 0; i < RADIX_TREE_MAP_SIZE; i++) {
|
|
|
|
if (node->slots[i]) {
|
|
|
|
BUG_ON(!radix_tree_exceptional_entry(node->slots[i]));
|
|
|
|
node->slots[i] = NULL;
|
|
|
|
BUG_ON(node->count < (1U << RADIX_TREE_COUNT_SHIFT));
|
|
|
|
node->count -= 1U << RADIX_TREE_COUNT_SHIFT;
|
2016-01-23 00:10:40 +01:00
|
|
|
BUG_ON(!mapping->nrexceptional);
|
|
|
|
mapping->nrexceptional--;
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
BUG_ON(node->count);
|
|
|
|
inc_zone_state(page_zone(virt_to_page(node)), WORKINGSET_NODERECLAIM);
|
|
|
|
if (!__radix_tree_delete_node(&mapping->page_tree, node))
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
spin_unlock(&mapping->tree_lock);
|
|
|
|
ret = LRU_REMOVED_RETRY;
|
|
|
|
out:
|
|
|
|
local_irq_enable();
|
|
|
|
cond_resched();
|
|
|
|
local_irq_disable();
|
|
|
|
spin_lock(lru_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long scan_shadow_nodes(struct shrinker *shrinker,
|
|
|
|
struct shrink_control *sc)
|
|
|
|
{
|
|
|
|
unsigned long ret;
|
|
|
|
|
|
|
|
/* list_lru lock nests inside IRQ-safe mapping->tree_lock */
|
|
|
|
local_irq_disable();
|
list_lru: introduce list_lru_shrink_{count,walk}
Kmem accounting of memcg is unusable now, because it lacks slab shrinker
support. That means when we hit the limit we will get ENOMEM w/o any
chance to recover. What we should do then is to call shrink_slab, which
would reclaim old inode/dentry caches from this cgroup. This is what
this patch set is intended to do.
Basically, it does two things. First, it introduces the notion of
per-memcg slab shrinker. A shrinker that wants to reclaim objects per
cgroup should mark itself as SHRINKER_MEMCG_AWARE. Then it will be
passed the memory cgroup to scan from in shrink_control->memcg. For
such shrinkers shrink_slab iterates over the whole cgroup subtree under
the target cgroup and calls the shrinker for each kmem-active memory
cgroup.
Secondly, this patch set makes the list_lru structure per-memcg. It's
done transparently to list_lru users - everything they have to do is to
tell list_lru_init that they want memcg-aware list_lru. Then the
list_lru will automatically distribute objects among per-memcg lists
basing on which cgroup the object is accounted to. This way to make FS
shrinkers (icache, dcache) memcg-aware we only need to make them use
memcg-aware list_lru, and this is what this patch set does.
As before, this patch set only enables per-memcg kmem reclaim when the
pressure goes from memory.limit, not from memory.kmem.limit. Handling
memory.kmem.limit is going to be tricky due to GFP_NOFS allocations, and
it is still unclear whether we will have this knob in the unified
hierarchy.
This patch (of 9):
NUMA aware slab shrinkers use the list_lru structure to distribute
objects coming from different NUMA nodes to different lists. Whenever
such a shrinker needs to count or scan objects from a particular node,
it issues commands like this:
count = list_lru_count_node(lru, sc->nid);
freed = list_lru_walk_node(lru, sc->nid, isolate_func,
isolate_arg, &sc->nr_to_scan);
where sc is an instance of the shrink_control structure passed to it
from vmscan.
To simplify this, let's add special list_lru functions to be used by
shrinkers, list_lru_shrink_count() and list_lru_shrink_walk(), which
consolidate the nid and nr_to_scan arguments in the shrink_control
structure.
This will also allow us to avoid patching shrinkers that use list_lru
when we make shrink_slab() per-memcg - all we will have to do is extend
the shrink_control structure to include the target memcg and make
list_lru_shrink_{count,walk} handle this appropriately.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Suggested-by: Dave Chinner <david@fromorbit.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Greg Thelen <gthelen@google.com>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-02-12 23:58:47 +01:00
|
|
|
ret = list_lru_shrink_walk(&workingset_shadow_nodes, sc,
|
|
|
|
shadow_lru_isolate, NULL);
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
local_irq_enable();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct shrinker workingset_shadow_shrinker = {
|
|
|
|
.count_objects = count_shadow_nodes,
|
|
|
|
.scan_objects = scan_shadow_nodes,
|
|
|
|
.seeks = DEFAULT_SEEKS,
|
2016-03-17 22:18:42 +01:00
|
|
|
.flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE,
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our list_lru->lock is IRQ-safe as it nests inside the IRQ-safe
|
|
|
|
* mapping->tree_lock.
|
|
|
|
*/
|
|
|
|
static struct lock_class_key shadow_nodes_key;
|
|
|
|
|
|
|
|
static int __init workingset_init(void)
|
|
|
|
{
|
mm: workingset: eviction buckets for bigmem/lowbit machines
For per-cgroup thrash detection, we need to store the memcg ID inside
the radix tree cookie as well. However, on 32 bit that doesn't leave
enough bits for the eviction timestamp to cover the necessary range of
recently evicted pages. The radix tree entry would look like this:
[ RADIX_TREE_EXCEPTIONAL(2) | ZONEID(2) | MEMCGID(16) | EVICTION(12) ]
12 bits means 4096 pages, means 16M worth of recently evicted pages.
But refaults are actionable up to distances covering half of memory. To
not miss refaults, we have to stretch out the range at the cost of how
precisely we can tell when a page was evicted. This way we can shave
off lower bits from the eviction timestamp until the necessary range is
covered. E.g. grouping evictions into 1M buckets (256 pages) will
stretch the longest representable refault distance to 4G.
This patch implements eviction buckets that are automatically sized
according to the available bits and the necessary refault range, in
preparation for per-cgroup thrash detection.
The maximum actionable distance is currently half of memory, but to
support memory hotplug of up to 200% of boot-time memory, we size the
buckets to cover double the distance. Beyond that, thrashing won't be
detectable anymore.
During boot, the kernel will print out the exact parameters, like so:
[ 0.113929] workingset: timestamp_bits=12 max_order=18 bucket_order=6
In this example, there are 12 radix entry bits available for the
eviction timestamp, to cover a maximum distance of 2^18 pages (this is a
1G machine). Consequently, evictions must be grouped into buckets of
2^6 pages, or 256K.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-15 22:57:13 +01:00
|
|
|
unsigned int timestamp_bits;
|
|
|
|
unsigned int max_order;
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
int ret;
|
|
|
|
|
mm: workingset: eviction buckets for bigmem/lowbit machines
For per-cgroup thrash detection, we need to store the memcg ID inside
the radix tree cookie as well. However, on 32 bit that doesn't leave
enough bits for the eviction timestamp to cover the necessary range of
recently evicted pages. The radix tree entry would look like this:
[ RADIX_TREE_EXCEPTIONAL(2) | ZONEID(2) | MEMCGID(16) | EVICTION(12) ]
12 bits means 4096 pages, means 16M worth of recently evicted pages.
But refaults are actionable up to distances covering half of memory. To
not miss refaults, we have to stretch out the range at the cost of how
precisely we can tell when a page was evicted. This way we can shave
off lower bits from the eviction timestamp until the necessary range is
covered. E.g. grouping evictions into 1M buckets (256 pages) will
stretch the longest representable refault distance to 4G.
This patch implements eviction buckets that are automatically sized
according to the available bits and the necessary refault range, in
preparation for per-cgroup thrash detection.
The maximum actionable distance is currently half of memory, but to
support memory hotplug of up to 200% of boot-time memory, we size the
buckets to cover double the distance. Beyond that, thrashing won't be
detectable anymore.
During boot, the kernel will print out the exact parameters, like so:
[ 0.113929] workingset: timestamp_bits=12 max_order=18 bucket_order=6
In this example, there are 12 radix entry bits available for the
eviction timestamp, to cover a maximum distance of 2^18 pages (this is a
1G machine). Consequently, evictions must be grouped into buckets of
2^6 pages, or 256K.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-15 22:57:13 +01:00
|
|
|
BUILD_BUG_ON(BITS_PER_LONG < EVICTION_SHIFT);
|
|
|
|
/*
|
|
|
|
* Calculate the eviction bucket size to cover the longest
|
|
|
|
* actionable refault distance, which is currently half of
|
|
|
|
* memory (totalram_pages/2). However, memory hotplug may add
|
|
|
|
* some more pages at runtime, so keep working with up to
|
|
|
|
* double the initial memory by using totalram_pages as-is.
|
|
|
|
*/
|
|
|
|
timestamp_bits = BITS_PER_LONG - EVICTION_SHIFT;
|
|
|
|
max_order = fls_long(totalram_pages - 1);
|
|
|
|
if (max_order > timestamp_bits)
|
|
|
|
bucket_order = max_order - timestamp_bits;
|
|
|
|
printk("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n",
|
|
|
|
timestamp_bits, max_order, bucket_order);
|
|
|
|
|
mm: keep page cache radix tree nodes in check
Previously, page cache radix tree nodes were freed after reclaim emptied
out their page pointers. But now reclaim stores shadow entries in their
place, which are only reclaimed when the inodes themselves are
reclaimed. This is problematic for bigger files that are still in use
after they have a significant amount of their cache reclaimed, without
any of those pages actually refaulting. The shadow entries will just
sit there and waste memory. In the worst case, the shadow entries will
accumulate until the machine runs out of memory.
To get this under control, the VM will track radix tree nodes
exclusively containing shadow entries on a per-NUMA node list. Per-NUMA
rather than global because we expect the radix tree nodes themselves to
be allocated node-locally and we want to reduce cross-node references of
otherwise independent cache workloads. A simple shrinker will then
reclaim these nodes on memory pressure.
A few things need to be stored in the radix tree node to implement the
shadow node LRU and allow tree deletions coming from the list:
1. There is no index available that would describe the reverse path
from the node up to the tree root, which is needed to perform a
deletion. To solve this, encode in each node its offset inside the
parent. This can be stored in the unused upper bits of the same
member that stores the node's height at no extra space cost.
2. The number of shadow entries needs to be counted in addition to the
regular entries, to quickly detect when the node is ready to go to
the shadow node LRU list. The current entry count is an unsigned
int but the maximum number of entries is 64, so a shadow counter
can easily be stored in the unused upper bits.
3. Tree modification needs tree lock and tree root, which are located
in the address space, so store an address_space backpointer in the
node. The parent pointer of the node is in a union with the 2-word
rcu_head, so the backpointer comes at no extra cost as well.
4. The node needs to be linked to an LRU list, which requires a list
head inside the node. This does increase the size of the node, but
it does not change the number of objects that fit into a slab page.
[akpm@linux-foundation.org: export the right function]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Metin Doslu <metin@citusdata.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Ozgun Erdogan <ozgun@citusdata.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <klamm@yandex-team.ru>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-03 23:47:56 +02:00
|
|
|
ret = list_lru_init_key(&workingset_shadow_nodes, &shadow_nodes_key);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
ret = register_shrinker(&workingset_shadow_shrinker);
|
|
|
|
if (ret)
|
|
|
|
goto err_list_lru;
|
|
|
|
return 0;
|
|
|
|
err_list_lru:
|
|
|
|
list_lru_destroy(&workingset_shadow_nodes);
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
module_init(workingset_init);
|