All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Moussa A. Ba" <moussa.a.ba@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: David Rientjes <rientjes@google.com>,
	xiyou.wangcong@gmail.com,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Matt Mackall <mpm@selenic.com>, Mel Gorman <mel@csn.ul.ie>,
	Ying Han <yinghan@google.com>, Nick Piggin <npiggin@suse.de>,
	jaredeh@gmail.com
Subject: [PATCH 1/1] pagemap clear_refs: modify to specify anon or mapped vma clearing
Date: Tue, 28 Jul 2009 09:44:36 -0700	[thread overview]
Message-ID: <4A6F2AF4.6050505@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.00.0907271657160.27881@chino.kir.corp.google.com>


This patch adds anonymous and file backed filters to the clear_refs interface.
echo 1 > /proc/PID/clear_refs resets the bits on all pages
echo 2 > /proc/PID/clear_refs resets the bits on anonymous pages only
echo 3 > /proc/PID/clear_refs resets the bits on file backed pages only
Any other value is ignored.

---
Signed-off-by: Moussa A. Ba <moussa.a.ba@gmail.com>
Signed-off-by: Jared E. Hulbert <jaredeh@gmail.com>
--- a/Documentation/filesystems/proc.txt	2009-07-20 17:29:11.000000000 -0700
+++ b/Documentation/filesystems/proc.txt	2009-07-27 16:58:05.000000000 -0700
@@ -375,6 +375,18 @@ of memory currently marked as referenced
  This file is only present if the CONFIG_MMU kernel configuration option is
  enabled.

+The /proc/PID/clear_refs is used to reset the PG_Referenced and ACCESSED/YOUNG
+bits on both physical and virtual pages associated with a process.
+To clear the bits for all the pages associated with the process
+    > echo 1 > /proc/PID/clear_refs
+
+To clear the bits for the anonymous pages associated with the process
+    > echo 2 > /proc/PID/clear_refs
+
+To clear the bits for the file backed pages associated with the process
+    > echo 3 > /proc/PID/clear_refs
+Any other value written to /proc/PID/clear_refs will have no effect.
+
  1.2 Kernel data
  ---------------

--- a/fs/proc/task_mmu.c	2009-07-21 14:30:01.000000000 -0700
+++ b/fs/proc/task_mmu.c	2009-07-27 17:05:25.000000000 -0700
@@ -462,6 +462,10 @@ static int clear_refs_pte_range(pmd_t *
  	return 0;
  }

+#define CLEAR_REFS_ALL 1
+#define CLEAR_REFS_ANON 2
+#define CLEAR_REFS_MAPPED 3
+
  static ssize_t clear_refs_write(struct file *file, const char __user * buf,
  				size_t count, loff_t * ppos)
  {
@@ -469,13 +473,15 @@ static ssize_t clear_refs_write(struct f
  	char buffer[PROC_NUMBUF], *end;
  	struct mm_struct *mm;
  	struct vm_area_struct *vma;
+	int type;

  	memset(buffer, 0, sizeof(buffer));
  	if (count > sizeof(buffer) - 1)
  		count = sizeof(buffer) - 1;
  	if (copy_from_user(buffer, buf, count))
  		return -EFAULT;
-	if (!simple_strtol(buffer, &end, 0))
+	type = simple_strtol(buffer, &end, 0);
+	if (!type || type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED)
  		return -EINVAL;
  	if (*end == '\n')
  		end++;
@@ -491,9 +497,23 @@ static ssize_t clear_refs_write(struct f
  		down_read(&mm->mmap_sem);
  		for (vma = mm->mmap; vma; vma = vma->vm_next) {
  			clear_refs_walk.private = vma;
-			if (!is_vm_hugetlb_page(vma))
-				walk_page_range(vma->vm_start, vma->vm_end,
-						&clear_refs_walk);
+			if (is_vm_hugetlb_page(vma))
+				continue;
+			/*
+			 * Writing 1 to /proc/pid/clear_refs affects all pages.
+			 *
+			 * Writing 2 to /proc/pid/clear_refs only affects
+			 * Anonymous pages.
+			 *
+			 * Writing 3 to /proc/pid/clear_refs only affects file
+			 * backed pages.
+			 */
+			if (type == CLEAR_REFS_ANON && vma->vm_file)
+				continue;
+			if (type == CLEAR_REFS_MAPPED && !vma->vm_file)
+				continue;
+			walk_page_range(vma->vm_start, vma->vm_end,
+					&clear_refs_walk);
  		}
  		flush_tlb_mm(mm);
  		up_read(&mm->mmap_sem);

  parent reply	other threads:[~2009-07-28 16:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24  3:57 [PATCH 1/1] pagemap clear_refs: modify to specify anon or mapped vma clearing Moussa A. Ba
2009-07-24  8:39 ` Amerigo Wang
2009-07-24 18:00   ` Moussa Ba
2009-07-27 20:19   ` Moussa A. Ba
2009-07-27 20:30     ` Matt Mackall
2009-07-27 20:57     ` David Rientjes
2009-07-27 22:14       ` Moussa Ba
2009-07-27 22:20         ` Matt Mackall
2009-07-27 22:49         ` David Rientjes
2009-07-27 23:38           ` Moussa Ba
2009-07-27 23:42             ` Moussa Ba
2009-07-27 23:58             ` David Rientjes
2009-07-28  3:24               ` Amerigo Wang
2009-07-28 16:44               ` Moussa A. Ba [this message]
2009-07-28 21:01                 ` David Rientjes
2009-07-28 22:52                   ` Moussa A. Ba
2009-07-28 23:52                     ` Andrew Morton
2009-07-29  0:00                       ` Moussa Ba
2009-07-29 14:58                         ` Mel Gorman
2009-07-29 16:41                           ` Matt Mackall
2009-07-30 19:21                           ` Moussa Ba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A6F2AF4.6050505@gmail.com \
    --to=moussa.a.ba@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jaredeh@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mel@csn.ul.ie \
    --cc=mpm@selenic.com \
    --cc=npiggin@suse.de \
    --cc=rientjes@google.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yinghan@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.