Re: [PATCH] add generic callbacks into compaction

2015-04-12 Thread Gioh Kim



2015-04-07 오전 9:59에 Minchan Kim 이(가) 쓴 글:

Hello Gioh,

I wanted to have such feature for zsmalloc.
Thanks for the work.

On Wed, Apr 01, 2015 at 08:11:30AM +0900, Gioh Kim wrote:

I sent a patch about page allocation for less fragmentation.
http://permalink.gmane.org/gmane.linux.kernel.mm/130599

It proposes a page allocator allocates pages in the same pageblock
for the drivers to move their unmovable pages. Some drivers which comsumes many 
pages
and increases system fragmentation use the allocator to move their pages to
decrease fragmentation.

I think I can try another approach.
There is a compaction code for balloon pages.
But the compaction code cannot migrate pages of other drivers.
If there is a generic migration framework applicable to any drivers,
drivers can register their migration functions.
And the compaction can migrate movable pages and also driver's pages.

I'm not familiar with virtualization so I couldn't test this patch yet.
But if mm developers agree with this approach, I will complete this patch.

I would do appreciate any feedback.


Could you separate introducing migrate core patchset and balloon patchset for
using the feature?


Sure.





Signed-off-by: Gioh Kim gioh@lge.com
---
  drivers/virtio/virtio_balloon.c|2 ++
  include/linux/balloon_compaction.h |   23 +---
  include/linux/fs.h |3 ++
  include/linux/pagemap.h|   26 ++
  mm/balloon_compaction.c|   68 ++--
  mm/compaction.c|7 ++--
  mm/migrate.c   |   24 ++---
  7 files changed, 129 insertions(+), 24 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 0413157..cd9b8e4 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -486,6 +486,8 @@ static int virtballoon_probe(struct virtio_device *vdev)

balloon_devinfo_init(vb-vb_dev_info);
  #ifdef CONFIG_BALLOON_COMPACTION
+   vb-vb_dev_info.mapping = balloon_mapping_alloc(vb-vb_dev_info,
+   balloon_aops);
vb-vb_dev_info.migratepage = virtballoon_migratepage;
  #endif

diff --git a/include/linux/balloon_compaction.h 
b/include/linux/balloon_compaction.h
index 9b0a15d..0af32b3 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -62,6 +62,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 address_space *mapping;
  };

  extern struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info);
@@ -76,10 +77,22 @@ static inline void balloon_devinfo_init(struct 
balloon_dev_info *balloon)
  }

  #ifdef CONFIG_BALLOON_COMPACTION
-extern bool balloon_page_isolate(struct page *page);
-extern void balloon_page_putback(struct page *page);
-extern int balloon_page_migrate(struct page *newpage,
-   struct page *page, enum migrate_mode mode);
+extern const struct address_space_operations balloon_aops;
+extern int balloon_page_isolate(struct page *page);
+extern int balloon_page_putback(struct page *page);
+extern int balloon_page_migrate(struct address_space *mapping,
+   struct page *newpage,
+   struct page *page,
+   enum migrate_mode mode);
+
+extern struct address_space
+*balloon_mapping_alloc(struct balloon_dev_info *b_dev_info,
+  const struct address_space_operations *a_ops);
+
+static inline void balloon_mapping_free(struct address_space *balloon_mapping)
+{
+   kfree(balloon_mapping);
+}

  /*
   * __is_movable_balloon_page - helper to perform @page PageBalloon tests
@@ -123,6 +136,7 @@ static inline bool isolated_balloon_page(struct page *page)
  static inline void balloon_page_insert(struct balloon_dev_info *balloon,
   struct page *page)
  {
+   page-mapping = balloon-mapping;
__SetPageBalloon(page);
SetPagePrivate(page);
set_page_private(page, (unsigned long)balloon);
@@ -139,6 +153,7 @@ static inline void balloon_page_insert(struct 
balloon_dev_info *balloon,
   */
  static inline void balloon_page_delete(struct page *page)
  {
+   page-mapping = NULL;
__ClearPageBalloon(page);
set_page_private(page, 0);
if (PagePrivate(page)) {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b4d71b5..de463b9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -368,6 +368,9 @@ struct address_space_operations {
 */
int (*migratepage) (struct address_space *,
struct page *, struct page *, enum migrate_mode);
+   int (*isolatepage)(struct page *);

Re: [PATCH] add generic callbacks into compaction

2015-04-06 Thread Minchan Kim
Hello Gioh,

I wanted to have such feature for zsmalloc.
Thanks for the work.

On Wed, Apr 01, 2015 at 08:11:30AM +0900, Gioh Kim wrote:
 I sent a patch about page allocation for less fragmentation.
 http://permalink.gmane.org/gmane.linux.kernel.mm/130599
 
 It proposes a page allocator allocates pages in the same pageblock
 for the drivers to move their unmovable pages. Some drivers which comsumes 
 many pages
 and increases system fragmentation use the allocator to move their pages to
 decrease fragmentation.
 
 I think I can try another approach.
 There is a compaction code for balloon pages.
 But the compaction code cannot migrate pages of other drivers.
 If there is a generic migration framework applicable to any drivers,
 drivers can register their migration functions.
 And the compaction can migrate movable pages and also driver's pages.
 
 I'm not familiar with virtualization so I couldn't test this patch yet.
 But if mm developers agree with this approach, I will complete this patch.
 
 I would do appreciate any feedback.

Could you separate introducing migrate core patchset and balloon patchset for
using the feature?

 
 Signed-off-by: Gioh Kim gioh@lge.com
 ---
  drivers/virtio/virtio_balloon.c|2 ++
  include/linux/balloon_compaction.h |   23 +---
  include/linux/fs.h |3 ++
  include/linux/pagemap.h|   26 ++
  mm/balloon_compaction.c|   68 
 ++--
  mm/compaction.c|7 ++--
  mm/migrate.c   |   24 ++---
  7 files changed, 129 insertions(+), 24 deletions(-)
 
 diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
 index 0413157..cd9b8e4 100644
 --- a/drivers/virtio/virtio_balloon.c
 +++ b/drivers/virtio/virtio_balloon.c
 @@ -486,6 +486,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
  
   balloon_devinfo_init(vb-vb_dev_info);
  #ifdef CONFIG_BALLOON_COMPACTION
 + vb-vb_dev_info.mapping = balloon_mapping_alloc(vb-vb_dev_info,
 + balloon_aops);
   vb-vb_dev_info.migratepage = virtballoon_migratepage;
  #endif
  
 diff --git a/include/linux/balloon_compaction.h 
 b/include/linux/balloon_compaction.h
 index 9b0a15d..0af32b3 100644
 --- a/include/linux/balloon_compaction.h
 +++ b/include/linux/balloon_compaction.h
 @@ -62,6 +62,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 address_space *mapping;
  };
  
  extern struct page *balloon_page_enqueue(struct balloon_dev_info 
 *b_dev_info);
 @@ -76,10 +77,22 @@ static inline void balloon_devinfo_init(struct 
 balloon_dev_info *balloon)
  }
  
  #ifdef CONFIG_BALLOON_COMPACTION
 -extern bool balloon_page_isolate(struct page *page);
 -extern void balloon_page_putback(struct page *page);
 -extern int balloon_page_migrate(struct page *newpage,
 - struct page *page, enum migrate_mode mode);
 +extern const struct address_space_operations balloon_aops;
 +extern int balloon_page_isolate(struct page *page);
 +extern int balloon_page_putback(struct page *page);
 +extern int balloon_page_migrate(struct address_space *mapping,
 + struct page *newpage,
 + struct page *page,
 + enum migrate_mode mode);
 +
 +extern struct address_space
 +*balloon_mapping_alloc(struct balloon_dev_info *b_dev_info,
 +const struct address_space_operations *a_ops);
 +
 +static inline void balloon_mapping_free(struct address_space 
 *balloon_mapping)
 +{
 + kfree(balloon_mapping);
 +}
  
  /*
   * __is_movable_balloon_page - helper to perform @page PageBalloon tests
 @@ -123,6 +136,7 @@ static inline bool isolated_balloon_page(struct page 
 *page)
  static inline void balloon_page_insert(struct balloon_dev_info *balloon,
  struct page *page)
  {
 + page-mapping = balloon-mapping;
   __SetPageBalloon(page);
   SetPagePrivate(page);
   set_page_private(page, (unsigned long)balloon);
 @@ -139,6 +153,7 @@ static inline void balloon_page_insert(struct 
 balloon_dev_info *balloon,
   */
  static inline void balloon_page_delete(struct page *page)
  {
 + page-mapping = NULL;
   __ClearPageBalloon(page);
   set_page_private(page, 0);
   if (PagePrivate(page)) {
 diff --git a/include/linux/fs.h b/include/linux/fs.h
 index b4d71b5..de463b9 100644
 --- a/include/linux/fs.h
 +++ b/include/linux/fs.h
 @@ -368,6 +368,9 @@ struct address_space_operations {
*/
   int (*migratepage) (struct address_space *,
   struct page *, struct page *, enum migrate_mode);
 + int (*isolatepage)(struct page *);

It