2014-10-25 19:26:40

by Timofey Titovets

[permalink] [raw]
Subject: UKSM: What's maintainers think about it?

Good time of day, people.
I try to find 'mm' subsystem specific people and lists, but list
linux-mm looks dead and mail archive look like deprecated.
If i must to sent this message to another list or add CC people, let me know.

If questions are already asked (i can't find activity before), feel
free to kick me.

The main questions:
1. Somebody test it? I see many reviews about it.
I already port it to latest linux-next-git kernel and its work without issues.
http://pastebin.com/6FMuKagS
(if it matter, i can describe use cases and results, if somebody ask it)

2. Developers of UKSM already tried to merge it? Somebody talked with uksm devs?
offtop: now i try to communicate with dev's on kerneldedup.org forum,
but i have problems with email verification and wait admin
registration approval.
(i already sent questions to
http://kerneldedup.org/forum/home.php?mod=space&username=xianai ,
because him looks like team leader)

3. I just want collect feedbacks from linux maintainers team, if you
decide what UKSM not needed in kernel, all other comments (as i
understand) not matter.

Like KSM, but better.
UKSM - Ultra Kernel Samepage Merging
http://kerneldedup.org/en/projects/uksm/introduction/


2014-10-26 04:31:48

by Andrew Morton

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

On Sat, 25 Oct 2014 22:25:56 +0300 Timofey Titovets <[email protected]> wrote:

> Good time of day, people.
> I try to find 'mm' subsystem specific people and lists, but list
> linux-mm looks dead and mail archive look like deprecated.
> If i must to sent this message to another list or add CC people, let me know.

[email protected] is alive and well.

> If questions are already asked (i can't find activity before), feel
> free to kick me.
>
> The main questions:
> 1. Somebody test it? I see many reviews about it.
> I already port it to latest linux-next-git kernel and its work without issues.
> http://pastebin.com/6FMuKagS
> (if it matter, i can describe use cases and results, if somebody ask it)
>
> 2. Developers of UKSM already tried to merge it? Somebody talked with uksm devs?
> offtop: now i try to communicate with dev's on kerneldedup.org forum,
> but i have problems with email verification and wait admin
> registration approval.
> (i already sent questions to
> http://kerneldedup.org/forum/home.php?mod=space&username=xianai ,
> because him looks like team leader)
>
> 3. I just want collect feedbacks from linux maintainers team, if you
> decide what UKSM not needed in kernel, all other comments (as i
> understand) not matter.
>
> Like KSM, but better.
> UKSM - Ultra Kernel Samepage Merging
> http://kerneldedup.org/en/projects/uksm/introduction/

It's the first I've heard of it. No, as far as I know there has been
no attempt to upstream UKSM.

2014-10-28 13:39:04

by Marco A Benatto

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

Hi All,

I'm not mantainer at all, but I've being using UKSM for a long time and remember
to port it to 3.16 family once.
UKSM seems good and stable and, at least for me, doesn't raised any errors.
AFAIK the only limitation I know (maybe I has been fixed already) it isn't able
to work together with zram stuff due to some race-conditions.

Cheers,

Marco A Benatto
Mandriva OEM Developer


On Sat, Oct 25, 2014 at 09:32:01PM -0700, Andrew Morton wrote:
> On Sat, 25 Oct 2014 22:25:56 +0300 Timofey Titovets <[email protected]> wrote:
>
> > Good time of day, people.
> > I try to find 'mm' subsystem specific people and lists, but list
> > linux-mm looks dead and mail archive look like deprecated.
> > If i must to sent this message to another list or add CC people, let me know.
>
> [email protected] is alive and well.
>
> > If questions are already asked (i can't find activity before), feel
> > free to kick me.
> >
> > The main questions:
> > 1. Somebody test it? I see many reviews about it.
> > I already port it to latest linux-next-git kernel and its work without issues.
> > http://pastebin.com/6FMuKagS
> > (if it matter, i can describe use cases and results, if somebody ask it)
> >
> > 2. Developers of UKSM already tried to merge it? Somebody talked with uksm devs?
> > offtop: now i try to communicate with dev's on kerneldedup.org forum,
> > but i have problems with email verification and wait admin
> > registration approval.
> > (i already sent questions to
> > http://kerneldedup.org/forum/home.php?mod=space&username=xianai ,
> > because him looks like team leader)
> >
> > 3. I just want collect feedbacks from linux maintainers team, if you
> > decide what UKSM not needed in kernel, all other comments (as i
> > understand) not matter.
> >
> > Like KSM, but better.
> > UKSM - Ultra Kernel Samepage Merging
> > http://kerneldedup.org/en/projects/uksm/introduction/
>
> It's the first I've heard of it. No, as far as I know there has been
> no attempt to upstream UKSM.
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to [email protected]. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

2014-10-28 14:00:30

by Timofey Titovets

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

2014-10-28 16:31 GMT+03:00 Marco A Benatto <[email protected]>:
> Hi All,
>
> I'm not mantainer at all, but I've being using UKSM for a long time and remember
> to port it to 3.16 family once.
> UKSM seems good and stable and, at least for me, doesn't raised any errors.
> AFAIK the only limitation I know (maybe I has been fixed already) it isn't able
> to work together with zram stuff due to some race-conditions.
>
> Cheers,
>
> Marco A Benatto
> Mandriva OEM Developer
>

http://kerneldedup.org/forum/forum.php?mod=viewthread&tid=106
As i did find, uksm not conflicting with zram (or zswap - on my system).

---
Offtop:
Why i open up question about UKSM?

May be we (as community, who want to help) can split out UKSM in
"several patches" in independent git repo. For allowing maintainers to
review this.

Is it morally correct?

UKSM code licensed under GPL and as i think we can feel free for port
and adopt code (with indicating the author)

Please, fix me if i mistake or miss something.
This is just stream of my thoughts %_%
---

> On Sat, Oct 25, 2014 at 09:32:01PM -0700, Andrew Morton wrote:
>> On Sat, 25 Oct 2014 22:25:56 +0300 Timofey Titovets <[email protected]> wrote:
>>
>> > Good time of day, people.
>> > I try to find 'mm' subsystem specific people and lists, but list
>> > linux-mm looks dead and mail archive look like deprecated.
>> > If i must to sent this message to another list or add CC people, let me know.
>>
>> [email protected] is alive and well.

So cool, thanks for adding 'mm' to CC.

>> > If questions are already asked (i can't find activity before), feel
>> > free to kick me.
>> >
>> > The main questions:
>> > 1. Somebody test it? I see many reviews about it.
>> > I already port it to latest linux-next-git kernel and its work without issues.
>> > http://pastebin.com/6FMuKagS
>> > (if it matter, i can describe use cases and results, if somebody ask it)
>> >
>> > 2. Developers of UKSM already tried to merge it? Somebody talked with uksm devs?
>> > offtop: now i try to communicate with dev's on kerneldedup.org forum,
>> > but i have problems with email verification and wait admin
>> > registration approval.
>> > (i already sent questions to
>> > http://kerneldedup.org/forum/home.php?mod=space&username=xianai ,
>> > because him looks like team leader)
>> >
>> > 3. I just want collect feedbacks from linux maintainers team, if you
>> > decide what UKSM not needed in kernel, all other comments (as i
>> > understand) not matter.
>> >
>> > Like KSM, but better.
>> > UKSM - Ultra Kernel Samepage Merging
>> > http://kerneldedup.org/en/projects/uksm/introduction/
>>
>> It's the first I've heard of it. No, as far as I know there has been
>> no attempt to upstream UKSM.
>>
>> --
>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>> the body to [email protected]. For more info on Linux MM,
>> see: http://www.linux-mm.org/ .
>> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
Have a nice day,
Timofey.

2014-10-28 16:08:23

by Marco A Benatto

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

On Tue, Oct 28, 2014 at 04:59:45PM +0300, Timofey Titovets wrote:
> 2014-10-28 16:31 GMT+03:00 Marco A Benatto <[email protected]>:
> > Hi All,
> >
> > I'm not mantainer at all, but I've being using UKSM for a long time and remember
> > to port it to 3.16 family once.
> > UKSM seems good and stable and, at least for me, doesn't raised any errors.
> > AFAIK the only limitation I know (maybe I has been fixed already) it isn't able
> > to work together with zram stuff due to some race-conditions.
> >
> > Cheers,
> >
> > Marco A Benatto
> > Mandriva OEM Developer
> >
>
> http://kerneldedup.org/forum/forum.php?mod=viewthread&tid=106
> As i did find, uksm not conflicting with zram (or zswap - on my system).

Interesting,

I've contacted the mantainers to send some patches in April and they said me this:

"The biggest problem between UKSM/KSM and zswap is that pages can be reclaimed so
fast by zswap before UKSM/KSM can have a chance to merge those can be merged.

So one of the ideas that make a direct solution is that:
1. sleep the processes who trigger the zswap
2. wake up the UKSM thread and adjust the scan parameters properly to make it
sample the whole memory in a limited time to judge if there are any VMAs need to
be worked on.
3. If there are those VMAs then merge them at full speed. if there not,
sleep UKSM.
4. Wake up the zswap code pathes and judge that if memory is enough to satisfy
the requests. If there is enough memory then return and redo the memory
allocation.
5. if there is not, then go on to do zswapping.

This is just an outline of ONE of the solutions. It need to be carefully
tweaked. Direct page reclaiming of zswap is a time sensitive code path
, we cannot add too much overhead by doing this,
otherwise it loses its meaning."

> ---
> Offtop:
> Why i open up question about UKSM?
>
> May be we (as community, who want to help) can split out UKSM in
> "several patches" in independent git repo. For allowing maintainers to
> review this.
>
> Is it morally correct?
>
> UKSM code licensed under GPL and as i think we can feel free for port
> and adopt code (with indicating the author)
>
> Please, fix me if i mistake or miss something.
> This is just stream of my thoughts %_%

If there's no problem in do this, and if you don't mind, you can help you
out on this.

Cheers,

> ---
>
> > On Sat, Oct 25, 2014 at 09:32:01PM -0700, Andrew Morton wrote:
> >> On Sat, 25 Oct 2014 22:25:56 +0300 Timofey Titovets <[email protected]> wrote:
> >>
> >> > Good time of day, people.
> >> > I try to find 'mm' subsystem specific people and lists, but list
> >> > linux-mm looks dead and mail archive look like deprecated.
> >> > If i must to sent this message to another list or add CC people, let me know.
> >>
> >> [email protected] is alive and well.
>
> So cool, thanks for adding 'mm' to CC.
>
> >> > If questions are already asked (i can't find activity before), feel
> >> > free to kick me.
> >> >
> >> > The main questions:
> >> > 1. Somebody test it? I see many reviews about it.
> >> > I already port it to latest linux-next-git kernel and its work without issues.
> >> > http://pastebin.com/6FMuKagS
> >> > (if it matter, i can describe use cases and results, if somebody ask it)
> >> >
> >> > 2. Developers of UKSM already tried to merge it? Somebody talked with uksm devs?
> >> > offtop: now i try to communicate with dev's on kerneldedup.org forum,
> >> > but i have problems with email verification and wait admin
> >> > registration approval.
> >> > (i already sent questions to
> >> > http://kerneldedup.org/forum/home.php?mod=space&username=xianai ,
> >> > because him looks like team leader)
> >> >
> >> > 3. I just want collect feedbacks from linux maintainers team, if you
> >> > decide what UKSM not needed in kernel, all other comments (as i
> >> > understand) not matter.
> >> >
> >> > Like KSM, but better.
> >> > UKSM - Ultra Kernel Samepage Merging
> >> > http://kerneldedup.org/en/projects/uksm/introduction/
> >>
> >> It's the first I've heard of it. No, as far as I know there has been
> >> no attempt to upstream UKSM.
> >>
> >> --
> >> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> >> the body to [email protected]. For more info on Linux MM,
> >> see: http://www.linux-mm.org/ .
> >> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
>
> --
> Have a nice day,
> Timofey.

2014-10-28 17:40:21

by Marco A Benatto

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

On Tue, Oct 28, 2014 at 04:59:45PM +0300, Timofey Titovets wrote:
> 2014-10-28 16:31 GMT+03:00 Marco A Benatto <[email protected]>:
> > Hi All,
> >
> > I'm not mantainer at all, but I've being using UKSM for a long time and remember
> > to port it to 3.16 family once.
> > UKSM seems good and stable and, at least for me, doesn't raised any errors.
> > AFAIK the only limitation I know (maybe I has been fixed already) it isn't able
> > to work together with zram stuff due to some race-conditions.
> >
> > Cheers,
> >
> > Marco A Benatto
> > Mandriva OEM Developer
> >
>
> http://kerneldedup.org/forum/forum.php?mod=viewthread&tid=106
> As i did find, uksm not conflicting with zram (or zswap - on my system).

Interesting,

I've contacted the mantainers to send some patches in April and they said me this:

"The biggest problem between UKSM/KSM and zswap is that pages can be reclaimed so
fast by zswap before UKSM/KSM can have a chance to merge those can be merged.

So one of the ideas that make a direct solution is that:
1. sleep the processes who trigger the zswap
2. wake up the UKSM thread and adjust the scan parameters properly to make it
sample the whole memory in a limited time to judge if there are any VMAs need to
be worked on.
3. If there are those VMAs then merge them at full speed. if there not,
sleep UKSM.
4. Wake up the zswap code pathes and judge that if memory is enough to satisfy
the requests. If there is enough memory then return and redo the memory
allocation.
5. if there is not, then go on to do zswapping.

This is just an outline of ONE of the solutions. It need to be carefully
tweaked. Direct page reclaiming of zswap is a time sensitive code path
, we cannot add too much overhead by doing this,
otherwise it loses its meaning."

> ---
> Offtop:
> Why i open up question about UKSM?
>
> May be we (as community, who want to help) can split out UKSM in
> "several patches" in independent git repo. For allowing maintainers to
> review this.
>
> Is it morally correct?
>
> UKSM code licensed under GPL and as i think we can feel free for port
> and adopt code (with indicating the author)
>
> Please, fix me if i mistake or miss something.
> This is just stream of my thoughts %_%
> ---

If there's no problem on that and if you don't mind, I can help you on this.
What dou you think?

Cheers,

> > On Sat, Oct 25, 2014 at 09:32:01PM -0700, Andrew Morton wrote:
> >> On Sat, 25 Oct 2014 22:25:56 +0300 Timofey Titovets <[email protected]> wrote:
> >>
> >> > Good time of day, people.
> >> > I try to find 'mm' subsystem specific people and lists, but list
> >> > linux-mm looks dead and mail archive look like deprecated.
> >> > If i must to sent this message to another list or add CC people, let me know.
> >>
> >> [email protected] is alive and well.
>
> So cool, thanks for adding 'mm' to CC.
>
> >> > If questions are already asked (i can't find activity before), feel
> >> > free to kick me.
> >> >
> >> > The main questions:
> >> > 1. Somebody test it? I see many reviews about it.
> >> > I already port it to latest linux-next-git kernel and its work without issues.
> >> > http://pastebin.com/6FMuKagS
> >> > (if it matter, i can describe use cases and results, if somebody ask it)
> >> >
> >> > 2. Developers of UKSM already tried to merge it? Somebody talked with uksm devs?
> >> > offtop: now i try to communicate with dev's on kerneldedup.org forum,
> >> > but i have problems with email verification and wait admin
> >> > registration approval.
> >> > (i already sent questions to
> >> > http://kerneldedup.org/forum/home.php?mod=space&username=xianai ,
> >> > because him looks like team leader)
> >> >
> >> > 3. I just want collect feedbacks from linux maintainers team, if you
> >> > decide what UKSM not needed in kernel, all other comments (as i
> >> > understand) not matter.
> >> >
> >> > Like KSM, but better.
> >> > UKSM - Ultra Kernel Samepage Merging
> >> > http://kerneldedup.org/en/projects/uksm/introduction/
> >>
> >> It's the first I've heard of it. No, as far as I know there has been
> >> no attempt to upstream UKSM.
> >>
> >> --
> >> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> >> the body to [email protected]. For more info on Linux MM,
> >> see: http://www.linux-mm.org/ .
> >> Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
>
> --
> Have a nice day,
> Timofey.

2014-10-28 21:37:10

by Timofey Titovets

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

2014-10-28 20:40 GMT+03:00 Marco A Benatto <[email protected]>:
> On Tue, Oct 28, 2014 at 04:59:45PM +0300, Timofey Titovets wrote:
>> 2014-10-28 16:31 GMT+03:00 Marco A Benatto <[email protected]>:
>> > Hi All,
>> >
>> > I'm not mantainer at all, but I've being using UKSM for a long time and remember
>> > to port it to 3.16 family once.
>> > UKSM seems good and stable and, at least for me, doesn't raised any errors.
>> > AFAIK the only limitation I know (maybe I has been fixed already) it isn't able
>> > to work together with zram stuff due to some race-conditions.
>> >
>> > Cheers,
>> >
>> > Marco A Benatto
>> > Mandriva OEM Developer
>> >
>>
>> http://kerneldedup.org/forum/forum.php?mod=viewthread&tid=106
>> As i did find, uksm not conflicting with zram (or zswap - on my system).
>
> Interesting,
>
> I've contacted the mantainers to send some patches in April and they said me this:
>
> "The biggest problem between UKSM/KSM and zswap is that pages can be reclaimed so
> fast by zswap before UKSM/KSM can have a chance to merge those can be merged.
>
> So one of the ideas that make a direct solution is that:
> 1. sleep the processes who trigger the zswap
> 2. wake up the UKSM thread and adjust the scan parameters properly to make it
> sample the whole memory in a limited time to judge if there are any VMAs need to
> be worked on.
> 3. If there are those VMAs then merge them at full speed. if there not,
> sleep UKSM.
> 4. Wake up the zswap code pathes and judge that if memory is enough to satisfy
> the requests. If there is enough memory then return and redo the memory
> allocation.
> 5. if there is not, then go on to do zswapping.
>
> This is just an outline of ONE of the solutions. It need to be carefully
> tweaked. Direct page reclaiming of zswap is a time sensitive code path
> , we cannot add too much overhead by doing this,
> otherwise it loses its meaning."
>
>> ---
>> Offtop:
>> Why i open up question about UKSM?
>>
>> May be we (as community, who want to help) can split out UKSM in
>> "several patches" in independent git repo. For allowing maintainers to
>> review this.
>>
>> Is it morally correct?
>>
>> UKSM code licensed under GPL and as i think we can feel free for port
>> and adopt code (with indicating the author)
>>
>> Please, fix me if i mistake or miss something.
>> This is just stream of my thoughts %_%
>> ---
>
> If there's no problem on that and if you don't mind, I can help you on this.
> What dou you think?

So cool, lets do it =3
https://github.com/Nefelim4ag/linux-uksm I've created a temporary
git-repository.
I am trying to split one big patch into several independent patches.
Patch is attached to e-mail.

Perhaps we can move conversation to personal emails(for you - to working)?

> Cheers,
>
> Marco A Benatto
> Mandriva OEM Developer

--
Have a nice day,
Timofey.


Attachments:
0002-uksm-0.1.2.3-for-linux-next-20141016.ge.1.patch (174.39 kB)

2014-10-30 03:19:15

by Matt

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

Hi Timofey,

Hi List,


don't forget to consider PKSM - it's supposed to be an improvement
over UKSM & KSM:

http://www.phoronix.com/scan.php?page=news_item&px=MTM0OTQ

https://code.google.com/p/pksm/


Kind Regards

Matt

2014-10-30 04:40:48

by Timofey Titovets

[permalink] [raw]
Subject: Re: UKSM: What's maintainers think about it?

2014-10-30 6:19 GMT+03:00 Matt <[email protected]>:
> Hi Timofey,
> Hi List,
> don't forget to consider PKSM - it's supposed to be an improvement
> over UKSM & KSM:
>
> http://www.phoronix.com/scan.php?page=news_item&px=MTM0OTQ
> https://code.google.com/p/pksm/
>
> Kind Regards
>
> Matt

I can mistaking, as i know UKSM use some (or full?) PKSM code.
As example uksm have (by Figo.zhang dev of PKSM)
Full Zero Page consideration (i can't find proof link now)

--
Have a nice day,
Timofey.

2014-11-08 00:58:15

by Timofey Titovets

[permalink] [raw]
Subject: [RFC PATCH] KSM: Auto add flag new VMA as VM_MERGEABLE

Hi list.

This is a small patch what allow ksm dedupe "whole" system memory.
I think what people with tiny pc and android developers will be happy
after this patch.
I just like clear memory =].

I have tested it and it working very good. For testing apply it and
enable ksm:
echo 1 | sudo tee /sys/kernel/mm/ksm/run
This show how much memory saved:
echo $[$(cat /sys/kernel/mm/ksm/pages_shared)*$(getconf PAGE_SIZE)/1024 ]KB

(i use linux-next-git 20141031)

It add very small overhead to mmap call's.

Please check my code, may be i should move new functions to other file?
I think about sysfs switcher like:
/sys/kernel/mm/ksm/mark_new_vma # 0 or 1 if 1 new vma will be marked
like VM_MERGEABLE.

Can you advise me something?

I implement 2 new functions:
ksm_vm_flags_mod() - working only in mm/mmap.c file, change default flags
ksm_vma_add_new() - add new created vma to ksm internal tree

If you see broken patch lines i have also attach patch.

From db8ad0877146a69e1e5d5ab98825cefcf44a95bb Mon Sep 17 00:00:00 2001
From: Timofey Titovets <[email protected]>
Date: Sat, 8 Nov 2014 03:02:52 +0300
Subject: [PATCH] KSM: Add auto flag new VMA as VM_MERGEABLE

Signed-off-by: Timofey Titovets <[email protected]>
---
include/linux/ksm.h | 31 +++++++++++++++++++++++++++++++
mm/mmap.c | 17 +++++++++++++++++
2 files changed, 48 insertions(+)

diff --git a/include/linux/ksm.h b/include/linux/ksm.h
index 3be6bb1..c3fff64 100644
--- a/include/linux/ksm.h
+++ b/include/linux/ksm.h
@@ -76,6 +76,29 @@ struct page *ksm_might_need_to_copy(struct page *page,
int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
void ksm_migrate_page(struct page *newpage, struct page *oldpage);

+/*
+ * Allow to mark new vma as VM_MERGEABLE
+ */
+#ifndef VM_SAO
+#define VM_SAO 0
+#endif
+static inline void ksm_vm_flags_mod(unsigned long *vm_flags)
+{
+ if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE |
+ VM_PFNMAP | VM_IO | VM_DONTEXPAND |
+ VM_HUGETLB | VM_NONLINEAR | VM_MIXEDMAP | VM_SAO) )
+ return;
+ *vm_flags |= VM_MERGEABLE;
+}
+
+static inline void ksm_vma_add_new(struct vm_area_struct *vma)
+{
+ struct mm_struct *mm = vma->vm_mm;
+ if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) {
+ __ksm_enter(mm);
+ }
+}
+
#else /* !CONFIG_KSM */

static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
@@ -92,6 +115,14 @@ static inline int PageKsm(struct page *page)
return 0;
}

+static inline void ksm_vm_flags_mod(unsigned long *vm_flags_p)
+{
+}
+
+void ksm_vma_add_new(struct vm_area_struct *vma)
+{
+}
+
#ifdef CONFIG_MMU
static inline int ksm_madvise(struct vm_area_struct *vma, unsigned
long start,
unsigned long end, int advice, unsigned long *vm_flags)
diff --git a/mm/mmap.c b/mm/mmap.c
index 7f85520..ce0073e 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -41,6 +41,7 @@
#include <linux/notifier.h>
#include <linux/memory.h>
#include <linux/printk.h>
+#include <linux/ksm.h>

#include <asm/uaccess.h>
#include <asm/cacheflush.h>
@@ -911,10 +912,14 @@ again: remove_next = 1 + (end > next->vm_end);
vma_gap_update(next);
else
mm->highest_vm_end = end;
+ } else {
+ if (next && !insert)
+ ksm_vma_add_new(next);
}
if (insert && file)
uprobe_mmap(insert);

+ ksm_vma_add_new(vma);
validate_mm(mm);

return 0;
@@ -1307,6 +1312,9 @@ unsigned long do_mmap_pgoff(struct file *file,
unsigned long addr,
vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;

+ /* If ksm is enabled, we add VM_MERGABLE to new VMAs. */
+ ksm_vm_flags_mod(&vm_flags);
+
if (flags & MAP_LOCKED)
if (!can_do_mlock())
return -EPERM;
@@ -1648,6 +1656,7 @@ munmap_back:
allow_write_access(file);
}
file = vma->vm_file;
+ ksm_vma_add_new(vma);
out:
perf_event_mmap(vma);

@@ -2484,6 +2493,8 @@ static int __split_vma(struct mm_struct *mm,
struct vm_area_struct *vma,
else
err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);

+ ksm_vma_add_new(vma);
+
/* Success. */
if (!err)
return 0;
@@ -2659,6 +2670,9 @@ static unsigned long do_brk(unsigned long addr,
unsigned long len)
if (error)
return error;

+ /* If ksm is enabled, we add VM_MERGABLE to new VMAs. */
+ ksm_vm_flags_mod(&flags);
+
/*
* mm->mmap_sem is required to protect against another thread
* changing the mappings in case we sleep.
@@ -2708,6 +2722,7 @@ static unsigned long do_brk(unsigned long addr,
unsigned long len)
vma->vm_flags = flags;
vma->vm_page_prot = vm_get_page_prot(flags);
vma_link(mm, vma, prev, rb_link, rb_parent);
+ ksm_vma_add_new(vma);
out:
perf_event_mmap(vma);
mm->total_vm += len >> PAGE_SHIFT;
@@ -2887,6 +2902,7 @@ struct vm_area_struct *copy_vma(struct
vm_area_struct **vmap,
new_vma->vm_ops->open(new_vma);
vma_link(mm, new_vma, prev, rb_link, rb_parent);
*need_rmap_locks = false;
+ ksm_vma_add_new(new_vma);
}
}
return new_vma;
@@ -3004,6 +3020,7 @@ static struct vm_area_struct
*__install_special_mapping(
mm->total_vm += len >> PAGE_SHIFT;

perf_event_mmap(vma);
+ ksm_vma_add_new(vma);

return vma;

--
2.1.3


Attachments:
0001-KSM-Add-auto-flag-new-VMA-as-VM_MERGEABLE.patch (4.12 kB)