From: Toshiki Fukasawa <t-fukasawa@vx.jp.nec.com>
To: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"dan.j.williams@intel.com" <dan.j.williams@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"mhocko@kernel.org" <mhocko@kernel.org>,
"adobriyan@gmail.com" <adobriyan@gmail.com>,
"hch@lst.de" <hch@lst.de>,
"longman@redhat.com" <longman@redhat.com>,
"sfr@canb.auug.org.au" <sfr@canb.auug.org.au>,
"mst@redhat.com" <mst@redhat.com>, "cai@lca.pw" <cai@lca.pw>,
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
Junichi Nomura <j-nomura@ce.jp.nec.com>
Subject: [PATCH 1/3] procfs: refactor kpage_*_read() in fs/proc/page.c
Date: Fri, 8 Nov 2019 00:08:07 +0000 [thread overview]
Message-ID: <20191108000855.25209-2-t-fukasawa@vx.jp.nec.com> (raw)
In-Reply-To: <20191108000855.25209-1-t-fukasawa@vx.jp.nec.com>
kpagecount_read(), kpageflags_read(), and kpagecgroup_read()
have duplicate code. This patch moves it into a common function.
Signed-off-by: Toshiki Fukasawa <t-fukasawa@vx.jp.nec.com>
---
fs/proc/page.c | 133 +++++++++++++++++++++------------------------------------
1 file changed, 48 insertions(+), 85 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 7c952ee..a49b638 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -21,20 +21,19 @@
#define KPMMASK (KPMSIZE - 1)
#define KPMBITS (KPMSIZE * BITS_PER_BYTE)
-/* /proc/kpagecount - an array exposing page counts
- *
- * Each entry is a u64 representing the corresponding
- * physical page count.
+typedef u64 (*read_page_data_fn_t)(struct page *page);
+
+/*
+ * This is general function to read various data on pages.
*/
-static ssize_t kpagecount_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t kpage_common_read(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos, read_page_data_fn_t read_fn)
{
u64 __user *out = (u64 __user *)buf;
struct page *ppage;
unsigned long src = *ppos;
unsigned long pfn;
ssize_t ret = 0;
- u64 pcount;
pfn = src / KPMSIZE;
count = min_t(size_t, count, (max_pfn * KPMSIZE) - src);
@@ -48,12 +47,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
*/
ppage = pfn_to_online_page(pfn);
- if (!ppage || PageSlab(ppage) || page_has_type(ppage))
- pcount = 0;
- else
- pcount = page_mapcount(ppage);
-
- if (put_user(pcount, out)) {
+ if (put_user(read_fn(ppage), out)) {
ret = -EFAULT;
break;
}
@@ -71,6 +65,30 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
return ret;
}
+/* /proc/kpagecount - an array exposing page counts
+ *
+ * Each entry is a u64 representing the corresponding
+ * physical page count.
+ */
+
+static u64 page_count_data(struct page *page)
+{
+ u64 pcount;
+
+ if (!page || PageSlab(page) || page_has_type(page))
+ pcount = 0;
+ else
+ pcount = page_mapcount(page);
+
+ return pcount;
+}
+
+static ssize_t kpagecount_read(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return kpage_common_read(file, buf, count, ppos, page_count_data);
+}
+
static const struct file_operations proc_kpagecount_operations = {
.llseek = mem_lseek,
.read = kpagecount_read,
@@ -203,43 +221,15 @@ u64 stable_page_flags(struct page *page)
return u;
};
+static u64 page_flags_data(struct page *page)
+{
+ return stable_page_flags(page);
+}
+
static ssize_t kpageflags_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
- u64 __user *out = (u64 __user *)buf;
- struct page *ppage;
- unsigned long src = *ppos;
- unsigned long pfn;
- ssize_t ret = 0;
-
- pfn = src / KPMSIZE;
- count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
- if (src & KPMMASK || count & KPMMASK)
- return -EINVAL;
-
- while (count > 0) {
- /*
- * TODO: ZONE_DEVICE support requires to identify
- * memmaps that were actually initialized.
- */
- ppage = pfn_to_online_page(pfn);
-
- if (put_user(stable_page_flags(ppage), out)) {
- ret = -EFAULT;
- break;
- }
-
- pfn++;
- out++;
- count -= KPMSIZE;
-
- cond_resched();
- }
-
- *ppos += (char __user *)out - buf;
- if (!ret)
- ret = (char __user *)out - buf;
- return ret;
+ return kpage_common_read(file, buf, count, ppos, page_flags_data);
}
static const struct file_operations proc_kpageflags_operations = {
@@ -248,49 +238,22 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf,
};
#ifdef CONFIG_MEMCG
-static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static u64 page_cgroup_data(struct page *page)
{
- u64 __user *out = (u64 __user *)buf;
- struct page *ppage;
- unsigned long src = *ppos;
- unsigned long pfn;
- ssize_t ret = 0;
u64 ino;
- pfn = src / KPMSIZE;
- count = min_t(unsigned long, count, (max_pfn * KPMSIZE) - src);
- if (src & KPMMASK || count & KPMMASK)
- return -EINVAL;
-
- while (count > 0) {
- /*
- * TODO: ZONE_DEVICE support requires to identify
- * memmaps that were actually initialized.
- */
- ppage = pfn_to_online_page(pfn);
-
- if (ppage)
- ino = page_cgroup_ino(ppage);
- else
- ino = 0;
-
- if (put_user(ino, out)) {
- ret = -EFAULT;
- break;
- }
-
- pfn++;
- out++;
- count -= KPMSIZE;
+ if (page)
+ ino = page_cgroup_ino(page);
+ else
+ ino = 0;
- cond_resched();
- }
+ return ino;
+}
- *ppos += (char __user *)out - buf;
- if (!ret)
- ret = (char __user *)out - buf;
- return ret;
+static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return kpage_common_read(file, buf, count, ppos, page_cgroup_data);
}
static const struct file_operations proc_kpagecgroup_operations = {
--
1.8.3.1
next prev parent reply other threads:[~2019-11-08 0:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-08 0:08 [PATCH 0/3] make pfn walker support ZONE_DEVICE Toshiki Fukasawa
2019-11-08 0:08 ` Toshiki Fukasawa [this message]
2019-11-08 0:08 ` [PATCH 2/3] mm: Introduce subsection_dev_map Toshiki Fukasawa
2019-11-08 19:13 ` Dan Williams
2019-11-13 18:51 ` David Hildenbrand
2019-11-13 19:06 ` Dan Williams
2019-11-13 19:53 ` David Hildenbrand
2019-11-13 20:10 ` Dan Williams
2019-11-13 20:23 ` David Hildenbrand
2019-11-13 20:40 ` David Hildenbrand
2019-11-13 21:11 ` Dan Williams
2019-11-13 21:22 ` David Hildenbrand
2019-11-13 21:26 ` Dan Williams
2019-11-14 23:36 ` Toshiki Fukasawa
2019-11-15 0:46 ` David Hildenbrand
2019-11-15 2:57 ` Toshiki Fukasawa
2019-11-08 0:08 ` [PATCH 3/3] mm: make pfn walker support ZONE_DEVICE Toshiki Fukasawa
2019-11-09 17:08 ` kbuild test robot
2019-11-09 19:14 ` kbuild test robot
2019-11-08 9:18 ` [PATCH 0/3] " Michal Hocko
2019-11-11 8:00 ` Toshiki Fukasawa
2019-11-11 16:23 ` Dan Williams
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=20191108000855.25209-2-t-fukasawa@vx.jp.nec.com \
--to=t-fukasawa@vx.jp.nec.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=dan.j.williams@intel.com \
--cc=hch@lst.de \
--cc=j-nomura@ce.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mhocko@kernel.org \
--cc=mst@redhat.com \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=sfr@canb.auug.org.au \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox