From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andrea Arcangeli <aarcange@redhat.com>,
Hugh Dickins <hughd@google.com>,
David Rientjes <rientjes@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux Memory Management List <linux-mm@kvack.org>
Subject: [PATCH 03/12] thp: move khugepaged_mutex out of khugepaged
Date: Mon, 13 Aug 2012 19:14:05 +0800 [thread overview]
Message-ID: <5028E17D.3040007@linux.vnet.ibm.com> (raw)
In-Reply-To: <5028E12C.70101@linux.vnet.ibm.com>
Currently, hugepaged_mutex is used really complexly and hard to understand,
actually, it is just used to serialize start_khugepaged and khugepaged for
these reasons:
- khugepaged_thread is shared between them
- the thp disable path (echo never > transparent_hugepage/enabled) is
nonblocking, so we need to protect khugepaged_thread to get a stable
running state
These can be avoided by:
- use the lock to serialize the thread creation and cancel
- thp disable path can not finised until the thread exits
Then khugepaged_thread is fully controlled by start_khugepaged, khugepaged
will be happy without the lock
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
mm/huge_memory.c | 36 +++++++++++++-----------------------
1 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 399e8c9..3715c52 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -139,9 +139,6 @@ static int start_khugepaged(void)
{
int err = 0;
if (khugepaged_enabled()) {
- int wakeup;
-
- mutex_lock(&khugepaged_mutex);
if (!khugepaged_thread)
khugepaged_thread = kthread_run(khugepaged, NULL,
"khugepaged");
@@ -151,15 +148,17 @@ static int start_khugepaged(void)
err = PTR_ERR(khugepaged_thread);
khugepaged_thread = NULL;
}
- wakeup = !list_empty(&khugepaged_scan.mm_head);
- mutex_unlock(&khugepaged_mutex);
- if (wakeup)
+
+ if (!list_empty(&khugepaged_scan.mm_head))
wake_up_interruptible(&khugepaged_wait);
set_recommended_min_free_kbytes();
- } else
+ } else if (khugepaged_thread) {
/* wakeup to exit */
wake_up_interruptible(&khugepaged_wait);
+ kthread_stop(khugepaged_thread);
+ khugepaged_thread = NULL;
+ }
return err;
}
@@ -221,7 +220,12 @@ static ssize_t enabled_store(struct kobject *kobj,
TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG);
if (ret > 0) {
- int err = start_khugepaged();
+ int err;
+
+ mutex_lock(&khugepaged_mutex);
+ err = start_khugepaged();
+ mutex_unlock(&khugepaged_mutex);
+
if (err)
ret = err;
}
@@ -2344,20 +2348,10 @@ static int khugepaged(void *none)
set_freezable();
set_user_nice(current, 19);
- /* serialize with start_khugepaged() */
- mutex_lock(&khugepaged_mutex);
-
- for (;;) {
- mutex_unlock(&khugepaged_mutex);
+ while (!kthread_should_stop()) {
VM_BUG_ON(khugepaged_thread != current);
khugepaged_loop();
VM_BUG_ON(khugepaged_thread != current);
-
- mutex_lock(&khugepaged_mutex);
- if (!khugepaged_enabled())
- break;
- if (unlikely(kthread_should_stop()))
- break;
}
spin_lock(&khugepaged_mm_lock);
@@ -2366,10 +2360,6 @@ static int khugepaged(void *none)
if (mm_slot)
collect_mm_slot(mm_slot);
spin_unlock(&khugepaged_mm_lock);
-
- khugepaged_thread = NULL;
- mutex_unlock(&khugepaged_mutex);
-
return 0;
}
--
1.7.7.6
--
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:[~2012-08-13 11:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-13 11:12 [PATCH 00/12] thp: optimize use of khugepaged_mutex and dependence of CONFIG_NUMA Xiao Guangrong
2012-08-13 11:13 ` [PATCH 01/12] thp: fix the count of THP_COLLAPSE_ALLOC Xiao Guangrong
2012-08-13 11:19 ` Kirill A. Shutemov
2012-08-13 11:13 ` [PATCH 02/12] thp: remove unnecessary check in start_khugepaged Xiao Guangrong
2012-08-13 11:14 ` Xiao Guangrong [this message]
2012-08-13 11:14 ` [PATCH 04/12] thp: remove unnecessary khugepaged_thread check Xiao Guangrong
2012-08-13 11:14 ` [PATCH 05/12] thp: remove wake_up_interruptible in the exit path Xiao Guangrong
2012-08-13 11:15 ` [PATCH 06/12] thp: remove some code depend on CONFIG_NUMA Xiao Guangrong
2012-08-13 11:15 ` [PATCH 07/12] thp: merge page pre-alloc in khugepaged_loop into khugepaged_do_scan Xiao Guangrong
2012-08-13 11:16 ` [PATCH 08/12] thp: release page in page pre-alloc path Xiao Guangrong
2012-08-13 11:16 ` [PATCH 09/12] thp: introduce khugepaged_prealloc_page and khugepaged_alloc_page Xiao Guangrong
2012-09-12 2:03 ` Hugh Dickins
2012-09-12 2:35 ` Xiao Guangrong
2012-09-12 3:37 ` Xiao Guangrong
2012-09-13 6:27 ` Hugh Dickins
2012-09-13 6:33 ` Hugh Dickins
2012-09-13 9:26 ` Xiao Guangrong
2012-08-13 11:16 ` [PATCH 10/12] thp: remove khugepaged_loop Xiao Guangrong
2012-08-13 11:17 ` [PATCH 11/12] thp: use khugepaged_enabled to remove duplicate code Xiao Guangrong
2012-08-13 11:17 ` [PATCH 12/12] thp: remove unnecessary set_recommended_min_free_kbytes Xiao Guangrong
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=5028E17D.3040007@linux.vnet.ibm.com \
--to=xiaoguangrong@linux.vnet.ibm.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.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 NNTP newsgroup(s).