--- linux-2.6.20.x86_64/mm/madvise.c.madv_free 2007-04-19 16:46:22.000000000 -0400 +++ linux-2.6.20.x86_64/mm/madvise.c 2007-04-19 16:52:19.000000000 -0400 @@ -130,7 +130,8 @@ static long madvise_willneed(struct vm_a */ static long madvise_dontneed(struct vm_area_struct * vma, struct vm_area_struct ** prev, - unsigned long start, unsigned long end) + unsigned long start, unsigned long end, + int behavior) { *prev = vma; if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP)) @@ -142,12 +143,14 @@ static long madvise_dontneed(struct vm_a .last_index = ULONG_MAX, }; zap_page_range(vma, start, end - start, &details); - } else { + } else if (behavior == MADV_FREE) { struct zap_details details = { .madv_free = 1, }; zap_page_range(vma, start, end - start, &details); - } + } else /* behavior == MADV_DONTNEED */ + zap_page_range(vma, start, end - start, NULL); + return 0; } @@ -219,10 +222,9 @@ madvise_vma(struct vm_area_struct *vma, error = madvise_willneed(vma, prev, start, end); break; - /* FIXME: POSIX says that MADV_DONTNEED cannot throw away data. */ case MADV_DONTNEED: case MADV_FREE: - error = madvise_dontneed(vma, prev, start, end); + error = madvise_dontneed(vma, prev, start, end, behavior); break; default: