Re: [RFCv3 2/5] mm/compaction: enable mobile-page migration

2015-07-13 Thread Gioh Kim



@@ -51,6 +54,66 @@ extern void compaction_defer_reset(struct zone *zone, int 
order,
 bool alloc_success);
  extern bool compaction_restarting(struct zone *zone, int order);

+static inline bool mobile_page(struct page *page)
+{
+   return page-mapping  page-mapping-a_ops 


Dereferncing mapping-a_ops isn't safe without page-lock and isn't required:
all mappings always have -a_ops.



I got it.


+static inline void putback_mobilepage(struct page *page)
+{
+   /*
+* 'lock_page()' stabilizes the page and prevents races against
+* concurrent isolation threads attempting to re-isolate it.
+*/
+   lock_page(page);
+   if (mobile_page(page)  page-mapping-a_ops-putbackpage) {


It seems if (page-mapping  page-mapping-a_ops-putbackpage)
should be enough: we already seen that page as mobile.


Ditto.




+   page-mapping-a_ops-putbackpage(page);
+   /* drop the extra ref count taken for mobile page isolation */
+   put_page(page);
+   }
+   unlock_page(page);


call put_page() after unlock and do that always -- putback must drop
page reference from caller.

lock_page(page);
if (page-mapping  page-mapping-a_ops-putbackpage)
  page-mapping-a_ops-putbackpage(page);
unlock_page();
put_page(page);



Ditto.


+}
  #else
  static inline unsigned long try_to_compact_pages(gfp_t gfp_mask,
 unsigned int order, int alloc_flags,
@@ -83,6 +146,19 @@ static inline bool compaction_deferred(struct zone *zone, 
int order)
 return true;
  }

+static inline bool mobile_page(struct page *page)
+{
+   return false;
+}
+
+static inline bool isolate_mobilepage(struct page *page, isolate_mode_t mode)
+{
+   return false;
+}
+
+static inline void putback_mobilepage(struct page *page)
+{
+}
  #endif /* CONFIG_COMPACTION */

  #if defined(CONFIG_COMPACTION)  defined(CONFIG_SYSFS)  
defined(CONFIG_NUMA)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 35ec87e..33c9aa5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -395,6 +395,8 @@ struct address_space_operations {
  */
 int (*migratepage) (struct address_space *,
 struct page *, struct page *, enum migrate_mode);
+   bool (*isolatepage) (struct page *, isolate_mode_t);
+   void (*putbackpage) (struct page *);
 int (*launder_page) (struct page *);
 int (*is_partially_uptodate) (struct page *, unsigned long,
 unsigned long);
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index f34e040..abef145 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -582,6 +582,25 @@ static inline void __ClearPageBalloon(struct page *page)
 atomic_set(page-_mapcount, -1);
  }

+#define PAGE_MOBILE_MAPCOUNT_VALUE (-255)
+
+static inline int PageMobile(struct page *page)
+{
+   return atomic_read(page-_mapcount) == PAGE_MOBILE_MAPCOUNT_VALUE;
+}
+
+static inline void __SetPageMobile(struct page *page)
+{
+   VM_BUG_ON_PAGE(atomic_read(page-_mapcount) != -1, page);
+   atomic_set(page-_mapcount, PAGE_MOBILE_MAPCOUNT_VALUE);
+}
+
+static inline void __ClearPageMobile(struct page *page)
+{
+   VM_BUG_ON_PAGE(!PageMobile(page), page);
+   atomic_set(page-_mapcount, -1);
+}
+
  /*
   * If network-based swap is enabled, sl*b must keep track of whether pages
   * were allocated from pfmemalloc reserves.
diff --git a/include/uapi/linux/kernel-page-flags.h 
b/include/uapi/linux/kernel-page-flags.h
index a6c4962..d50d9e8 100644
--- a/include/uapi/linux/kernel-page-flags.h
+++ b/include/uapi/linux/kernel-page-flags.h
@@ -33,6 +33,7 @@
  #define KPF_THP22
  #define KPF_BALLOON23
  #define KPF_ZERO_PAGE  24
+#define KPF_MOBILE 25


  #endif /* _UAPILINUX_KERNEL_PAGE_FLAGS_H */
--
2.1.4





I fixed the code as your comments and I found patch 3/5 and 4/5 could not be 
applied separately.
So I merge them and report new [PATCH].
I appreciate your reviews.

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH] KVM: Add Kconfig option to signal cross-endian guests

2015-07-13 Thread Greg Kurz
On Thu,  9 Jul 2015 09:49:05 +0200
Thomas Huth th...@redhat.com wrote:

 The option for supporting cross-endianness legacy guests in
 the vhost and tun code should only be available on systems
 that support cross-endian guests.
 
 Signed-off-by: Thomas Huth th...@redhat.com

Acked-by: Greg Kurz gk...@linux.vnet.ibm.com

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 4/4] mm: remove direct calling of migration

2015-07-13 Thread Gioh Kim
From: Gioh Kim guru...@hanmail.net

Migration is completely generalized so that migrating mobile page
is processed with lru-pages in move_to_new_page.

Signed-off-by: Gioh Kim gioh@lge.com
Acked-by: Rafael Aquini aqu...@redhat.com
---
 mm/migrate.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 53f0081d..e6644ac 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -844,21 +844,6 @@ static int __unmap_and_move(struct page *page, struct page 
*newpage,
}
}
 
-   if (unlikely(mobile_page(page))) {
-   /*
-* A mobile 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).
-*/
-   lock_page(newpage);
-   rc = page-mapping-a_ops-migratepage(page-mapping,
-  newpage, page, mode);
-   unlock_page(newpage);
-   goto out_unlock;
-   }
-
/*
 * Corner case handling:
 * 1. When a new swap-cache page is read into, it is added to the LRU
-- 
2.1.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 3/4] mm/balloon: apply mobile page migratable into balloon

2015-07-13 Thread Gioh Kim
From: Gioh Kim guru...@hanmail.net

Apply mobile page migration into balloon driver.
The balloong driver has an anonymous inode that manages
address_space_operation for page migration.
Compaction calls interfaces of mobile page migration
instead of calling balloon migration directly.

Signed-off-by: Gioh Kim gioh@lge.com
Acked-by: Rafael Aquini aqu...@redhat.com
---
 drivers/virtio/virtio_balloon.c|  3 ++
 include/linux/balloon_compaction.h | 15 ++--
 mm/balloon_compaction.c| 72 --
 mm/compaction.c|  8 ++---
 mm/migrate.c   | 21 ++-
 5 files changed, 54 insertions(+), 65 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 82e80e0..ef5b9b5 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -30,6 +30,7 @@
 #include linux/balloon_compaction.h
 #include linux/oom.h
 #include linux/wait.h
+#include linux/anon_inodes.h
 
 /*
  * Balloon device works in 4K page units.  So each page is pointed to by
@@ -505,6 +506,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
balloon_devinfo_init(vb-vb_dev_info);
 #ifdef CONFIG_BALLOON_COMPACTION
vb-vb_dev_info.migratepage = virtballoon_migratepage;
+   vb-vb_dev_info.inode = anon_inode_new();
+   vb-vb_dev_info.inode-i_mapping-a_ops = balloon_aops;
 #endif
 
err = init_vqs(vb);
diff --git a/include/linux/balloon_compaction.h 
b/include/linux/balloon_compaction.h
index 9b0a15d..a9e0bde 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -48,6 +48,7 @@
 #include linux/migrate.h
 #include linux/gfp.h
 #include linux/err.h
+#include linux/fs.h
 
 /*
  * Balloon device information descriptor.
@@ -62,6 +63,7 @@ struct balloon_dev_info {
struct list_head pages; /* Pages enqueued  handled to Host */
int (*migratepage)(struct balloon_dev_info *, struct page *newpage,
struct page *page, enum migrate_mode mode);
+   struct inode *inode;
 };
 
 extern struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info);
@@ -73,12 +75,16 @@ static inline void balloon_devinfo_init(struct 
balloon_dev_info *balloon)
spin_lock_init(balloon-pages_lock);
INIT_LIST_HEAD(balloon-pages);
balloon-migratepage = NULL;
+   balloon-inode = NULL;
 }
 
 #ifdef CONFIG_BALLOON_COMPACTION
-extern bool balloon_page_isolate(struct page *page);
+extern const struct address_space_operations balloon_aops;
+extern bool balloon_page_isolate(struct page *page,
+isolate_mode_t mode);
 extern void balloon_page_putback(struct page *page);
-extern int balloon_page_migrate(struct page *newpage,
+extern int balloon_page_migrate(struct address_space *mapping,
+   struct page *newpage,
struct page *page, enum migrate_mode mode);
 
 /*
@@ -124,6 +130,7 @@ static inline void balloon_page_insert(struct 
balloon_dev_info *balloon,
   struct page *page)
 {
__SetPageBalloon(page);
+   page-mapping = balloon-inode-i_mapping;
SetPagePrivate(page);
set_page_private(page, (unsigned long)balloon);
list_add(page-lru, balloon-pages);
@@ -140,6 +147,7 @@ static inline void balloon_page_insert(struct 
balloon_dev_info *balloon,
 static inline void balloon_page_delete(struct page *page)
 {
__ClearPageBalloon(page);
+   page-mapping = NULL;
set_page_private(page, 0);
if (PagePrivate(page)) {
ClearPagePrivate(page);
@@ -191,7 +199,8 @@ static inline bool isolated_balloon_page(struct page *page)
return false;
 }
 
-static inline bool balloon_page_isolate(struct page *page)
+static inline bool balloon_page_isolate(struct page *page,
+   isolate_mode_t mode)
 {
return false;
 }
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index fcad832..8fbcf9c 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -131,43 +131,16 @@ static inline void __putback_balloon_page(struct page 
*page)
 }
 
 /* __isolate_lru_page() counterpart for a ballooned page */
-bool balloon_page_isolate(struct page *page)
+bool balloon_page_isolate(struct page *page, isolate_mode_t mode)
 {
/*
-* Avoid burning cycles with pages that are yet under __free_pages(),
-* or just got freed under us.
-*
-* In case we 'win' a race for a balloon page being freed under us and
-* raise its refcount preventing __free_pages() from doing its job
-* the put_page() at the end of this block will take care of
-* release this page, thus avoiding a nasty leakage.
+* A ballooned page, by default, has PagePrivate set.
+* Prevent concurrent compaction threads from isolating
+* 

Re: [PATCH 0/4] enable migration of driver pages

2015-07-13 Thread Konstantin Khlebnikov
On Mon, Jul 13, 2015 at 11:35 AM, Gioh Kim gioh@lge.com wrote:
 From: Gioh Kim guru...@hanmail.net

 Hello,

 This series try to enable migration of non-LRU pages, such as driver's page.

 My ARM-based platform occured severe fragmentation problem after long-term
 (several days) test. Sometimes even order-3 page allocation failed. It has
 memory size 512MB ~ 1024MB. 30% ~ 40% memory is consumed for graphic 
 processing
 and 20~30 memory is reserved for zram.

 I found that many pages of GPU driver and zram are non-movable pages. So I
 reported Minchan Kim, the maintainer of zram, and he made the internal
 compaction logic of zram. And I made the internal compaction of GPU driver.

 They reduced some fragmentation but they are not enough effective.
 They are activated by its own interface, /sys, so they are not cooperative
 with kernel compaction. If there is too much fragmentation and kernel starts
 to compaction, zram and GPU driver cannot work with the kernel compaction.

 So I thought there needs a interface to combine driver and kernel compaction.
 This patch adds a generic isolate/migrate/putback callbacks for page
 address-space and a new interface to create anon-inode to manage
 address_space_operation. The zram and GPU, and any other modules can create
 anon_inode and register its own migration method. The kernel compaction can
 call the registered migration when it does compaction.

 My GPU driver source is not in-kernel driver so that I apply the interface
 into balloon driver. The balloon driver is already merged
 into the kernel compaction as a corner-case. This patch have the balloon
 driver migration be called by the generic interface.


 This patch set combines 4 patches.

 1. patch 1/4: get inode from anon_inodes
 This patch adds new interface to create inode from anon_inodes.

 2. patch 2/4: framework to isolate/migrate/putback page
 Add isolatepage, putbackpage into address_space_operations
 and wrapper function to call them.

 3. patch 3/4: apply the framework into balloon driver
 The balloon driver is applied into the framework. It gets a inode
 from anon_inodes and register operations in the inode.
 The kernel compaction calls generic interfaces, not balloon
 driver interfaces.
 Any other drivers can register operations via inode like this
 to migrate it's pages.

 4. patch 4/4: remove direct calling of migration of driver pages
 Non-lru pages are also migrated with lru pages by move_to_new_page().

The whole patchset looks good.

Reviewed-by: Konstantin Khlebnikov koc...@gmail.com


 This patch set is tested:
 - turn on Ubuntu 14.04 with 1G memory on qemu.
 - do kernel building
 - after several seconds check more than 512MB is used with free command
 - command balloon 512 in qemu monitor
 - check hundreds MB of pages are migrated

Another simple test is several instances of
tools/testing/selftests/vm/transhuge-stress.c
runnng in parallel with balloon inflating/deflating.
(transparent huge pages must be enabled of course)
That catched a lot of races in ballooning code.


 My thanks to Konstantin Khlebnikov for his reviews of the RFC patch set.
 Most of the changes were based on his feedback.

 This patch-set is based on v4.1


 Gioh Kim (4):
   fs/anon_inodes: new interface to create new inode
   mm/compaction: enable mobile-page migration
   mm/balloon: apply mobile page migratable into balloon
   mm: remove direct calling of migration

  drivers/virtio/virtio_balloon.c|  3 ++
  fs/anon_inodes.c   |  6 +++
  fs/proc/page.c |  3 ++
  include/linux/anon_inodes.h|  1 +
  include/linux/balloon_compaction.h | 15 +--
  include/linux/compaction.h | 80 
 ++
  include/linux/fs.h |  2 +
  include/linux/page-flags.h | 19 
  include/uapi/linux/kernel-page-flags.h |  1 +
  mm/balloon_compaction.c| 72 ++
  mm/compaction.c|  8 ++--
  mm/migrate.c   | 24 +++---
  12 files changed, 160 insertions(+), 74 deletions(-)

 --
 2.1.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH 0/4] enable migration of driver pages

2015-07-13 Thread Gioh Kim



2015-07-13 오후 6:24에 Konstantin Khlebnikov 이(가) 쓴 글:

On Mon, Jul 13, 2015 at 11:35 AM, Gioh Kim gioh@lge.com wrote:

From: Gioh Kim guru...@hanmail.net

Hello,

This series try to enable migration of non-LRU pages, such as driver's page.

My ARM-based platform occured severe fragmentation problem after long-term
(several days) test. Sometimes even order-3 page allocation failed. It has
memory size 512MB ~ 1024MB. 30% ~ 40% memory is consumed for graphic processing
and 20~30 memory is reserved for zram.

I found that many pages of GPU driver and zram are non-movable pages. So I
reported Minchan Kim, the maintainer of zram, and he made the internal
compaction logic of zram. And I made the internal compaction of GPU driver.

They reduced some fragmentation but they are not enough effective.
They are activated by its own interface, /sys, so they are not cooperative
with kernel compaction. If there is too much fragmentation and kernel starts
to compaction, zram and GPU driver cannot work with the kernel compaction.

So I thought there needs a interface to combine driver and kernel compaction.
This patch adds a generic isolate/migrate/putback callbacks for page
address-space and a new interface to create anon-inode to manage
address_space_operation. The zram and GPU, and any other modules can create
anon_inode and register its own migration method. The kernel compaction can
call the registered migration when it does compaction.

My GPU driver source is not in-kernel driver so that I apply the interface
into balloon driver. The balloon driver is already merged
into the kernel compaction as a corner-case. This patch have the balloon
driver migration be called by the generic interface.


This patch set combines 4 patches.

1. patch 1/4: get inode from anon_inodes
This patch adds new interface to create inode from anon_inodes.

2. patch 2/4: framework to isolate/migrate/putback page
Add isolatepage, putbackpage into address_space_operations
and wrapper function to call them.

3. patch 3/4: apply the framework into balloon driver
The balloon driver is applied into the framework. It gets a inode
from anon_inodes and register operations in the inode.
The kernel compaction calls generic interfaces, not balloon
driver interfaces.
Any other drivers can register operations via inode like this
to migrate it's pages.

4. patch 4/4: remove direct calling of migration of driver pages
Non-lru pages are also migrated with lru pages by move_to_new_page().


The whole patchset looks good.

Reviewed-by: Konstantin Khlebnikov koc...@gmail.com



This patch set is tested:
- turn on Ubuntu 14.04 with 1G memory on qemu.
- do kernel building
- after several seconds check more than 512MB is used with free command
- command balloon 512 in qemu monitor
- check hundreds MB of pages are migrated


Another simple test is several instances of
tools/testing/selftests/vm/transhuge-stress.c
runnng in parallel with balloon inflating/deflating.
(transparent huge pages must be enabled of course)
That catched a lot of races in ballooning code.



Great!
I'll do it and inform you the result in this week.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH 0/4] enable migration of driver pages

2015-07-13 Thread Rafael Aquini
On Mon, Jul 13, 2015 at 05:35:15PM +0900, Gioh Kim wrote:
 From: Gioh Kim guru...@hanmail.net
 
 Hello,
 
 This series try to enable migration of non-LRU pages, such as driver's page.
 
 My ARM-based platform occured severe fragmentation problem after long-term
 (several days) test. Sometimes even order-3 page allocation failed. It has
 memory size 512MB ~ 1024MB. 30% ~ 40% memory is consumed for graphic 
 processing
 and 20~30 memory is reserved for zram.
 
 I found that many pages of GPU driver and zram are non-movable pages. So I
 reported Minchan Kim, the maintainer of zram, and he made the internal 
 compaction logic of zram. And I made the internal compaction of GPU driver.
 
 They reduced some fragmentation but they are not enough effective.
 They are activated by its own interface, /sys, so they are not cooperative
 with kernel compaction. If there is too much fragmentation and kernel starts
 to compaction, zram and GPU driver cannot work with the kernel compaction.
 
 So I thought there needs a interface to combine driver and kernel compaction.
 This patch adds a generic isolate/migrate/putback callbacks for page
 address-space and a new interface to create anon-inode to manage
 address_space_operation. The zram and GPU, and any other modules can create
 anon_inode and register its own migration method. The kernel compaction can
 call the registered migration when it does compaction.
 
 My GPU driver source is not in-kernel driver so that I apply the interface
 into balloon driver. The balloon driver is already merged
 into the kernel compaction as a corner-case. This patch have the balloon
 driver migration be called by the generic interface.
 
 
 This patch set combines 4 patches.
 
 1. patch 1/4: get inode from anon_inodes
 This patch adds new interface to create inode from anon_inodes.
 
 2. patch 2/4: framework to isolate/migrate/putback page
 Add isolatepage, putbackpage into address_space_operations
 and wrapper function to call them.
 
 3. patch 3/4: apply the framework into balloon driver
 The balloon driver is applied into the framework. It gets a inode
 from anon_inodes and register operations in the inode.
 The kernel compaction calls generic interfaces, not balloon
 driver interfaces. 
 Any other drivers can register operations via inode like this
 to migrate it's pages.
 
 4. patch 4/4: remove direct calling of migration of driver pages
 Non-lru pages are also migrated with lru pages by move_to_new_page().
 
 This patch set is tested:
 - turn on Ubuntu 14.04 with 1G memory on qemu.
 - do kernel building
 - after several seconds check more than 512MB is used with free command
 - command balloon 512 in qemu monitor
 - check hundreds MB of pages are migrated
 
 My thanks to Konstantin Khlebnikov for his reviews of the RFC patch set.
 Most of the changes were based on his feedback.
 
 This patch-set is based on v4.1
 
 
 Gioh Kim (4):
   fs/anon_inodes: new interface to create new inode
   mm/compaction: enable mobile-page migration
   mm/balloon: apply mobile page migratable into balloon
   mm: remove direct calling of migration
 
  drivers/virtio/virtio_balloon.c|  3 ++
  fs/anon_inodes.c   |  6 +++
  fs/proc/page.c |  3 ++
  include/linux/anon_inodes.h|  1 +
  include/linux/balloon_compaction.h | 15 +--
  include/linux/compaction.h | 80 
 ++
  include/linux/fs.h |  2 +
  include/linux/page-flags.h | 19 
  include/uapi/linux/kernel-page-flags.h |  1 +
  mm/balloon_compaction.c| 72 ++
  mm/compaction.c|  8 ++--
  mm/migrate.c   | 24 +++---
  12 files changed, 160 insertions(+), 74 deletions(-)
 
 -- 
 2.1.4
 
Acked-by: Rafael Aquini aqu...@redhat.com
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 0/4] enable migration of driver pages

2015-07-13 Thread Gioh Kim
From: Gioh Kim guru...@hanmail.net

Hello,

This series try to enable migration of non-LRU pages, such as driver's page.

My ARM-based platform occured severe fragmentation problem after long-term
(several days) test. Sometimes even order-3 page allocation failed. It has
memory size 512MB ~ 1024MB. 30% ~ 40% memory is consumed for graphic processing
and 20~30 memory is reserved for zram.

I found that many pages of GPU driver and zram are non-movable pages. So I
reported Minchan Kim, the maintainer of zram, and he made the internal 
compaction logic of zram. And I made the internal compaction of GPU driver.

They reduced some fragmentation but they are not enough effective.
They are activated by its own interface, /sys, so they are not cooperative
with kernel compaction. If there is too much fragmentation and kernel starts
to compaction, zram and GPU driver cannot work with the kernel compaction.

So I thought there needs a interface to combine driver and kernel compaction.
This patch adds a generic isolate/migrate/putback callbacks for page
address-space and a new interface to create anon-inode to manage
address_space_operation. The zram and GPU, and any other modules can create
anon_inode and register its own migration method. The kernel compaction can
call the registered migration when it does compaction.

My GPU driver source is not in-kernel driver so that I apply the interface
into balloon driver. The balloon driver is already merged
into the kernel compaction as a corner-case. This patch have the balloon
driver migration be called by the generic interface.


This patch set combines 4 patches.

1. patch 1/4: get inode from anon_inodes
This patch adds new interface to create inode from anon_inodes.

2. patch 2/4: framework to isolate/migrate/putback page
Add isolatepage, putbackpage into address_space_operations
and wrapper function to call them.

3. patch 3/4: apply the framework into balloon driver
The balloon driver is applied into the framework. It gets a inode
from anon_inodes and register operations in the inode.
The kernel compaction calls generic interfaces, not balloon
driver interfaces. 
Any other drivers can register operations via inode like this
to migrate it's pages.

4. patch 4/4: remove direct calling of migration of driver pages
Non-lru pages are also migrated with lru pages by move_to_new_page().

This patch set is tested:
- turn on Ubuntu 14.04 with 1G memory on qemu.
- do kernel building
- after several seconds check more than 512MB is used with free command
- command balloon 512 in qemu monitor
- check hundreds MB of pages are migrated

My thanks to Konstantin Khlebnikov for his reviews of the RFC patch set.
Most of the changes were based on his feedback.

This patch-set is based on v4.1


Gioh Kim (4):
  fs/anon_inodes: new interface to create new inode
  mm/compaction: enable mobile-page migration
  mm/balloon: apply mobile page migratable into balloon
  mm: remove direct calling of migration

 drivers/virtio/virtio_balloon.c|  3 ++
 fs/anon_inodes.c   |  6 +++
 fs/proc/page.c |  3 ++
 include/linux/anon_inodes.h|  1 +
 include/linux/balloon_compaction.h | 15 +--
 include/linux/compaction.h | 80 ++
 include/linux/fs.h |  2 +
 include/linux/page-flags.h | 19 
 include/uapi/linux/kernel-page-flags.h |  1 +
 mm/balloon_compaction.c| 72 ++
 mm/compaction.c|  8 ++--
 mm/migrate.c   | 24 +++---
 12 files changed, 160 insertions(+), 74 deletions(-)

-- 
2.1.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH 2/4] mm/compaction: enable mobile-page migration

2015-07-13 Thread Gioh Kim
From: Gioh Kim guru...@hanmail.net

Add framework to register callback functions and check page mobility.
There are some modes for page isolation so that isolate interface
has arguments of page address and isolation mode while putback
interface has only page address as argument.

Signed-off-by: Gioh Kim gioh@lge.com
Acked-by: Rafael Aquini aqu...@redhat.com
---
 fs/proc/page.c |  3 ++
 include/linux/compaction.h | 80 ++
 include/linux/fs.h |  2 +
 include/linux/page-flags.h | 19 
 include/uapi/linux/kernel-page-flags.h |  1 +
 5 files changed, 105 insertions(+)

diff --git a/fs/proc/page.c b/fs/proc/page.c
index 7eee2d8..a4f5a00 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -146,6 +146,9 @@ u64 stable_page_flags(struct page *page)
if (PageBalloon(page))
u |= 1  KPF_BALLOON;
 
+   if (PageMobile(page))
+   u |= 1  KPF_MOBILE;
+
u |= kpf_copy_bit(k, KPF_LOCKED,PG_locked);
 
u |= kpf_copy_bit(k, KPF_SLAB,  PG_slab);
diff --git a/include/linux/compaction.h b/include/linux/compaction.h
index aa8f61c..f693072 100644
--- a/include/linux/compaction.h
+++ b/include/linux/compaction.h
@@ -1,6 +1,9 @@
 #ifndef _LINUX_COMPACTION_H
 #define _LINUX_COMPACTION_H
 
+#include linux/page-flags.h
+#include linux/pagemap.h
+
 /* Return values for compact_zone() and try_to_compact_pages() */
 /* compaction didn't start as it was deferred due to past failures */
 #define COMPACT_DEFERRED   0
@@ -51,6 +54,70 @@ extern void compaction_defer_reset(struct zone *zone, int 
order,
bool alloc_success);
 extern bool compaction_restarting(struct zone *zone, int order);
 
+static inline bool mobile_page(struct page *page)
+{
+   return page-mapping  (PageMobile(page) || PageBalloon(page));
+}
+
+static inline bool isolate_mobilepage(struct page *page, isolate_mode_t mode)
+{
+   bool ret = false;
+
+   /*
+* Avoid burning cycles with pages that are yet under __free_pages(),
+* or just got freed under us.
+*
+* In case we 'win' a race for a mobile page being freed under us and
+* raise its refcount preventing __free_pages() from doing its job
+* the put_page() at the end of this block will take care of
+* release this page, thus avoiding a nasty leakage.
+*/
+   if (unlikely(!get_page_unless_zero(page)))
+   goto out;
+
+   /*
+* As mobile pages are not isolated from LRU lists, concurrent
+* compaction threads can race against page migration functions
+* as well as race against the releasing a page.
+*
+* In order to avoid having an already isolated mobile page
+* being (wrongly) re-isolated while it is under migration,
+* or to avoid attempting to isolate pages being released,
+* lets be sure we have the page lock
+* before proceeding with the mobile page isolation steps.
+*/
+   if (unlikely(!trylock_page(page)))
+   goto out_putpage;
+
+   if (!(mobile_page(page)  page-mapping-a_ops-isolatepage))
+   goto out_not_isolated;
+   ret = page-mapping-a_ops-isolatepage(page, mode);
+   if (!ret)
+   goto out_not_isolated;
+   unlock_page(page);
+   return ret;
+
+out_not_isolated:
+   unlock_page(page);
+out_putpage:
+   put_page(page);
+out:
+   return ret;
+}
+
+static inline void putback_mobilepage(struct page *page)
+{
+   /*
+* 'lock_page()' stabilizes the page and prevents races against
+* concurrent isolation threads attempting to re-isolate it.
+*/
+   lock_page(page);
+   if (page-mapping  page-mapping-a_ops-putbackpage)
+   page-mapping-a_ops-putbackpage(page);
+   unlock_page(page);
+   /* drop the extra ref count taken for mobile page isolation */
+   put_page(page);
+}
 #else
 static inline unsigned long try_to_compact_pages(gfp_t gfp_mask,
unsigned int order, int alloc_flags,
@@ -83,6 +150,19 @@ static inline bool compaction_deferred(struct zone *zone, 
int order)
return true;
 }
 
+static inline bool mobile_page(struct page *page)
+{
+   return false;
+}
+
+static inline bool isolate_mobilepage(struct page *page, isolate_mode_t mode)
+{
+   return false;
+}
+
+static inline void putback_mobilepage(struct page *page)
+{
+}
 #endif /* CONFIG_COMPACTION */
 
 #if defined(CONFIG_COMPACTION)  defined(CONFIG_SYSFS)  defined(CONFIG_NUMA)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index a0653e5..2cc4b24 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -396,6 +396,8 @@ struct address_space_operations {
 */
int (*migratepage) (struct address_space *,
struct page *, struct page *, enum migrate_mode);
+   bool 

[PATCH 1/4] fs/anon_inodes: new interface to create new inode

2015-07-13 Thread Gioh Kim
From: Gioh Kim guru...@hanmail.net

The anon_inodes has already complete interfaces to create manage
many anonymous inodes but don't have interface to get
new inode. Other sub-modules can create anonymous inode
without creating and mounting it's own pseudo filesystem.

Signed-off-by: Gioh Kim gioh@lge.com
Acked-by: Rafael Aquini aqu...@redhat.com
---
 fs/anon_inodes.c| 6 ++
 include/linux/anon_inodes.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 80ef38c..1d51f96 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -162,6 +162,12 @@ err_put_unused_fd:
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfd);
 
+struct inode *anon_inode_new(void)
+{
+   return alloc_anon_inode(anon_inode_mnt-mnt_sb);
+}
+EXPORT_SYMBOL_GPL(anon_inode_new);
+
 static int __init anon_inode_init(void)
 {
anon_inode_mnt = kern_mount(anon_inode_fs_type);
diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h
index 8013a45..ddbd67f 100644
--- a/include/linux/anon_inodes.h
+++ b/include/linux/anon_inodes.h
@@ -15,6 +15,7 @@ struct file *anon_inode_getfile(const char *name,
void *priv, int flags);
 int anon_inode_getfd(const char *name, const struct file_operations *fops,
 void *priv, int flags);
+struct inode *anon_inode_new(void);
 
 #endif /* _LINUX_ANON_INODES_H */
 
-- 
2.1.4

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization