From: yuyufen <yuyufen@huawei.com>
To: Mike Kravetz <mike.kravetz@oracle.com>, <linux-mm@kvack.org>
Subject: Re: [PATCH] hugetlbfs: fix memory leak for resv_map
Date: Tue, 5 Mar 2019 10:09:44 +0800 [thread overview]
Message-ID: <64ab7e52-91a1-cf87-8bae-871663547d43@huawei.com> (raw)
In-Reply-To: <16c7f90d-ad52-4255-f937-b585b649ce57@oracle.com>
Hi, Mike
On 2019/3/5 2:29, Mike Kravetz wrote:
> Thank you for finding this issue.
>
> On 3/2/19 2:47 AM, Yufen Yu wrote:
>> When .mknod create a block device file in hugetlbfs, it will
>> allocate an inode, and kmalloc a 'struct resv_map' in resv_map_alloc().
>> For now, inode->i_mapping->private_data is used to point the resv_map.
>> However, when open the device, bd_acquire() will set i_mapping as
>> bd_inode->imapping, result in resv_map memory leak.
> We are certainly leaking the resv_map.
>
>> We fix the leak by adding a new entry resv_map in hugetlbfs_inode_info.
>> It can store resv_map pointer.
> This approach preserves the way the existing code always allocates a
> resv_map at inode allocation time. However, it does add an extra word
> to every hugetlbfs inode. My first thought was, why not special case
> the block/char inode creation to not allocate a resv_map? After all,
> it is not used in this case. In fact, we only need/use the resv_map
> when mmap'ing a regular file. It is a waste to allocate the structure
> in all other cases.
>
> It seems like we should be able to wait until a call to hugetlb_reserve_pages()
> to allocate the inode specific resv_map in much the same way we do for
> private mappings. We could then remove the resv_map allocation at inode
> creation time. Of course, we would still need the code to free the structure
> when the inode is destroyed.
>
> I have not looked too closely at this approach, and there may be some
> unknown issues. However, it would address the leak you discovered and
> would result in less memory used for hugetlbfs inodes that are never
> mmap'ed.
>
> Any thoughts on this approach?
>
> I know it is beyond the scope of your patch. If you do not want to try this,
> I can code up something in a couple days.
Thanks for your suggestion. I agree with you. It will be a better solution.
I don't understand hugetlbfs deeply, but I want to try my best to solve
this problem.
Yufen
Thanks.
next prev parent reply other threads:[~2019-03-05 2:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-02 10:47 Yufen Yu
2019-03-04 18:29 ` Mike Kravetz
2019-03-05 2:09 ` yuyufen [this message]
2019-04-01 21:31 Mike Kravetz
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=64ab7e52-91a1-cf87-8bae-871663547d43@huawei.com \
--to=yuyufen@huawei.com \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox