Hooks for calling vma specific migration functions With this patch a vma may define a vma->vm_ops->migrate function. That function may perform page migration on its own. Only mmap_sem is held when the migration function is called. The migrate() function gets passed two sets of nodemasks describing the source and the target of the migration. The flags parameter either contains MPOL_MF_MOVE which means that only pages used exclusively by the specified mm should be moved or MPOL_MF_MOVE_ALL which means that pages shared with other processes should also be moved. The migration function returns 0 on success or an error condition. An error condition will prevent regular page migration from occurring. On its own this patch cannot be included since there are no users for this functionality Signed-off-by: Christoph Lameter Index: linux-2.6.17-rc3-mm1/mm/mempolicy.c =================================================================== --- linux-2.6.17-rc3-mm1.orig/mm/mempolicy.c 2006-05-08 00:48:20.343013936 -0700 +++ linux-2.6.17-rc3-mm1/mm/mempolicy.c 2006-05-09 17:33:48.375400570 -0700 @@ -627,6 +627,10 @@ int do_migrate_pages(struct mm_struct *m down_read(&mm->mmap_sem); + err = migrate_vmas(mm, from_nodes, to_nodes, flags); + if (err) + goto out; + /* * Find a 'source' bit set in 'tmp' whose corresponding 'dest' * bit in 'to' is not also set in 'tmp'. Clear the found 'source' @@ -686,7 +690,7 @@ int do_migrate_pages(struct mm_struct *m if (err < 0) break; } - +out: up_read(&mm->mmap_sem); if (err < 0) return err; Index: linux-2.6.17-rc3-mm1/mm/migrate.c =================================================================== --- linux-2.6.17-rc3-mm1.orig/mm/migrate.c 2006-05-08 23:41:04.988734466 -0700 +++ linux-2.6.17-rc3-mm1/mm/migrate.c 2006-05-10 17:01:24.288939708 -0700 @@ -753,3 +753,23 @@ out: nr_pages++; return nr_pages; } + +/* + * Call migration functions in the vma_ops that may prepare + * memory in a vm for migration. migration functions may perform + * the migration for vmas that do not have an underlying page struct. + */ +int migrate_vmas(struct mm_struct *mm, nodemask_t *to + nodemask_t *from, unsigned int flags) +{ + struct vm_area_struct *vma; + int err = 0; + + for(vma = mm->first_vma; vma->vm_next && !err; vma = vma->vm_next) { + if (vma->vm_ops && vma->vm_ops->migrate) { + err = vma->vm_ops->migrate(vma, to, from, flags); + if (err) + break; + } + return err; +} Index: linux-2.6.17-rc3-mm1/include/linux/mm.h =================================================================== --- linux-2.6.17-rc3-mm1.orig/include/linux/mm.h 2006-05-08 00:48:19.041336781 -0700 +++ linux-2.6.17-rc3-mm1/include/linux/mm.h 2006-05-09 17:45:31.934297895 -0700 @@ -204,6 +204,7 @@ struct vm_operations_struct { int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new); struct mempolicy *(*get_policy)(struct vm_area_struct *vma, unsigned long addr); + int (*migrate)(struct vm_area_struct *vma, nodemask_t from, nodemask_t to); #endif }; Index: linux-2.6.17-rc3-mm1/include/linux/migrate.h =================================================================== --- linux-2.6.17-rc3-mm1.orig/include/linux/migrate.h 2006-05-08 00:48:19.020830239 -0700 +++ linux-2.6.17-rc3-mm1/include/linux/migrate.h 2006-05-09 17:33:29.224244825 -0700 @@ -17,7 +17,8 @@ extern int fail_migrate_page(struct addr struct page *, struct page *); extern int migrate_prep(void); - +extern int migrate_vmas(struct mm_struct *mm, + nodemask_t *from, nodemask_t *to, unsigned long flags); #else static inline int isolate_lru_page(struct page *p, struct list_head *list) @@ -31,6 +32,12 @@ static inline int migrate_pages_to(struc static inline int migrate_prep(void) { return -ENOSYS; } +static inline int migrate_vmas(struct mm_struct *mm, + nodemask_t *from, nodemask_t *to, unsigned long flags) +{ + return -ENOSYS; +} + /* Possible settings for the migrate_page() method in address_operations */ #define migrate_page NULL #define fail_migrate_page NULL