Skip to contentSkip to conversation

zsmalloc: make its pages can be migrated

RFC Superseded Hui Zhu 4 participants 7 messages Oct 15, 2015 – Oct 19, 2015

Subsystems (9)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hui Zhu

author
#0 lore raw

v2 cover zsmalloc: make its pages can be migrated

According to the review for the prev version [1], I got that I should not increase the size of struct page.
So I update it in new version.

And I also add check for CONFIG_MIGRATION to make function just work when CONFIG_MIGRATION is open.

Hui Zhu (3):
migrate: new struct migration and add it to struct page
zsmalloc: mark its page "PageMigration"
zram: make create "__GFP_MOVABLE" pool

 drivers/block/zram/zram_drv.c |    6 
 include/linux/migrate.h       |   43 ++
 include/linux/mm_types.h      |    3 
 mm/compaction.c               |    8 
 mm/migrate.c                  |   17 -
 mm/vmscan.c                   |    2 
 mm/zsmalloc.c                 |  605 +++++++++++++++++++++++++++++++++++++++---
 7 files changed, 639 insertions(+), 45 deletions(-)

[1] http://comments.gmane.org/gmane.linux.kernel.mm/139724

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#1 lore raw

RFC v2 1/3 migrate: new struct migration and add it to struct page

I got that add function interfaces is really not a good idea. So I add a new struct migration to put all migration interfaces and add this struct to struct page as union of "mapping".
Then the function doesn't need increase the size of struct page.

Also I change the flags from "PG_movable" to "PageMigration" according to the review.

---
 include/linux/migrate.h  | 30 ++++++++++++++++++++++++++++++
 include/linux/mm_types.h |  3 +++
 mm/compaction.c          |  8 ++++++++
 mm/migrate.c             | 17 +++++++++++++----
 mm/vmscan.c              |  2 +-
 5 files changed, 55 insertions(+), 5 deletions(-)
include/linux/migrate.h +30 -0
index cac1c09..8b8caba 100644
@@ -27,6 +27,31 @@ enum migrate_reason {
 };
 
 #ifdef CONFIG_MIGRATION
+struct migration {
+	int (*isolate)(struct page *page);
+	void (*put)(struct page *page);
+	int (*move)(struct page *page, struct page *newpage, int force,
+		       enum migrate_mode mode);
+};
+
+#define PAGE_MIGRATION_MAPCOUNT_VALUE (-512)
+
+static inline int PageMigration(struct page *page)
+{
+	return atomic_read(&page->_mapcount) == PAGE_MIGRATION_MAPCOUNT_VALUE;
+}
+
+static inline void __SetPageMigration(struct page *page)
+{
+	VM_BUG_ON_PAGE(atomic_read(&page->_mapcount) != -1, page);
+	atomic_set(&page->_mapcount, PAGE_MIGRATION_MAPCOUNT_VALUE);
+}
+
+static inline void __ClearPageMigration(struct page *page)
+{
+	VM_BUG_ON_PAGE(!PageMigration(page), page);
+	atomic_set(&page->_mapcount, -1);
+}
 
 extern void putback_movable_pages(struct list_head *l);
 extern int migrate_page(struct address_space *,
@@ -45,6 +70,11 @@ extern int migrate_page_move_mapping(struct address_space *mapping,
 		int extra_count);
 #else
 
+static inline int PageMigration(struct page *page)
+{
+	return false;
+}
+
 static inline void putback_movable_pages(struct list_head *l) {}
 static inline int migrate_pages(struct list_head *l, new_page_t new,
 		free_page_t free, unsigned long private, enum migrate_mode mode,
include/linux/mm_types.h +3 -0
index 3d6baa7..61d5da4 100644
@@ -56,6 +56,9 @@ struct page {
 						 * see PAGE_MAPPING_ANON below.
 						 */
 		void *s_mem;			/* slab first object */
+#ifdef CONFIG_MIGRATION
+		struct migration *migration;
+#endif
 	};
 
 	/* Second double word */
mm/compaction.c +8 -0
index c5c627a..d05822e 100644
@@ -752,6 +752,14 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 		 */
 		is_lru = PageLRU(page);
 		if (!is_lru) {
+#ifdef CONFIG_MIGRATION
+			if (PageMigration(page)) {
+				if (page->migration->isolate(page) == 0)
+					goto isolate_success;
+
+				continue;
+			}
+#endif
 			if (unlikely(balloon_page_movable(page))) {
 				if (balloon_page_isolate(page)) {
 					/* Successfully isolated */
mm/migrate.c +13 -4
index 842ecd7..2e20d4e 100644
@@ -93,7 +93,9 @@ void putback_movable_pages(struct list_head *l)
 		list_del(&page->lru);
 		dec_zone_page_state(page, NR_ISOLATED_ANON +
 				page_is_file_cache(page));
-		if (unlikely(isolated_balloon_page(page)))
+		if (PageMigration(page))
+			page->migration->put(page);
+		else if (unlikely(isolated_balloon_page(page)))
 			balloon_page_putback(page);
 		else
 			putback_lru_page(page);
@@ -953,7 +955,10 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,
 		if (unlikely(split_huge_page(page)))
 			goto out;
 
-	rc = __unmap_and_move(page, newpage, force, mode);
+	if (PageMigration(page))
+		rc = page->migration->move(page, newpage, force, mode);
+	else
+		rc = __unmap_and_move(page, newpage, force, mode);
 
 out:
 	if (rc != -EAGAIN) {
@@ -967,7 +972,9 @@ out:
 		dec_zone_page_state(page, NR_ISOLATED_ANON +
 				page_is_file_cache(page));
 		/* Soft-offlined page shouldn't go through lru cache list */
-		if (reason == MR_MEMORY_FAILURE) {
+		if (PageMigration(page))
+			page->migration->put(page);
+		else if (reason == MR_MEMORY_FAILURE) {
 			put_page(page);
 			if (!test_set_page_hwpoison(page))
 				num_poisoned_pages_inc();
@@ -983,7 +990,9 @@ out:
 	if (rc != MIGRATEPAGE_SUCCESS && put_new_page) {
 		ClearPageSwapBacked(newpage);
 		put_new_page(newpage, private);
-	} else if (unlikely(__is_movable_balloon_page(newpage))) {
+	} else if (PageMigration(newpage))
+		put_page(newpage);
+	else if (unlikely(__is_movable_balloon_page(newpage))) {
 		/* drop our reference, page already in the balloon */
 		put_page(newpage);
 	} else
mm/vmscan.c +1 -1
index 7f63a93..87d6934 100644
@@ -1245,7 +1245,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
 
 	list_for_each_entry_safe(page, next, page_list, lru) {
 		if (page_is_file_cache(page) && !PageDirty(page) &&
-		    !isolated_balloon_page(page)) {
+		    !isolated_balloon_page(page) && !PageMigration(page)) {
 			ClearPageActive(page);
 			list_move(&page->lru, &clean_pages);
 		}
Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

Re: [RFC v2 1/3] migrate: new struct migration and add it to struct page

Quoted 3 lines · Hui Zhu

I got that add function interfaces is really not a good idea. So I add a new struct migration to put all migration interfaces and add this struct to struct page as union of "mapping".

That's better, but not as flexible as the previously proposed approaches that Sergey pointed you at:

http://lkml.iu.edu/hypermail/linux/kernel/1507.0/03233.html
http://lkml.iu.edu/hypermail/linux/kernel/1508.1/00696.html

There the operations are reachable via mapping, so we can support the special operations migration also when mapping is otherwise needed; your patch excludes mapping.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#3 lore raw

Re: [RFC v2 1/3] migrate: new struct migration and add it to struct page

Quoted 8 lines · Vlastimil Babka
Quoted 3 lines · Hui Zhu

I got that add function interfaces is really not a good idea. So I add a new struct migration to put all migration interfaces and add this struct to struct page as union of "mapping".

That's better, but not as flexible as the previously proposed approaches that Sergey pointed you at:

Quoted 7 lines

http://lkml.iu.edu/hypermail/linux/kernel/1507.0/03233.html
http://lkml.iu.edu/hypermail/linux/kernel/1508.1/00696.html

There the operations are reachable via mapping, so we can support the special operations migration also when mapping is otherwise needed; your patch excludes mapping.

Hello Hui,

FYI, I take over the work from Gioh and have a plan to improve the work. So, Could you wait a bit? Of course, if you have better idea, feel free to post it.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [RFC v2 1/3] migrate: new struct migration and add it to struct page

Quoted 17 lines · Minchan Kim
Quoted 8 lines · Vlastimil Babka
Quoted 3 lines · Hui Zhu

I got that add function interfaces is really not a good idea. So I add a new struct migration to put all migration interfaces and add this struct to struct page as union of "mapping".

That's better, but not as flexible as the previously proposed approaches that Sergey pointed you at:

Quoted 7 lines

http://lkml.iu.edu/hypermail/linux/kernel/1507.0/03233.html
http://lkml.iu.edu/hypermail/linux/kernel/1508.1/00696.html

There the operations are reachable via mapping, so we can support the special operations migration also when mapping is otherwise needed; your patch excludes mapping.

Quoted 7 lines

Hello Hui,

FYI, I take over the work from Gioh and have a plan to improve the work. So, Could you wait a bit? Of course, if you have better idea, feel free to post it.

Thanks.

Hi Minchan and Vlastimil,

If you don't mind. I want to wait the patches and focus on page movable of zsmalloc part.
What do you think about it?

Best,
Hui

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#5 lore raw

RFC v2 2/3 zsmalloc: mark its page "PageMigration"

In reply to Hui Zhu

Most of idea is same with prev version that mark zsmalloc's page "PageMigration" and introduce the function for the interfaces zs_isolatepage, zs_isolatepage and zs_migratepage.

But I put data of zs from struct page to struct migration.

---
 include/linux/migrate.h |  13 ++
 mm/zsmalloc.c           | 605 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 578 insertions(+), 40 deletions(-)
include/linux/migrate.h +13 -0
index 8b8caba..b8f9448 100644
@@ -32,6 +32,19 @@ struct migration {
 	void (*put)(struct page *page);
 	int (*move)(struct page *page, struct page *newpage, int force,
 		       enum migrate_mode mode);
+#ifdef CONFIG_ZSMALLOC
+	struct {
+		/* For all zs_page.  */
+		struct list_head zs_lru;
+		struct page *zs_page;
+		void *zs_class;
+
+		/* For all zs_page first_page.  */
+		int zs_fg;
+		unsigned zs_inuse;
+		unsigned zs_objects;
+	};
+#endif
 };
 
 #define PAGE_MIGRATION_MAPCOUNT_VALUE (-512)
mm/zsmalloc.c +565 -40

936 lines not on this page · raw message

Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#6 lore raw

RFC v2 3/3 zram: make create "__GFP_MOVABLE" pool

In reply to Hui Zhu

Change the flags when call zs_create_pool to make zram alloc movable zsmalloc page if CONFIG_MIGRATION.

---
 drivers/block/zram/zram_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/zram/zram_drv.c +6 -0
index 9fa15bb..3e1e955 100644
@@ -514,7 +514,13 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
 		goto out_error;
 	}
 
+#ifdef CONFIG_MIGRATION
+	meta->mem_pool
+		= zs_create_pool(pool_name,
+				 GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE);
+#else
 	meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
+#endif
 	if (!meta->mem_pool) {
 		pr_err("Error creating memory pool\n");
 		goto out_error;
Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>