aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorVladimir Davydov <vdavydov@parallels.com>2015-09-09 18:35:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-10 16:29:01 -0400
commit33c3fc71c8cfa3cc3a98beaa901c069c177dc295 (patch)
treed367186631c578017fda08db238e739d44fd0b99 /fs/proc
parent1d7715c676a1566c2e4c3e77d16b1f9bb4909025 (diff)
mm: introduce idle page tracking
Knowing the portion of memory that is not used by a certain application or memory cgroup (idle memory) can be useful for partitioning the system efficiently, e.g. by setting memory cgroup limits appropriately. Currently, the only means to estimate the amount of idle memory provided by the kernel is /proc/PID/{clear_refs,smaps}: the user can clear the access bit for all pages mapped to a particular process by writing 1 to clear_refs, wait for some time, and then count smaps:Referenced. However, this method has two serious shortcomings: - it does not count unmapped file pages - it affects the reclaimer logic To overcome these drawbacks, this patch introduces two new page flags, Idle and Young, and a new sysfs file, /sys/kernel/mm/page_idle/bitmap. A page's Idle flag can only be set from userspace by setting bit in /sys/kernel/mm/page_idle/bitmap at the offset corresponding to the page, and it is cleared whenever the page is accessed either through page tables (it is cleared in page_referenced() in this case) or using the read(2) system call (mark_page_accessed()). Thus by setting the Idle flag for pages of a particular workload, which can be found e.g. by reading /proc/PID/pagemap, waiting for some time to let the workload access its working set, and then reading the bitmap file, one can estimate the amount of pages that are not used by the workload. The Young page flag is used to avoid interference with the memory reclaimer. A page's Young flag is set whenever the Access bit of a page table entry pointing to the page is cleared by writing to the bitmap file. If page_referenced() is called on a Young page, it will add 1 to its return value, therefore concealing the fact that the Access bit was cleared. Note, since there is no room for extra page flags on 32 bit, this feature uses extended page flags when compiled on 32 bit. [akpm@linux-foundation.org: fix build] [akpm@linux-foundation.org: kpageidle requires an MMU] [akpm@linux-foundation.org: decouple from page-flags rework] Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Reviewed-by: Andres Lagar-Cavilla <andreslc@google.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Greg Thelen <gthelen@google.com> Cc: Michel Lespinasse <walken@google.com> Cc: David Rientjes <rientjes@google.com> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Cyrill Gorcunov <gorcunov@openvz.org> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/page.c3
-rw-r--r--fs/proc/task_mmu.c5
2 files changed, 7 insertions, 1 deletions
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 70d23245dd43..c2d29edcaa6b 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -10,12 +10,15 @@
10#include <linux/seq_file.h> 10#include <linux/seq_file.h>
11#include <linux/hugetlb.h> 11#include <linux/hugetlb.h>
12#include <linux/memcontrol.h> 12#include <linux/memcontrol.h>
13#include <linux/mmu_notifier.h>
14#include <linux/page_idle.h>
13#include <linux/kernel-page-flags.h> 15#include <linux/kernel-page-flags.h>
14#include <asm/uaccess.h> 16#include <asm/uaccess.h>
15#include "internal.h" 17#include "internal.h"
16 18
17#define KPMSIZE sizeof(u64) 19#define KPMSIZE sizeof(u64)
18#define KPMMASK (KPMSIZE - 1) 20#define KPMMASK (KPMSIZE - 1)
21#define KPMBITS (KPMSIZE * BITS_PER_BYTE)
19 22
20/* /proc/kpagecount - an array exposing page counts 23/* /proc/kpagecount - an array exposing page counts
21 * 24 *
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 41f1a50c10c9..e2d46adb54b4 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -13,6 +13,7 @@
13#include <linux/swap.h> 13#include <linux/swap.h>
14#include <linux/swapops.h> 14#include <linux/swapops.h>
15#include <linux/mmu_notifier.h> 15#include <linux/mmu_notifier.h>
16#include <linux/page_idle.h>
16 17
17#include <asm/elf.h> 18#include <asm/elf.h>
18#include <asm/uaccess.h> 19#include <asm/uaccess.h>
@@ -459,7 +460,7 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
459 460
460 mss->resident += size; 461 mss->resident += size;
461 /* Accumulate the size in pages that have been accessed. */ 462 /* Accumulate the size in pages that have been accessed. */
462 if (young || PageReferenced(page)) 463 if (young || page_is_young(page) || PageReferenced(page))
463 mss->referenced += size; 464 mss->referenced += size;
464 mapcount = page_mapcount(page); 465 mapcount = page_mapcount(page);
465 if (mapcount >= 2) { 466 if (mapcount >= 2) {
@@ -807,6 +808,7 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
807 808
808 /* Clear accessed and referenced bits. */ 809 /* Clear accessed and referenced bits. */
809 pmdp_test_and_clear_young(vma, addr, pmd); 810 pmdp_test_and_clear_young(vma, addr, pmd);
811 test_and_clear_page_young(page);
810 ClearPageReferenced(page); 812 ClearPageReferenced(page);
811out: 813out:
812 spin_unlock(ptl); 814 spin_unlock(ptl);
@@ -834,6 +836,7 @@ out:
834 836
835 /* Clear accessed and referenced bits. */ 837 /* Clear accessed and referenced bits. */
836 ptep_test_and_clear_young(vma, addr, pte); 838 ptep_test_and_clear_young(vma, addr, pte);
839 test_and_clear_page_young(page);
837 ClearPageReferenced(page); 840 ClearPageReferenced(page);
838 } 841 }
839 pte_unmap_unlock(pte - 1, ptl); 842 pte_unmap_unlock(pte - 1, ptl);