From: Oleksandr Natalenko <oleksandr@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>,
Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
Matthew Wilcox <willy@infradead.org>,
Pavel Tatashin <pasha.tatashin@oracle.com>,
Timofey Titovets <nefelim4ag@gmail.com>,
Aaron Tomlin <atomlin@redhat.com>,
linux-mm@kvack.org
Subject: [PATCH RFC 1/4] mm/ksm: introduce ksm_enter() helper
Date: Fri, 10 May 2019 09:21:22 +0200 [thread overview]
Message-ID: <20190510072125.18059-2-oleksandr@redhat.com> (raw)
In-Reply-To: <20190510072125.18059-1-oleksandr@redhat.com>
Move MADV_MERGEABLE part of ksm_madvise() into a dedicated helper since
it will be further used in do_anonymous_page().
This does not bring any functional changes.
Signed-off-by: Oleksandr Natalenko <oleksandr@redhat.com>
---
include/linux/ksm.h | 2 ++
mm/ksm.c | 66 ++++++++++++++++++++++++++-------------------
2 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/include/linux/ksm.h b/include/linux/ksm.h
index e48b1e453ff5..bc13f228e2ed 100644
--- a/include/linux/ksm.h
+++ b/include/linux/ksm.h
@@ -21,6 +21,8 @@ struct mem_cgroup;
#ifdef CONFIG_KSM
int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
unsigned long end, int advice, unsigned long *vm_flags);
+int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long *vm_flags);
int __ksm_enter(struct mm_struct *mm);
void __ksm_exit(struct mm_struct *mm);
diff --git a/mm/ksm.c b/mm/ksm.c
index fc64874dc6f4..a6b0788a3a22 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2450,33 +2450,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
switch (advice) {
case MADV_MERGEABLE:
- /*
- * Be somewhat over-protective for now!
- */
- if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE |
- VM_PFNMAP | VM_IO | VM_DONTEXPAND |
- VM_HUGETLB | VM_MIXEDMAP))
- return 0; /* just ignore the advice */
-
- if (vma_is_dax(vma))
- return 0;
-
-#ifdef VM_SAO
- if (*vm_flags & VM_SAO)
- return 0;
-#endif
-#ifdef VM_SPARC_ADI
- if (*vm_flags & VM_SPARC_ADI)
- return 0;
-#endif
-
- if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) {
- err = __ksm_enter(mm);
- if (err)
- return err;
- }
-
- *vm_flags |= VM_MERGEABLE;
+ err = ksm_enter(mm, vma, vm_flags);
+ if (err)
+ return err;
break;
case MADV_UNMERGEABLE:
@@ -2496,6 +2472,42 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
return 0;
}
+int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long *vm_flags)
+{
+ int err;
+
+ /*
+ * Be somewhat over-protective for now!
+ */
+ if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE |
+ VM_PFNMAP | VM_IO | VM_DONTEXPAND |
+ VM_HUGETLB | VM_MIXEDMAP))
+ return 0; /* just ignore the advice */
+
+ if (vma_is_dax(vma))
+ return 0;
+
+#ifdef VM_SAO
+ if (*vm_flags & VM_SAO)
+ return 0;
+#endif
+#ifdef VM_SPARC_ADI
+ if (*vm_flags & VM_SPARC_ADI)
+ return 0;
+#endif
+
+ if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) {
+ err = __ksm_enter(mm);
+ if (err)
+ return err;
+ }
+
+ *vm_flags |= VM_MERGEABLE;
+
+ return 0;
+}
+
int __ksm_enter(struct mm_struct *mm)
{
struct mm_slot *mm_slot;
--
2.21.0
next prev parent reply other threads:[~2019-05-10 7:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-10 7:21 [PATCH RFC 0/4] mm/ksm: add option to automerge VMAs Oleksandr Natalenko
2019-05-10 7:21 ` Oleksandr Natalenko [this message]
2019-05-10 7:21 ` [PATCH RFC 2/4] mm/ksm: introduce VM_UNMERGEABLE Oleksandr Natalenko
2019-05-10 7:21 ` [PATCH RFC 3/4] mm/ksm: allow anonymous memory automerging Oleksandr Natalenko
2019-05-10 7:21 ` [PATCH RFC 4/4] mm/ksm: add automerging documentation Oleksandr Natalenko
2019-05-13 10:38 ` [PATCH RFC 0/4] mm/ksm: add option to automerge VMAs Kirill Tkhai
2019-05-13 11:33 ` Oleksandr Natalenko
2019-05-13 11:48 ` Timofey Titovets
2019-05-13 12:01 ` Oleksandr Natalenko
2019-05-13 12:06 ` Oleksandr Natalenko
2019-05-13 12:37 ` Kirill Tkhai
2019-05-14 6:30 ` Oleksandr Natalenko
2019-05-14 9:12 ` Kirill Tkhai
2019-05-14 13:33 ` Oleksandr Natalenko
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=20190510072125.18059-2-oleksandr@redhat.com \
--to=oleksandr@redhat.com \
--cc=atomlin@redhat.com \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=nefelim4ag@gmail.com \
--cc=pasha.tatashin@oracle.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.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).