From: "Wei-chin Tsai (蔡維晉)" <Wei-chin.Tsai@mediatek.com>
To: "linux@armlinux.org.uk" <linux@armlinux.org.uk>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Mel Lee (李奇錚)" <Mel.Lee@mediatek.com>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
wsd_upstream <wsd_upstream@mediatek.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"Ivan Tseng (曾志軒)" <ivan.tseng@mediatek.com>,
"angelogioacchino.delregno@collabora.com"
<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH v1 1/1] memory: export symbols for process memory related functions
Date: Fri, 9 Jun 2023 16:09:01 +0000 [thread overview]
Message-ID: <5cc76704214673cf03376d9f10f61325b9ed323f.camel@mediatek.com> (raw)
In-Reply-To: <ZIMK9QV5+ce69Shr@shell.armlinux.org.uk>
On Fri, 2023-06-09 at 12:20 +0100, Russell King (Oracle) wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> On Fri, Jun 09, 2023 at 07:09:00PM +0800, jim.tsai wrote:
> > Export symbols for arch_vma_name and smap_gather_stats
> > functions so that we can detect the memory leak issues.
> > Besides, we can know which memory type is leaked, too.
>
> This commit description doesn't give enough information. How does
> exporting arch_vma_name() help with detecting memory leak issues?
>
> You haven't included any users of these new exports, so the initial
> reaction is going to be negative - please include the users of these
> new symbols in your patch set.
>
> Thanks.
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Hi Russell,
arch_vma_name() is to get the heap infromation from a user process.
We use these two export functions from our kernel module to get a
specific user process's memory information and heap usage. Furthermore,
we can use such information to detect the memory leak issues.
The example code is as follows:
/*example code*/
void m_map_vma(struct vm_area_struct *vma, unsigned long cur_pss,
unsigned long *native_heap, unsigned long
*java_heap)
{
struct mm_struct *mm = vma->vm_mm;
const char *name = NULL;
...
name = arch_vma_name(vma);
if (!name) {
struct anon_vma_name *anon_name;
...
anon_name = m_anon_vma_name(vma);
if (anon_name) {
if (strstr(anon_name->name, "scudo"))
(*native_heap) += cur_pss;
else if (strstr(anon_name->name,
"libc_malloc"))
(*native_heap) += cur_pss;
else if (strstr(anon_name->name, "GWP-ASan"))
(*native_heap) += cur_pss;
else if (strstr(anon_name->name, "dalvik-alloc
space"))
(*java_heap) += cur_pss;
else if (strstr(anon_name->name, "dalvik-main
space"))
(*java_heap) += cur_pss;
...
}
}
}
void calculate_process_memory(struct task_struct *t)
{
struct mm_struct *mm = NULL;
struct vm_area_struct *vma = NULL;
struct mem_size_stats mss;
unsigned long pss, uss, rss, swap, cur_pss;
unsigned long java_heap = 0, native_heap = 0;
struct vma_iterator vmi;
get_task_struct(t);
mm = t->mm;
if (mm) {
memset(&mss, 0, sizeof(mss));
mmgrab(mm);
mmap_read_lock(mm);
vma_iter_init(&vmi, mm, 0);
for_each_vma(vmi, vma) {
cur_pss = (unsigned long)(mss.pss >>
PSS_SHIFT);
smap_gather_stats(vma, &mss, 0);
cur_pss =
((unsigned long)(mss.pss >> PSS_SHIFT))
- cur_pss;
cur_pss = cur_pss / 1024;
m_map_vma(vma, cur_pss, &native_heap,
&java_heap);
}
mmap_read_unlock(mm);
mmdrop(mm);
}
put_task_struct(t);
...
}
Thanks
Jim
next prev parent reply other threads:[~2023-06-09 16:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230609110902.13799-1-Wei-chin.Tsai@mediatek.com>
2023-06-09 11:20 ` [PATCH v1 1/1] memory: export symbols for process memory related functions Russell King (Oracle)
2023-06-09 16:09 ` Wei-chin Tsai (蔡維晉) [this message]
2023-06-10 0:21 ` Matthew Wilcox
2023-06-12 14:21 ` Wei-chin Tsai (蔡維晉)
2023-06-16 9:24 ` Matthias Brugger
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=5cc76704214673cf03376d9f10f61325b9ed323f.camel@mediatek.com \
--to=wei-chin.tsai@mediatek.com \
--cc=Mel.Lee@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=ivan.tseng@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.bgg@gmail.com \
--cc=wsd_upstream@mediatek.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).