mm: balloon: use general non-lru movable page feature
Subsystems (7)
[email protected]
maintainerPATCH 44/126 mm: balloon: use general non-lru movable page feature
From: Minchan Kim <[email protected]>
Subject: mm: balloon: use general non-lru movable page feature
Now, VM has a feature to migrate non-lru movable pages so balloon doesn't need custom migration hooks in migrate.c and compaction.c. Instead, this patch implements page->mapping->a_ops->{isolate|migrate|putback} functions.
With that, we could remove hooks for ballooning in general migration functions and make balloon compaction simple.
[[email protected]: compaction.h requires that the includer first include node.h]
Signed-off-by Gioh Kim <[email protected]>
Signed-off-by Minchan Kim <[email protected]>
Acked-by Vlastimil Babka <[email protected]>
Cc Rafael Aquini <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
drivers/virtio/virtio_balloon.c | 54 +++++++++++++-- include/linux/balloon_compaction.h | 54 ++++----------- include/uapi/linux/magic.h | 1 mm/balloon_compaction.c | 94 ++++----------------------- mm/compaction.c | 7 -- mm/migrate.c | 19 ----- mm/vmscan.c | 2 7 files changed, 86 insertions(+), 145 deletions(-)
drivers/virtio/virtio_balloon.c renamed from drivers/virtio/virtio_balloon.c~mm-balloon-use-general-non-lru-movable-page-feature +48 -6
@@ -30,6 +30,7 @@#include <linux/oom.h> #include <linux/wait.h> #include <linux/mm.h> +#include <linux/mount.h> /* * Balloon device works in 4K page units. So each page is pointed to by
@@ -45,6 +46,10 @@ static int oom_pages = OOM_VBALLOON_DEFAmodule_param (oom_pages, int,S_IRUSR |S_IWUSR );MODULE_PARM_DESC (oom_pages,"pages to free on OOM" ); +#ifdef CONFIG_BALLOON_COMPACTION +static struct vfsmount *balloon_mnt; +#endif +struct virtio_balloon {struct virtio_device *vdev;struct virtqueue *inflate_vq, *deflate_vq, *stats_vq;
@@ -488,8 +493,26 @@ static int virtballoon_migratepage(strucput_page (page);/* balloon reference */ - return MIGRATEPAGE_SUCCESS; + return 0; } + +static struct dentry *balloon_mount (struct file_system_type *fs_type, +int flags,const char *dev_name,void *data) +{ +static const struct dentry_operations ops = { + .d_dname = simple_dname, + }; + +return mount_pseudo (fs_type,"balloon-kvm:" ,NULL , &ops, +BALLOON_KVM_MAGIC ); +} + +static struct file_system_type balloon_fs = { + .name ="balloon-kvm" , + .mount = balloon_mount, + .kill_sb = kill_anon_super, +}; +#endif /* CONFIG_BALLOON_COMPACTION */ static int virtballoon_probe (struct virtio_device *vdev)
@@ -519,9 +542,6 @@ static int virtballoon_probe(struct virt vb->vdev = vdev;balloon_devinfo_init (&vb->vb_dev_info); -#ifdef CONFIG_BALLOON_COMPACTION - vb->vb_dev_info.migratepage = virtballoon_migratepage; -#endif err =init_vqs (vb);if (err)
@@ -531,13 +551,33 @@ static int virtballoon_probe(struct virt vb->nb.priority =VIRTBALLOON_OOM_NOTIFY_PRIORITY ; err =register_oom_notifier (&vb->nb);if (err <0 ) - goto out_oom_notify; + goto out_del_vqs; + +#ifdef CONFIG_BALLOON_COMPACTION + balloon_mnt =kern_mount (&balloon_fs); +if (IS_ERR (balloon_mnt)) { + err =PTR_ERR (balloon_mnt); +unregister_oom_notifier (&vb->nb); + goto out_del_vqs; + } + + vb->vb_dev_info.migratepage = virtballoon_migratepage; + vb->vb_dev_info.inode =alloc_anon_inode (balloon_mnt->mnt_sb); +if (IS_ERR (vb->vb_dev_info.inode)) { + err =PTR_ERR (vb->vb_dev_info.inode); +kern_unmount (balloon_mnt); +unregister_oom_notifier (&vb->nb); + vb->vb_dev_info.inode =NULL ; + goto out_del_vqs; + } + vb->vb_dev_info.inode->i_mapping->a_ops = &balloon_aops; +#endif virtio_device_ready (vdev);return 0 ; -out_oom_notify: +out_del_vqs: vdev->config->del_vqs (vdev); out_free_vb:kfree (vb);
@@ -571,6 +611,8 @@ static void virtballoon_remove(struct vicancel_work_sync (&vb->update_balloon_stats_work);remove_common (vb); +if (vb->vb_dev_info.inode) +iput (vb->vb_dev_info.inode);kfree (vb); }
include/linux/balloon_compaction.h renamed from include/linux/balloon_compaction.h~mm-balloon-use-general-non-lru-movable-page-feature +17 -37
95 lines not on this page · raw message
include/uapi/linux/magic.h renamed from include/uapi/linux/magic.h~mm-balloon-use-general-non-lru-movable-page-feature +1 -0
@@ -80,5 +80,6 @@#define BPF_FS_MAGIC 0xcafe4a11/* Since UDF 2.01 is ISO 13346 based... */ #define UDF_SUPER_MAGIC 0x15013346 +#define BALLOON_KVM_MAGIC 0x13661366#endif /* __LINUX_MAGIC_H__ */
mm/balloon_compaction.c renamed from mm/balloon_compaction.c~mm-balloon-use-general-non-lru-movable-page-feature +17 -77
134 lines not on this page · raw message
mm/compaction.c renamed from mm/compaction.c~mm-balloon-use-general-non-lru-movable-page-feature +0 -7
@@ -791,13 +791,6 @@ isolate_migratepages_block(struct compac* Skip any other type of page */ if (!PageLRU (page)) { -if (unlikely (balloon_page_movable (page))) { -if (balloon_page_isolate (page)) { -/* Successfully isolated */ - goto isolate_success; - } - } -/* * __PageMovable can return false positive so we need * to verify it under page_lock.
mm/migrate.c renamed from mm/migrate.c~mm-balloon-use-general-non-lru-movable-page-feature +2 -17
@@ -170,14 +170,12 @@ void putback_movable_pages(struct list_hlist_del (&page->lru);dec_zone_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); -if (unlikely (isolated_balloon_page (page))) { -balloon_page_putback (page);/* * We isolated non-lru movable page so here we can use * __PageMovable because LRU page's mapping cannot have * PAGE_MAPPING_MOVABLE. */ - }else if (unlikely (__PageMovable (page))) { +if (unlikely (__PageMovable (page))) {VM_BUG_ON_PAGE (!PageIsolated (page), page);lock_page (page);if (PageMovable (page))
@@ -992,18 +990,6 @@ static int __unmap_and_move(struct pageif (unlikely (!trylock_page (newpage))) goto out_unlock; -if (unlikely (isolated_balloon_page (page))) { -/* -* A ballooned page does not need any special attention from -* physical to virtual reverse mapping procedures. -* Skip any attempt to unmap PTEs or to remap swap cache, -* in order to avoid burning cycles at rmap level, and perform -* the page migration right away (proteced by page lock). -*/ - rc =balloon_page_migrate (newpage, page, mode); - goto out_unlock_both; - } -if (unlikely (!is_lru)) { rc =move_to_new_page (newpage, page, mode); goto out_unlock_both;
@@ -1058,8 +1044,7 @@ out:* list in here. */ if (rc ==MIGRATEPAGE_SUCCESS ) { -if (unlikely (__is_movable_balloon_page (newpage) || -__PageMovable (newpage))) +if (unlikely (__PageMovable (newpage)))put_page (newpage);else putback_lru_page (newpage);
mm/vmscan.c renamed from mm/vmscan.c~mm-balloon-use-general-non-lru-movable-page-feature +1 -1
@@ -1254,7 +1254,7 @@ unsigned long reclaim_clean_pages_from_llist_for_each_entry_safe (page, next, page_list, lru) {if (page_is_file_cache (page) && !PageDirty (page) && - !isolated_balloon_page (page)) { + !__PageMovable (page)) {ClearPageActive (page);list_move (&page->lru, &clean_pages); }
_