From: "Américo Wang" <xiyou.wangcong@gmail.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 2/3][mmotm] showing size of kcore v2
Date: Fri, 18 Sep 2009 10:20:36 +0800 [thread overview]
Message-ID: <2375c9f90909171920q6941b8al39a045529550732d@mail.gmail.com> (raw)
In-Reply-To: <20090917151016.99f7c5ab.kamezawa.hiroyu@jp.fujitsu.com>
On Thu, Sep 17, 2009 at 2:10 PM, KAMEZAWA Hiroyuki
<kamezawa.hiroyu@jp.fujitsu.com> wrote:
> On Thu, 17 Sep 2009 14:02:39 +0800
> Américo Wang <xiyou.wangcong@gmail.com> wrote:
>> > @@ -124,6 +126,7 @@ static void __kcore_update_ram(struct li
>> > write_unlock(&kclist_lock);
>> >
>> > free_kclist_ents(&garbage);
>> > + proc_root_kcore->size = get_kcore_size(&nphdr, &size);
>>
>>
>> This makes me to think if we will have some race condition here?
>> Two processes can open kcore at the same time...
>>
> Finally,
> ==
> static void __kcore_update_ram(struct list_head *list)
> {
> write_lock(&kclist_lock);
> if (kcore_need_update) {
> list_for_each_entry_safe(pos, tmp, &kclist_head, list) {
> if (pos->type == KCORE_RAM
> || pos->type == KCORE_VMEMMAP)
> list_move(&pos->list, &garbage);
> }
> list_splice_tail(list, &kclist_head);
> } else
> list_splice(list, &garbage);
> kcore_need_update = 0;
> write_unlock(&kclist_lock);
> }
>
> kclist itself is double checked under write_lock.
> And, once updated, get_kcore_size()'s return vaule is static.
Imagine one process does get_kcore_size(), then another process
is scheduled, who also does get_kcore_size() but at this time,
memory size is changed, so it gets a different value. If then the
second process writes to proc_root_kcore->size before the first one
does, the proc_root_kcore->size is wrong.
Am I missing something here?
> So, I think there are no race. But..Hmm...is this clearer ?
>
> ==
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Yes, this version should be OK.
Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
>
> Now, size of /proc/kcore which can be read by 'ls -l' is 0.
> But it's not correct value.
>
> This is a patch for showing size of /proc/kcore as following.
>
> On x86-64, ls -l shows
> ... root root 140737486266368 2009-09-17 10:29 /proc/kcore
> Then, 7FFFFFFE02000. This comes from vmalloc area's size.
> This shows "core" size, not memory size.
>
> This patch shows the size by updating "size" field in struct proc_dir_entry.
> Later, lookup routine will create inode and fill inode->i_size based
> on this value. Then, this has a problem.
>
> - Once inode is cached, inode->i_size will never be updated.
>
> Then, this patch is not memory-hotplug-aware.
>
> To update inode->i_size, we have to know dentry or inode.
> But there is no way to lookup them by inside kernel. Hmmm....
> Next patch will try it.
>
> Changelog:
> -moved upadting ->size under lock.
>
> Cc: WANG Cong <xiyou.wangcong@gmail.com>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
> fs/proc/kcore.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> Index: mmotm-2.6.31-Sep14/fs/proc/kcore.c
> ===================================================================
> --- mmotm-2.6.31-Sep14.orig/fs/proc/kcore.c
> +++ mmotm-2.6.31-Sep14/fs/proc/kcore.c
> @@ -107,6 +107,8 @@ static void free_kclist_ents(struct list
> */
> static void __kcore_update_ram(struct list_head *list)
> {
> + int nphdr;
> + size_t size;
> struct kcore_list *tmp, *pos;
> LIST_HEAD(garbage);
>
> @@ -121,6 +123,7 @@ static void __kcore_update_ram(struct li
> } else
> list_splice(list, &garbage);
> kcore_need_update = 0;
> + proc_root_kcore->size = get_kcore_size(&nphdr, &size);
> write_unlock(&kclist_lock);
>
> free_kclist_ents(&garbage);
> @@ -429,7 +432,8 @@ read_kcore(struct file *file, char __use
> unsigned long start;
>
> read_lock(&kclist_lock);
> - proc_root_kcore->size = size = get_kcore_size(&nphdr, &elf_buflen);
> + size = get_kcore_size(&nphdr, &elf_buflen);
> +
> if (buflen == 0 || *fpos >= size) {
> read_unlock(&kclist_lock);
> return 0;
>
>
>
>
>
>
>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-09-18 2:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 9:35 kcore patches (was Re: 2.6.32 -mm merge plans) Américo Wang
2009-09-16 11:17 ` KAMEZAWA Hiroyuki
2009-09-17 2:41 ` [PATCH 0/3][mmotm] showing size of kcore (Was " KAMEZAWA Hiroyuki
2009-09-17 2:42 ` [PATCH 1/3][mmotm] kcore: more fixes for init KAMEZAWA Hiroyuki
2009-09-17 5:55 ` Américo Wang
2009-09-17 2:44 ` [PATCH 2/3][mmotm] showing size of kcore KAMEZAWA Hiroyuki
2009-09-17 6:02 ` Américo Wang
2009-09-17 6:10 ` [PATCH 2/3][mmotm] showing size of kcore v2 KAMEZAWA Hiroyuki
2009-09-18 2:20 ` Américo Wang [this message]
2009-09-17 2:45 ` [PATCH 3/3][mmotm] updateing size of kcore KAMEZAWA Hiroyuki
2009-09-17 6:59 ` Américo Wang
2009-09-17 7:14 ` KAMEZAWA Hiroyuki
2009-09-18 2:05 ` Américo Wang
2009-09-17 3:09 ` kcore patches (was Re: 2.6.32 -mm merge plans) Américo Wang
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=2375c9f90909171920q6941b8al39a045529550732d@mail.gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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;
as well as URLs for NNTP newsgroup(s).