From: SeongJae Park <sjpark@amazon.com>
To: Alkaid <zgf574564920@gmail.com>
Cc: <akpm@linux-foundation.org>, SeongJae Park <sjpark@amazon.de>,
<Jonathan.Cameron@huawei.com>, <aarcange@redhat.com>,
<acme@kernel.org>, <alexander.shishkin@linux.intel.com>,
<amit@kernel.org>, <benh@kernel.crashing.org>,
<brendan.d.gregg@gmail.com>, <brendanhiggins@google.com>,
<cai@lca.pw>, <colin.king@canonical.com>, <corbet@lwn.net>,
<david@redhat.com>, <dwmw@amazon.com>, <fan.du@intel.com>,
<foersleo@amazon.de>, <gthelen@google.com>, <irogers@google.com>,
<jolsa@redhat.com>, <kirill@shutemov.name>,
<mark.rutland@arm.com>, <mgorman@suse.de>, <minchan@kernel.org>,
<mingo@redhat.com>, <namhyung@kernel.org>, <peterz@infradead.org>,
<rdunlap@infradead.org>, <riel@surriel.com>,
<rientjes@google.com>, <rostedt@goodmis.org>, <rppt@kernel.org>,
<sblbir@amazon.com>, <shakeelb@google.com>, <shuah@kernel.org>,
<sj38.park@gmail.com>, <snu@amazon.de>, <vbabka@suse.cz>,
<vdavydov.dev@gmail.com>, <yang.shi@linux.alibaba.com>,
<ying.huang@intel.com>, <linux-damon@amazon.com>,
<linux-mm@kvack.org>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, SeongJae Park <sjpark@amazon.com>
Subject: Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
Date: Fri, 28 Aug 2020 13:39:21 +0200 [thread overview]
Message-ID: <20200828113921.15279-1-sjpark@amazon.com> (raw)
In-Reply-To: <20200828095315.27210-1-sjpark@amazon.com>
On Fri, 28 Aug 2020 11:53:15 +0200 SeongJae Park <sjpark@amazon.com> wrote:
> On Fri, 28 Aug 2020 04:11:56 -0400 Alkaid <zgf574564920@gmail.com> wrote:
>
> >
> > [-- Attachment #1: Type: text/plain, Size: 2677 bytes --]
> >
> > Hi SeongJae,
> >
> > I think there are potential memory leaks in the following execution paths
>
> Agreed, definitely memory leaks exists. Thank you for let me know this! I
> will post a patch for this soon.
And, below is the patch. The complete tree is available at:
https://github.com/sjp38/linux/tree/damon/next
Thanks,
SeongJae Park
==================================== >8 =======================================
From 8f605d807c55b536ab5b0f87306ac78033dc4499 Mon Sep 17 00:00:00 2001
From: SeongJae Park <sjpark@amazon.de>
Date: Fri, 28 Aug 2020 11:29:30 +0000
Subject: [PATCH] mm/damon/paddr: Add missed 'put_page()' calls
Exceptional cases handlings in 'damon_phys_mkold()' and
'damon_phys_young()' doesn't properly put pages. This commit fixes the
problem by adding the 'put_page()' call.
Reported-by: Alkaid <zgf574564920@gmail.com>
Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
mm/damon.c | 53 ++++++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/mm/damon.c b/mm/damon.c
index d0d55656553b..74a10ea54958 100644
--- a/mm/damon.c
+++ b/mm/damon.c
@@ -836,12 +836,16 @@ unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx)
/* access check functions for physical address based regions */
/*
- * Get a page by pfn if it is in the LRU list. Otherwise, returns NULL.
+ * Get a page by @pfn if it is in the LRU list and mapped. If the page needs
+ * locked, do the lock and save the result in @locked. Otherwise, returns
+ * NULL.
*
- * The body of this function is stollen from the 'page_idle_get_page()'. We
- * steal rather than reuse it because the code is quite simple .
+ * The body of this function is mostly stollen from the 'page_idle_get_page()'
+ * and 'page_idle_clear_pte_refs()'. We steal rather than reuse it not because
+ * we are great artists but the code is quite simple and we need to unify parts
+ * of the two functions.
*/
-static struct page *damon_phys_get_page(unsigned long pfn)
+static struct page *damon_phys_get_page(unsigned long pfn, bool *locked)
{
struct page *page = pfn_to_online_page(pfn);
pg_data_t *pgdat;
@@ -854,9 +858,22 @@ static struct page *damon_phys_get_page(unsigned long pfn)
spin_lock_irq(&pgdat->lru_lock);
if (unlikely(!PageLRU(page))) {
put_page(page);
- page = NULL;
+ spin_unlock_irq(&pgdat->lru_lock);
+ return NULL;
}
spin_unlock_irq(&pgdat->lru_lock);
+
+ if (!page_mapped(page) || !page_rmapping(page)) {
+ put_page(page);
+ return NULL;
+ }
+
+ *locked = !PageAnon(page) || PageKsm(page);
+ if (*locked && !trylock_page(page)) {
+ put_page(page);
+ return NULL;
+ }
+
return page;
}
@@ -869,26 +886,19 @@ static bool damon_page_mkold(struct page *page, struct vm_area_struct *vma,
static void damon_phys_mkold(unsigned long paddr)
{
- struct page *page = damon_phys_get_page(PHYS_PFN(paddr));
+ bool locked;
+ struct page *page = damon_phys_get_page(PHYS_PFN(paddr), &locked);
struct rmap_walk_control rwc = {
.rmap_one = damon_page_mkold,
.anon_lock = page_lock_anon_vma_read,
};
- bool need_lock;
if (!page)
return;
- if (!page_mapped(page) || !page_rmapping(page))
- return;
-
- need_lock = !PageAnon(page) || PageKsm(page);
- if (need_lock && !trylock_page(page))
- return;
-
rmap_walk(page, &rwc);
- if (need_lock)
+ if (locked)
unlock_page(page);
put_page(page);
}
@@ -930,7 +940,8 @@ static bool damon_page_accessed(struct page *page, struct vm_area_struct *vma,
static bool damon_phys_young(unsigned long paddr, unsigned long *page_sz)
{
- struct page *page = damon_phys_get_page(PHYS_PFN(paddr));
+ bool locked;
+ struct page *page = damon_phys_get_page(PHYS_PFN(paddr), &locked);
struct damon_phys_access_chk_result result = {
.page_sz = PAGE_SIZE,
.accessed = false,
@@ -940,21 +951,13 @@ static bool damon_phys_young(unsigned long paddr, unsigned long *page_sz)
.rmap_one = damon_page_accessed,
.anon_lock = page_lock_anon_vma_read,
};
- bool need_lock;
if (!page)
return false;
- if (!page_mapped(page) || !page_rmapping(page))
- return false;
-
- need_lock = !PageAnon(page) || PageKsm(page);
- if (need_lock && !trylock_page(page))
- return false;
-
rmap_walk(page, &rwc);
- if (need_lock)
+ if (locked)
unlock_page(page);
put_page(page);
--
2.17.1
next prev parent reply other threads:[~2020-08-28 11:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-18 7:24 [RFC v7 00/10] DAMON: Support Physical Memory Address Space Monitoring SeongJae Park
2020-08-18 7:24 ` [RFC v7 01/10] mm/damon/debugfs: Allow users to set initial monitoring target regions SeongJae Park
2020-08-18 7:24 ` [RFC v7 02/10] tools/damon: Support init target regions specification SeongJae Park
2020-08-18 7:24 ` [RFC v7 03/10] mm/damon-test: Add more unit tests for 'init_regions' SeongJae Park
2020-08-18 19:22 ` Brendan Higgins
2020-08-18 7:24 ` [RFC v7 04/10] selftests/damon/_chk_record: Do not check number of gaps SeongJae Park
2020-08-18 7:24 ` [RFC v7 05/10] Docs/admin-guide/mm/damon: Document 'init_regions' feature SeongJae Park
2020-08-18 7:24 ` [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring SeongJae Park
2020-08-20 0:26 ` Shakeel Butt
2020-08-20 7:16 ` SeongJae Park
2020-08-20 13:26 ` Shakeel Butt
2020-08-20 14:28 ` SeongJae Park
2020-08-28 8:11 ` Alkaid
2020-08-28 9:53 ` SeongJae Park
2020-08-28 11:39 ` SeongJae Park [this message]
2020-08-18 7:24 ` [RFC v7 07/10] mm/damon/debugfs: Support " SeongJae Park
2020-08-18 7:24 ` [RFC v7 08/10] tools/damon/record: " SeongJae Park
2020-08-18 7:25 ` [RFC v7 09/10] tools/damon/record: Support NUMA specific recording SeongJae Park
2020-08-18 7:25 ` [RFC v7 10/10] Docs/DAMON: Document physical memory monitoring support SeongJae Park
2020-08-20 1:21 ` [RFC v7 00/10] DAMON: Support Physical Memory Address Space Monitoring Shakeel Butt
2020-08-20 7:10 ` SeongJae Park
2020-08-20 15:44 ` Shakeel Butt
2020-08-20 17:33 ` SeongJae Park
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=20200828113921.15279-1-sjpark@amazon.com \
--to=sjpark@amazon.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=aarcange@redhat.com \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=amit@kernel.org \
--cc=benh@kernel.crashing.org \
--cc=brendan.d.gregg@gmail.com \
--cc=brendanhiggins@google.com \
--cc=cai@lca.pw \
--cc=colin.king@canonical.com \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=dwmw@amazon.com \
--cc=fan.du@intel.com \
--cc=foersleo@amazon.de \
--cc=gthelen@google.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=kirill@shutemov.name \
--cc=linux-damon@amazon.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mark.rutland@arm.com \
--cc=mgorman@suse.de \
--cc=minchan@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sblbir@amazon.com \
--cc=shakeelb@google.com \
--cc=shuah@kernel.org \
--cc=sj38.park@gmail.com \
--cc=sjpark@amazon.de \
--cc=snu@amazon.de \
--cc=vbabka@suse.cz \
--cc=vdavydov.dev@gmail.com \
--cc=yang.shi@linux.alibaba.com \
--cc=ying.huang@intel.com \
--cc=zgf574564920@gmail.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