-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 164402 b: refs/heads/master c: f8af4da h: refs/heads/master v: v3
- Loading branch information
Hugh Dickins
authored and
Linus Torvalds
committed
Sep 22, 2009
1 parent
3c5e8da
commit a49c1c6
Showing
9 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: d19f352484467a5e518639ddff0554669c10ffab | ||
refs/heads/master: f8af4da3b4c14e7267c4ffb952079af3912c51c5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef __LINUX_KSM_H | ||
#define __LINUX_KSM_H | ||
/* | ||
* Memory merging support. | ||
* | ||
* This code enables dynamic sharing of identical pages found in different | ||
* memory areas, even if they are not shared by fork(). | ||
*/ | ||
|
||
#include <linux/bitops.h> | ||
#include <linux/mm.h> | ||
#include <linux/sched.h> | ||
|
||
#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); | ||
void __ksm_exit(struct mm_struct *mm); | ||
|
||
static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) | ||
{ | ||
if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) | ||
return __ksm_enter(mm); | ||
return 0; | ||
} | ||
|
||
static inline void ksm_exit(struct mm_struct *mm) | ||
{ | ||
if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) | ||
__ksm_exit(mm); | ||
} | ||
#else /* !CONFIG_KSM */ | ||
|
||
static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, | ||
unsigned long end, int advice, unsigned long *vm_flags) | ||
{ | ||
return 0; | ||
} | ||
|
||
static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) | ||
{ | ||
return 0; | ||
} | ||
|
||
static inline void ksm_exit(struct mm_struct *mm) | ||
{ | ||
} | ||
#endif /* !CONFIG_KSM */ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Initial dummy version just to illustrate KSM's interface to other files. | ||
*/ | ||
|
||
#include <linux/errno.h> | ||
#include <linux/mman.h> | ||
#include <linux/ksm.h> | ||
|
||
int ksm_madvise(struct vm_area_struct *vma, unsigned long start, | ||
unsigned long end, int advice, unsigned long *vm_flags) | ||
{ | ||
struct mm_struct *mm = vma->vm_mm; | ||
|
||
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_RESERVED | VM_HUGETLB | VM_INSERTPAGE | | ||
VM_MIXEDMAP | VM_SAO)) | ||
return 0; /* just ignore the advice */ | ||
|
||
if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) | ||
if (__ksm_enter(mm) < 0) | ||
return -EAGAIN; | ||
|
||
*vm_flags |= VM_MERGEABLE; | ||
break; | ||
|
||
case MADV_UNMERGEABLE: | ||
if (!(*vm_flags & VM_MERGEABLE)) | ||
return 0; /* just ignore the advice */ | ||
|
||
/* Unmerge any merged pages here */ | ||
|
||
*vm_flags &= ~VM_MERGEABLE; | ||
break; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int __ksm_enter(struct mm_struct *mm) | ||
{ | ||
/* Allocate a structure to track mm and link it into KSM's list */ | ||
set_bit(MMF_VM_MERGEABLE, &mm->flags); | ||
return 0; | ||
} | ||
|
||
void __ksm_exit(struct mm_struct *mm) | ||
{ | ||
/* Unlink and free all KSM's structures which track this mm */ | ||
clear_bit(MMF_VM_MERGEABLE, &mm->flags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters