Subsystems (5)
This patch was done after Linus requested it when I intended to split madvice out of filemap.c. We extend splitvma() in mmap.c to take another argument that specifies whether to split above or below the address given, and thus can use it in those function, cleaning them up a lot and removing most of their code.
You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.
===================================================================
[email protected], 2002-08-17 23:43:39+02:00, [email protected]
VM: split madvice(2) into a separate source file
Makefile | 2 filemap.c | 332 ------------------------------------------------------------ madvise.c | 340 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 342 insertions, 332 deletions
mm/Makefile +1 -1
@@ -16,6 +16,6 @@ vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o \ page_alloc.o swap_state.o swapfile.o numa.o oom_kill.o \ shmem.o highmem.o mempool.o msync.o mincore.o readahead.o \ - pdflush.o page-writeback.o rmap.o + pdflush.o page-writeback.o rmap.o madvise.o include $(TOPDIR)/Rules.make
mm/filemap.c +1 -331
338 lines not on this page · raw message
mm/madvise.c new file +340 -0
340 lines not on this page · raw message
===================================================================
This BitKeeper patch contains the following changesets:
1.490
## Wrapped with gzip_uu ##
begin 664 bkpatch7649 M'XL(`$?$7CT``\U:>U/;2!+_V_H4L[M564.PL6P#-@0N#CB)BU<.2';K+E>J ML32VM98T6CT@SI'[[-?=,Y(E/P+DDKHE*8/FT=//7_>T]0M['XMHOS*Q)\8O M[*V,D_U*/*P/8T<&GAN(NHS&,'$E)4QL1R*4VS"<?JHUZSL&3+SCB3UAMR** M]RMFO96/)+-0[%>N^F_>G_6N#./PD!U/>#6UR)AAX=&(J-;[CGQ2YY,/!G4 MDX@'L2\27K>E?Y\OO6\V&DWXMV/NM1H[N_?F;J.]=V^;CFGRMBF<1K/=V6T; MMSQP(GDK7M[:=?LV3>KVYT4:'7.WV=K9:S3OF[L=LV6<,+/>[C98H[G=Z&R; M>ZS9VF^W]EO=YXWF?J/!0!\O%_7GK=8K6&\8M^7^V/#9A_.]UD<>F["?.[< MNK:H-C>8&R22<1:+D$<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;LVK3;Q&5@\.5+L1[OS7"<*R4LP+HD:T"E6,[FQ6\A80M0)+PB.AMR+K MFP&=0M-$TYL;\\6JIFAER8$*!^=-GM)&:GF63B_W\%\</L.V7Y5$[;(ZWQT MJ31$)2]6KEFOJMRN5<?A]@VUH.#`%:H*<^)E/1P8"XN?+O!*JZX3H;!OH0@O M2U!D:=$X"C*T-V:#@?B4Z%XN;(,R.0T?0H"E.EF_$Y>]./?P2Z1/?EG/X-/0 M?_G9#7%[G:?+%/;,KMEI=)KM^UUS9Z>CWN5J/?%E+I/5S!_R#BDES,RX=8GY M5@[_J,V,4Z9>*UQ^PRL3[QM>\#HQN\PT!O1)=^K0H=L]'$S%]D7VQ@P$.'+ M5W+.6F;,_'W01UGSB6^[email protected]:WW6JW[YO=EKFK[-GL/-V@K=:/,FDD M?$@<Q;>"\=IW4N\ET%*(?/BZ[/+YLW%_2;[MO:Z#4;F'L-M'+Y]3A=!J"M MV::EOK12G5T<RCH6.L%9<8C=HDW]1>76_,UQV&!/X]0_%*.])M_AN\9_>NF &_X:2+@``
`
end
--
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/
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Christoph Hellwig
This patch was done after Linus requested it when I intended to split madvice out of
filemap.c. We extendsplitvma()inmmap.cto take another argument that specifies whether to split above or below the address given, and thus can use it in those function, cleaning them up a lot and removing most of their code.
Quoted 3 lines
This description seems to have leaked from a different patch.
Your patch purely shuffles code about, yes?
No. it makes madvise/mlock/mprotect use slit_vma (that involved from splitvma). There is no change in behaviour (verified by ltp testruns), but the implementation is very different, and lots of code is gone.
--
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/
Quoted 7 lines · Christoph Hellwig
This patch was done after Linus requested it when I intended to split madvice out of
filemap.c. We extendsplitvma()inmmap.cto take another argument that specifies whether to split above or below the address given, and thus can use it in those function, cleaning them up a lot and removing most of their code.
This description seems to have leaked from a different patch.
Your patch purely shuffles code about, yes?
--
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/
Quoted 26 lines · Andrew Morton
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Christoph Hellwig
This patch was done after Linus requested it when I intended to split madvice out of
filemap.c. We extendsplitvma()inmmap.cto take another argument that specifies whether to split above or below the address given, and thus can use it in those function, cleaning them up a lot and removing most of their code.Quoted 7 lines
Quoted 3 lines
This description seems to have leaked from a different patch.
Your patch purely shuffles code about, yes?
No. it makes madvise/mlock/mprotect use
slit_vma(that involved from splitvma). There is no change in behaviour (verified by ltp testruns), but the implementation is very different, and lots of code is gone.did you send the right patch?
mnm:/usr/src/25> grep split
patches/madvise-move.patch
- * We can potentially split a vm area into separate
+ * We can potentially split a vm area into separate
Quoted 5 lines
mnm:/usr/src/25> diffstat
patches/madvise-move.patchMakefile | 2 filemap.c | 332 ------------------------------------------------------------ madvise.c | 340 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 342 insertions(+), 332 deletions(-)
Sorry, that was the first patch I sent to Linus before I did the changes I explained..
Here's the right one:
include/linux/mm.h | 7 - mm/Makefile | 2 mm/filemap.c | 332 ----------------------------------------------------- mm/madvise.c | 238 +++++++++++++++++++++++++++++++++++++ mm/mlock.c | 158 ++++--------------------- mm/mmap.c | 37 +++-- mm/mprotect.c | 218 +++++++++++----------------------- 7 files changed, 365 insertions, 627 deletions
include/linux/mm.h +4 -3
@@ -483,6 +483,7 @@extern struct vm_area_struct *find_vma (struct mm_struct * mm,unsigned long addr);extern struct vm_area_struct *find_vma_prev (struct mm_struct * mm,unsigned long addr,struct vm_area_struct **pprev); +extern struct vm_area_struct *find_extend_vma (struct mm_struct * mm,unsigned long addr);/* Look up the first VMA which intersects the interval start_addr..end_addr-1, NULL if none. Assume start_addr < end_addr. */
@@ -495,11 +496,11 @@return vma; } -extern struct vm_area_struct *find_extend_vma (struct mm_struct *mm,unsigned long addr); +extern int split_vma (struct mm_struct * mm,struct vm_area_struct * vma, +unsigned long addr,int new_below);extern struct page *vmalloc_to_page (void *addr);extern unsigned long get_page_cache_size (void );#endif /* __KERNEL__ */ - -#endif +#endif /* _LINUX_MM_H */
mm/Makefile +1 -1
@@ -16,6 +16,6 @@ vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o \ page_alloc.o swap_state.o swapfile.o numa.o oom_kill.o \ shmem.o highmem.o mempool.o msync.o mincore.o readahead.o \ - pdflush.o page-writeback.o rmap.o + pdflush.o page-writeback.o rmap.o madvise.o include $(TOPDIR)/Rules.make
mm/filemap.c +1 -331
338 lines not on this page · raw message
mm/mlock.c +30 -128
177 lines not on this page · raw message
mm/mmap.c +22 -15
@@ -1043,10 +1043,11 @@ }/* -* Split a vma into two pieces at address 'addr', the original vma -* will contain the first part, a new vma is allocated for the tail. +* Split a vma into two pieces at address 'addr', a new vma is allocated +* either for the first part or the the tail. */ -static int splitvma (struct mm_struct *mm,struct vm_area_struct *mpnt,unsigned long addr) +int split_vma (struct mm_struct * mm,struct vm_area_struct * vma, +unsigned long addr,int new_below) {struct vm_area_struct *new;
@@ -1058,22 +1059,28 @@return -ENOMEM ;/* most fields are the same, copy all, and then fixup */ - *new = *mpnt; + *new = *vma; + +if (new_below) { + vma->vm_start = new->vm_end = addr; + vma->vm_pgoff += ((addr - vma->vm_start) >>PAGE_SHIFT ); + }else { + new->vm_start = vma->vm_end = addr; + new->vm_pgoff += ((addr - vma->vm_start) >>PAGE_SHIFT ); + } - new->vm_start = addr; - new->vm_pgoff = mpnt->vm_pgoff + ((addr - mpnt->vm_start) >>PAGE_SHIFT ); new->vm_raend =0 ; -if (mpnt->vm_file) -get_file (mpnt->vm_file); -if (mpnt->vm_ops && mpnt->vm_ops->open) - mpnt->vm_ops->open (mpnt); - mpnt->vm_end = addr;/* Truncate area */ +if (new->vm_file) +get_file (new->vm_file); + +if (new->vm_ops && new->vm_ops->open) + new->vm_ops->open (new);spin_lock (&mm->page_table_lock); -lock_vma_mappings (mpnt); +lock_vma_mappings (vma);__insert_vm_struct (mm, new); -unlock_vma_mappings (mpnt); +unlock_vma_mappings (vma);spin_unlock (&mm->page_table_lock);return 0 ;
@@ -1110,7 +1117,7 @@* If we need to split any vma, do it now to save pain later. */ if (start > mpnt->vm_start) { -if (splitvma (mm, mpnt, start)) +if (split_vma (mm, mpnt, start,0 ))return -ENOMEM ; prev = mpnt; mpnt = mpnt->vm_next;
@@ -1119,7 +1126,7 @@/* Does it split the last one? */ last =find_vma (mm, end);if (last && end > last->vm_start) { -if (splitvma (mm, last, end)) +if (split_vma (mm, last, end,0 ))return -ENOMEM ; }
mm/mprotect.c +69 -149
275 lines not on this page · raw message
mm/madvise.c Sun Aug 18 14:28:08 2002 renamed from mm/madvise.c +238 -0
238 lines not on this page · raw message
--
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/
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Christoph Hellwig
This patch was done after Linus requested it when I intended to split madvice out of
filemap.c. We extendsplitvma()inmmap.cto take another argument that specifies whether to split above or below the address given, and thus can use it in those function, cleaning them up a lot and removing most of their code.
Quoted 7 lines
Quoted 3 lines
This description seems to have leaked from a different patch.
Your patch purely shuffles code about, yes?
No. it makes madvise/mlock/mprotect use
slit_vma(that involved from splitvma). There is no change in behaviour (verified by ltp testruns), but the implementation is very different, and lots of code is gone.
did you send the right patch?
mnm:/usr/src/25> grep split patches/madvise-move.patch
- * We can potentially split a vm area into separate
+ * We can potentially split a vm area into separate
mnm:/usr/src/25> diffstat patches/madvise-move.patch
Makefile | 2 filemap.c | 332 ------------------------------------------------------------ madvise.c | 340 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 342 insertions(+), 332 deletions(-)
--
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/
Quoted 10 lines · Christoph Hellwig
...
include/linux/mm.h | 7 - mm/Makefile | 2 mm/filemap.c | 332 ----------------------------------------------------- mm/madvise.c | 238 +++++++++++++++++++++++++++++++++++++ mm/mlock.c | 158 ++++--------------------- mm/mmap.c | 37 +++-- mm/mprotect.c | 218 +++++++++++----------------------- 7 files changed, 365 insertions, 627 deletions
It's nice to keep the file movement and the functional changes in separate patches. Makes it easier to understand what has
been changed. I have done that split. (Took 30 seconds. Do
that with bitkeeper ;))
Review
Quoted 8 lines
static int mlock_fixup(struct
vm_area_struct* vma,
unsigned long start, unsigned long end, unsigned int newflags)
{
...(quoted diff) +4
-0+ + spin_lock(&mm->page_table_lock); + vma->vm_flags = newflags; + spin_unlock(&mm->page_table_lock);
hrm. What's being locked here?
Review
Quoted 12 lines
...
(quoted diff) +4
-3-static int splitvma(struct mm_struct *mm, struct vm_area_struct *mpnt, unsigned long addr) +int split_vma(struct mm_struct * mm, struct vm_area_struct * vma, + unsigned long addr, int new_below) spin_lock(&mm->page_table_lock); - lock_vma_mappings(mpnt); + lock_vma_mappings(vma); __insert_vm_struct(mm, new); - unlock_vma_mappings(mpnt); + unlock_vma_mappings(vma); spin_unlock(&mm->page_table_lock);
OK, split_vma() has the same rank ordering bug as vma_link(). i_shared_lock should nest outside page_table_lock. That's how vmtruncate does it, and it seems to be a logical ranking to me.
I don't know why vma_link() takes page_table_lock at all. But then, I don't know what page_table_lock actually locks, apart from page tables. It's all very weird.
Could you please fix up this, fix up vma_link, do a little audit of the other paths which play with these locks and update the locking comment in filemap.c?
Generally: I'm going to need a lot of help understanding what this patch does, and why it does it. Could you prepare a little description of that?
I've attached the separated diffs here - I'll do a 2.5.33-mm1 today, including these diffs. That should make syncing up easier.
Patch from Christoph Hellwig moves the madvise implementation out of filemap.c and into its own .c file. No other changes are made.
Makefile | 2 filemap.c | 332 ------------------------------------------------------------ madvise.c | 340 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 342 insertions(+), 332 deletions(-)
mm/filemap.c renamed from mm/filemap.c~madvise-move +1 -331
@@ -1443,337 +1443,7 @@ int generic_file_mmap(struct file * filereturn 0 ; } -static inline void setup_read_behavior (struct vm_area_struct * vma, -int behavior) -{ -VM_ClearReadHint (vma); -switch (behavior) { -case MADV_SEQUENTIAL : - vma->vm_flags |=VM_SEQ_READ ; -break ; -case MADV_RANDOM : - vma->vm_flags |=VM_RAND_READ ; -break ; -default : -break ; - } -return ; -} - -static long madvise_fixup_start (struct vm_area_struct * vma, -unsigned long end,int behavior) -{ -struct vm_area_struct * n; -struct mm_struct * mm = vma->vm_mm; - - n =kmem_cache_alloc (vm_area_cachep,SLAB_KERNEL ); -if (!n) -return -EAGAIN ; - *n = *vma; - n->vm_end = end; -setup_read_behavior (n, behavior); - n->vm_raend =0 ; -if (n->vm_file) -get_file (n->vm_file); -if (n->vm_ops && n->vm_ops->open) - n->vm_ops->open (n); - vma->vm_pgoff += (end - vma->vm_start) >>PAGE_SHIFT ; -lock_vma_mappings (vma); -spin_lock (&mm->page_table_lock); - vma->vm_start = end; -__insert_vm_struct (mm, n); -spin_unlock (&mm->page_table_lock); -unlock_vma_mappings (vma); -return 0 ; -} - -static long madvise_fixup_end (struct vm_area_struct * vma, -unsigned long start,int behavior) -{ -struct vm_area_struct * n; -struct mm_struct * mm = vma->vm_mm; - - n =kmem_cache_alloc (vm_area_cachep,SLAB_KERNEL ); -if (!n) -return -EAGAIN ; - *n = *vma; - n->vm_start = start; - n->vm_pgoff += (n->vm_start - vma->vm_start) >>PAGE_SHIFT ; -setup_read_behavior (n, behavior); - n->vm_raend =0 ; -if (n->vm_file) -get_file (n->vm_file); -if (n->vm_ops && n->vm_ops->open) - n->vm_ops->open (n); -lock_vma_mappings (vma); -spin_lock (&mm->page_table_lock); - vma->vm_end = start; -__insert_vm_struct (mm, n); -spin_unlock (&mm->page_table_lock); -unlock_vma_mappings (vma); -return 0 ; -} - -static long madvise_fixup_middle (struct vm_area_struct * vma, -unsigned long start,unsigned long end,int behavior) -{ -struct vm_area_struct * left, * right; -struct mm_struct * mm = vma->vm_mm; - - left =kmem_cache_alloc (vm_area_cachep,SLAB_KERNEL ); -if (!left) -return -EAGAIN ; - right =kmem_cache_alloc (vm_area_cachep,SLAB_KERNEL ); -if (!right) { -kmem_cache_free (vm_area_cachep, left); -return -EAGAIN ; - } - *left = *vma; - *right = *vma; - left->vm_end = start; - right->vm_start = end; - right->vm_pgoff += (right->vm_start - left->vm_start) >>PAGE_SHIFT ; - left->vm_raend =0 ; - right->vm_raend =0 ; -if (vma->vm_file) -atomic_add (2 , &vma->vm_file->f_count); - -if (vma->vm_ops && vma->vm_ops->open) { - vma->vm_ops->open (left); - vma->vm_ops->open (right); - } - vma->vm_pgoff += (start - vma->vm_start) >>PAGE_SHIFT ; - vma->vm_raend =0 ; -lock_vma_mappings (vma); -spin_lock (&mm->page_table_lock); - vma->vm_start = start; - vma->vm_end = end; -setup_read_behavior (vma, behavior); -__insert_vm_struct (mm, left); -__insert_vm_struct (mm, right); -spin_unlock (&mm->page_table_lock); -unlock_vma_mappings (vma); -return 0 ; -} - -/* -* We can potentially split a vm area into separate -* areas, each area with its own behavior. -*/ -static long madvise_behavior (struct vm_area_struct * vma, -unsigned long start,unsigned long end,int behavior) -{ -int error =0 ; - -/* This caps the number of vma's this process can own */ -if (vma->vm_mm->map_count >MAX_MAP_COUNT ) -return -ENOMEM ; - -if (start == vma->vm_start) { -if (end == vma->vm_end) { -setup_read_behavior (vma, behavior); - vma->vm_raend =0 ; - }else - error =madvise_fixup_start (vma, end, behavior); - }else { -if (end == vma->vm_end) - error =madvise_fixup_end (vma, start, behavior); -else - error =madvise_fixup_middle (vma, start, end, behavior); - } - -return error; -} - -/* -* Schedule all required I/O operations, then run the disk queue -* to make sure they are started. Do not wait for completion. -*/ -static long madvise_willneed (struct vm_area_struct * vma, -unsigned long start,unsigned long end) -{ -long error = -EBADF ; -struct file * file; -unsigned long size, rlim_rss; - -/* Doesn't work if there's no mapped file. */ -if (!vma->vm_file) -return error; - file = vma->vm_file; - size = (file->f_dentry->d_inode->i_size +PAGE_CACHE_SIZE -1 ) >> -PAGE_CACHE_SHIFT ; - - start = ((start - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; -if (end > vma->vm_end) - end = vma->vm_end; - end = ((end - vma->vm_start) >>PAGE_SHIFT ) + vma->vm_pgoff; - -/* Make sure this doesn't exceed the process's max rss. */ - error = -EIO ; - rlim_rss = current->rlim ? current->rlim[RLIMIT_RSS ].rlim_cur : -LONG_MAX ;/* default: see resource.h */ -if ((vma->vm_mm->rss + (end - start)) > rlim_rss) -return error; - -do_page_cache_readahead (file, start, end - start); -return 0 ; -} - -/* -* Application no longer needs these pages. If the pages are dirty, -* it's OK to just throw them away. The app will be more careful about -* data it wants to keep. Be sure to free swap resources too. The -* zap_page_range call sets things up for refill_inactive to actually free -* these pages later if no one else has touched them in the meantime, -* although we could add these pages to a global reuse list for -* refill_inactive to pick up before reclaiming other pages. -* -* NB: This interface discards data rather than pushes it out to swap, -* as some implementations do. This has performance implications for -* applications like large transactional databases which want to discard -* pages in anonymous maps after committing to backing store the data -* that was kept in them. There is no reason to write this data out to -* the swap area if the application is discarding it. -* -* An interface that causes the system to free clean pages and flush -* dirty pages is already available as msync(MS_INVALIDATE). -*/ -static long madvise_dontneed (struct vm_area_struct * vma, -unsigned long start,unsigned long end) -{ -if (vma->vm_flags &VM_LOCKED ) -return -EINVAL ; - -zap_page_range (vma, start, end - start); -return 0 ; -} - -static long madvise_vma (struct vm_area_struct * vma,unsigned long start, -unsigned long end,int behavior) -{ -long error = -EBADF ; - -switch (behavior) { -case MADV_NORMAL : -case MADV_SEQUENTIAL : -case MADV_RANDOM : - error =madvise_behavior (vma, start, end, behavior); -break ; - -case MADV_WILLNEED : - error =madvise_willneed (vma, start, end); -break ; - -case MADV_DONTNEED : - error =madvise_dontneed (vma, start, end); -break ; - -default : - error = -EINVAL ; -break ; - } - -return error; -} - -/* -* The madvise(2) system call. -* -* Applications can use madvise() to advise the kernel how it should -* handle paging I/O in this VM area. The idea is to help the kernel -* use appropriate read-ahead and caching techniques. The information -* provided is advisory only, and can be safely disregarded by the -* kernel without affecting the correct operation of the application. -* -* behavior values: -* MADV_NORMAL - the default behavior is to read clusters. This -* results in some read-ahead and read-behind. -* MADV_RANDOM - the system should read the minimum amount of data -* on any access, since it is unlikely that the appli- -* cation will need more than what it asks for. -* MADV_SEQUENTIAL - pages in the given range will probably be accessed -* once, so they can be aggressively read ahead, and -* can be freed soon after they are accessed. -* MADV_WILLNEED - the application is notifying the system to read -* some pages ahead. -* MADV_DONTNEED - the application is finished with the given range, -* so the kernel can free resources associated with it. -* -* return values: -* zero - success -* -EINVAL - start + len < 0, start is not page-aligned, -* "behavior" is not a valid value, or application -* is attempting to release locked or shared pages. -* -ENOMEM - addresses in the specified range are not currently -* mapped, or are outside the AS of the process. -* -EIO - an I/O error occurred while paging in data. -* -EBADF - map exists, but area maps something that isn't a file. -* -EAGAIN - a kernel resource was temporarily unavailable. -*/ -asmlinkage long sys_madvise (unsigned long start,size_t len,int behavior) -{ -unsigned long end; -struct vm_area_struct * vma; -int unmapped_error =0 ; -int error = -EINVAL ; - -down_write (¤t->mm->mmap_sem); - -if (start & ~PAGE_MASK ) - goto out; - len = (len + ~PAGE_MASK ) &PAGE_MASK ; - end = start + len; -if (end < start) - goto out; - - error =0 ; -if (end == start) - goto out; - -/* -* If the interval [start,end) covers some unmapped address -* ranges, just ignore them, but return -ENOMEM at the end. -*/ - vma =find_vma (current->mm, start); -for (;;) { -/* Still start < end. */ - error = -ENOMEM ; -if (!vma) - goto out; - -/* Here start < vma->vm_end. */ -if (start < vma->vm_start) { - unmapped_error = -ENOMEM ; - start = vma->vm_start; - } - -/* Here vma->vm_start <= start < vma->vm_end. */ -if (end <= vma->vm_end) { -if (start < end) { - error =madvise_vma (vma, start, end, - behavior); -if (error) - goto out; - } - error = unmapped_error; - goto out; - } - -/* Here vma->vm_start <= start < vma->vm_end < end. */ - error =madvise_vma (vma, start, vma->vm_end, behavior); -if (error) - goto out; - start = vma->vm_end; - vma = vma->vm_next; - } - -out: -up_write (¤t->mm->mmap_sem); -return error; -} - -static inline -struct page *__read_cache_page (struct address_space *mapping, +static inline struct page *__read_cache_page (struct address_space *mapping,unsigned long index,int (*filler)(void *,struct page *),void *data)
mm/madvise.c new file +340 -0
340 lines not on this page · raw message
mm/Makefile renamed from mm/Makefile~madvise-move +1 -1
@@ -16,6 +16,6 @@ obj-y := memory.o mmap.o filemap.o mpro vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o \ page_alloc.o swap_state.o swapfile.o numa.o oom_kill.o \ shmem.o highmem.o mempool.o msync.o mincore.o readahead.o \ - pdflush.o page-writeback.o rmap.o + pdflush.o page-writeback.o rmap.o madvise.o include $(TOPDIR)/Rules.make
.
include/linux/mm.h | 2 mm/madvise.c | 150 +++++------------------------------- mm/mlock.c | 158 +++++++------------------------------- mm/mmap.c | 37 +++++--- mm/mprotect.c | 218 ++++++++++++++++------------------------------------- 5 files changed, 147 insertions(+), 418 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~split-vma +2 -0
@@ -497,6 +497,8 @@ extern int expand_stack(struct vm_area_sextern struct vm_area_struct *find_vma (struct mm_struct * mm,unsigned long addr);extern struct vm_area_struct *find_vma_prev (struct mm_struct * mm,unsigned long addr,struct vm_area_struct **pprev); +extern int split_vma (struct mm_struct * mm,struct vm_area_struct * vma, +unsigned long addr,int new_below);/* Look up the first VMA which intersects the interval start_addr..end_addr-1, NULL if none. Assume start_addr < end_addr. */
mm/madvise.c renamed from mm/madvise.c~split-vma +24 -126
175 lines not on this page · raw message
mm/mlock.c renamed from mm/mlock.c~split-vma +30 -128
177 lines not on this page · raw message
mm/mmap.c renamed from mm/mmap.c~split-vma +22 -15
@@ -1047,10 +1047,11 @@ static struct vm_area_struct *touched_by }/* -* Split a vma into two pieces at address 'addr', the original vma -* will contain the first part, a new vma is allocated for the tail. +* Split a vma into two pieces at address 'addr', a new vma is allocated +* either for the first part or the the tail. */ -static int splitvma (struct mm_struct *mm,struct vm_area_struct *mpnt,unsigned long addr) +int split_vma (struct mm_struct * mm,struct vm_area_struct * vma, +unsigned long addr,int new_below) {struct vm_area_struct *new;
@@ -1062,22 +1063,28 @@ static int splitvma(struct mm_struct *mmreturn -ENOMEM ;/* most fields are the same, copy all, and then fixup */ - *new = *mpnt; + *new = *vma; + +if (new_below) { + vma->vm_start = new->vm_end = addr; + vma->vm_pgoff += ((addr - vma->vm_start) >>PAGE_SHIFT ); + }else { + new->vm_start = vma->vm_end = addr; + new->vm_pgoff += ((addr - vma->vm_start) >>PAGE_SHIFT ); + } - new->vm_start = addr; - new->vm_pgoff = mpnt->vm_pgoff + ((addr - mpnt->vm_start) >>PAGE_SHIFT ); new->vm_raend =0 ; -if (mpnt->vm_file) -get_file (mpnt->vm_file); -if (mpnt->vm_ops && mpnt->vm_ops->open) - mpnt->vm_ops->open (mpnt); - mpnt->vm_end = addr;/* Truncate area */ +if (new->vm_file) +get_file (new->vm_file); + +if (new->vm_ops && new->vm_ops->open) + new->vm_ops->open (new);spin_lock (&mm->page_table_lock); -lock_vma_mappings (mpnt); +lock_vma_mappings (vma);__insert_vm_struct (mm, new); -unlock_vma_mappings (mpnt); +unlock_vma_mappings (vma);spin_unlock (&mm->page_table_lock);return 0 ;
@@ -1114,7 +1121,7 @@ int do_munmap(struct mm_struct *mm, unsi* If we need to split any vma, do it now to save pain later. */ if (start > mpnt->vm_start) { -if (splitvma (mm, mpnt, start)) +if (split_vma (mm, mpnt, start,0 ))return -ENOMEM ; prev = mpnt; mpnt = mpnt->vm_next;
@@ -1123,7 +1130,7 @@ int do_munmap(struct mm_struct *mm, unsi/* Does it split the last one? */ last =find_vma (mm, end);if (last && end > last->vm_start) { -if (splitvma (mm, last, end)) +if (split_vma (mm, last, end,0 ))return -ENOMEM ; }
mm/mprotect.c renamed from mm/mprotect.c~split-vma +69 -149
275 lines not on this page · raw message
.