Support non-lru page migration
Subsystems (14)
Minchan Kim
maintainerv5 cover Support non-lru page migration
Recently, I got many reports about perfermance degradation in embedded system(Android mobile phone, webOS TV and so on) and easy fork fail.
The problem was fragmentation caused by zram and GPU driver mainly. With memory pressure, their pages were spread out all of pageblock and it cannot be migrated with current compaction algorithm which supports only LRU pages. In the end, compaction cannot work well so reclaimer shrinks all of working set pages. It made system very slow and even to fail to fork easily which requires order-[2 or 3] allocations.
Other pain point is that they cannot use CMA memory space so when OOM kill happens, I can see many free pages in CMA area, which is not memory efficient. In our product which has big CMA memory, it reclaims zones too exccessively to allocate GPU and zram page although there are lots of free space in CMA so system becomes very slow easily.
To solve these problem, this patch tries to add facility to migrate non-lru pages via introducing new functions and page flags to help migration.
struct address_space_operations {
..
..
bool (*isolate_page)(struct page *, isolate_mode_t);
void (*putback_page)(struct page *);
..
}new page flags
PG_movable
PG_isolated
For details, please read description in "mm: migrate: support non-lru movable page migration".
Originally, Gioh Kim had tried to support this feature but he moved so I took over the work. I took many code from his work and changed a little bit and Konstantin Khlebnikov helped Gioh a lot so he should deserve to have many credit, too.
And I should mention Chulmin who have tested this patchset heavily so I can find many bugs from him. :)
Thanks, Gioh, Konstantin and Chulmin!
This patchset consists of five parts.
1. clean up migration
mm: use put_page to free page instead of putback_lru_page
2. add non-lru page migration feature
mm: migrate: support non-lru movable page migration
3. rework KVM memory-ballooning
mm: balloon: use general non-lru movable page feature
4. zsmalloc refactoring for preparing page migration
zsmalloc: keep max_object in size_class
zsmalloc: use bit_spin_lock
zsmalloc: use accessor
zsmalloc: factor page chain functionality out
zsmalloc: introduce zspage structure
zsmalloc: separate free_zspage from putback_zspage
zsmalloc: use freeobj for index
5. zsmalloc page migration
zsmalloc: page migration support
zram: use __GFP_MOVABLE for memory allocation
* From v4
* rebase on mmotm-2016-05-05-17-19
* fix huge object migration - Chulmin
* !CONFIG_COMPACTION support for zsmalloc
* From v3
* rebase on mmotm-2016-04-06-20-40
* fix swap_info deadlock - Chulmin
* race without page_lock - Vlastimil
* no use page._mapcount for potential user-mapped page driver - Vlastimil
* fix and enhance doc/description - Vlastimil
* use page->mapping lower bits to represent PG_movable
* make driver side's rule simple.
* From v2
* rebase on mmotm-2016-03-29-15-54-16
* check PageMovable before lock_page - Joonsoo
* check PageMovable before PageIsolated checking - Joonsoo
* add more description about rule
* From v1
* rebase on v4.5-mmotm-2016-03-17-15-04
* reordering patches to merge clean-up patches first
* add Acked-by/Reviewed-by from Vlastimil and Sergey
* use each own mount model instead of reusing anon_inode_fs - Al Viro
* small changes - YiPing, Gioh
Minchan Kim (12):
mm: use put_page to free page instead of putback_lru_page
mm: migrate: support non-lru movable page migration
mm: balloon: use general non-lru movable page feature
zsmalloc: keep max_object in size_class
zsmalloc: use bit_spin_lock
zsmalloc: use accessor
zsmalloc: factor page chain functionality out
zsmalloc: introduce zspage structure
zsmalloc: separate free_zspage from putback_zspage
zsmalloc: use freeobj for index
zsmalloc: page migration support
zram: use __GFP_MOVABLE for memory allocation
Documentation/filesystems/Locking | 4 + Documentation/filesystems/vfs.txt | 11 + Documentation/vm/page_migration | 107 ++- drivers/block/zram/zram_drv.c | 6 +- drivers/virtio/virtio_balloon.c | 52 +- include/linux/balloon_compaction.h | 51 +- include/linux/fs.h | 2 + include/linux/ksm.h | 3 +- include/linux/migrate.h | 5 + include/linux/mm.h | 1 + include/linux/page-flags.h | 29 +- include/uapi/linux/magic.h | 2 + mm/balloon_compaction.c | 94 +-- mm/compaction.c | 40 +- mm/ksm.c | 4 +- mm/migrate.c | 287 ++++++-- mm/page_alloc.c | 2 +- mm/util.c | 6 +- mm/vmscan.c | 2 +- mm/zsmalloc.c | 1351 +++++++++++++++++++++++++----------- 20 files changed, 1453 insertions(+), 606 deletions(-)
Signature · 1 line
1.9.1
Minchan Kim
maintainerPATCH v5 1/12 mm: use put_page to free page instead of putback_lru_page
Procedure of page migration is as follows:
First of all, it should isolate a page from LRU and try to migrate the page. If it is successful, it releases the page for freeing. Otherwise, it should put the page back to LRU list.
For LRU pages, we have used putback_lru_page for both freeing and putback to LRU list. It's okay because put_page is aware of LRU list so if it releases last refcount of the page, it removes the page from LRU list. However, It makes unnecessary operations (e.g., lru_cache_add, pagevec and flags operations. It would be not significant but no worth to do) and harder to support new non-lru page migration because put_page isn't aware of non-lru page's data structure.
To solve the problem, we can add new hook in put_page with PageMovable flags check but it can increase overhead in hot path and needs new locking scheme to stabilize the flag check with put_page.
So, this patch cleans it up to divide two semantic(ie, put and putback). If migration is successful, use put_page instead of putback_lru_page and use putback_lru_page only on failure. That makes code more readable and doesn't add overhead in put_page.
Comment from Vlastimil
"Yeah, and compaction (perhaps also other migration users) has to drain the lru pvec... Getting rid of this stuff is worth even by itself."
--- mm/migrate.c | 64 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 24 deletions(-)
mm/migrate.c +40 -24
@@ -913,6 +913,19 @@ static int __unmap_and_move(struct page *page, struct page *newpage,put_anon_vma (anon_vma);unlock_page (page); out: +/* +* If migration is successful, decrease refcount of the newpage +* which will not free the page because new page owner increased +* refcounter. As well, if it is LRU page, add the page to LRU +* list in here. +*/ +if (rc ==MIGRATEPAGE_SUCCESS ) { +if (unlikely (__is_movable_balloon_page (newpage))) +put_page (newpage); +else +putback_lru_page (newpage); + } +return rc; }
@@ -946,6 +959,12 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,if (page_count (page) ==1 ) {/* page was freed from under us. So we are done. */ +ClearPageActive (page); +ClearPageUnevictable (page); +if (put_new_page) +put_new_page (newpage, private); +else +put_page (newpage); goto out; }
@@ -958,10 +977,8 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, } rc =__unmap_and_move (page, newpage, force, mode); -if (rc ==MIGRATEPAGE_SUCCESS ) { - put_new_page =NULL ; +if (rc ==MIGRATEPAGE_SUCCESS )set_page_owner_migrate_reason (newpage, reason); - } out:if (rc != -EAGAIN ) {
@@ -974,34 +991,33 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,list_del (&page->lru);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 && rc ==MIGRATEPAGE_SUCCESS ) { + } + +/* +* If migration is successful, releases reference grabbed during +* isolation. Otherwise, restore the page to right list unless +* we want to retry. +*/ +if (rc ==MIGRATEPAGE_SUCCESS ) { +put_page (page); +if (reason ==MR_MEMORY_FAILURE ) {/* -* With this release, we free successfully migrated -* page and set PG_HWPoison on just freed page -* intentionally. Although it's rather weird, it's how -* HWPoison flag works at the moment. +* Set PG_HWPoison on just freed page +* intentionally. Although it's rather weird, +* it's how HWPoison flag works at the moment. */ -put_page (page);if (!test_set_page_hwpoison (page))num_poisoned_pages_inc (); - }else + } + }else { +if (rc != -EAGAIN )putback_lru_page (page); +if (put_new_page) +put_new_page (newpage, private); +else +put_page (newpage); } -/* -* If migration was not successful and there's a freeing callback, use -* it. Otherwise, putback_lru_page() will drop the reference grabbed -* during isolation. -*/ -if (put_new_page) -put_new_page (newpage, private); -else if (unlikely (__is_movable_balloon_page (newpage))) { -/* drop our reference, page already in the balloon */ -put_page (newpage); - }else -putback_lru_page (newpage); -if (result) {if (rc) *result = rc;
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>
Minchan Kim
maintainerPATCH v5 2/12 mm: migrate: support non-lru movable page migration
In reply to Minchan KimWe have allowed migration for only LRU pages until now and it was enough to make high-order pages. But recently, embedded system(e.g., webOS, android) uses lots of non-movable pages(e.g., zram, GPU memory) so we have seen several reports about troubles of small high-order allocation. For fixing the problem, there were several efforts (e,g,. enhance compaction algorithm, SLUB fallback to 0-order page, reserved memory, vmalloc and so on) but if there are lots of non-movable pages in system, their solutions are void in the long run.
So, this patch is to support facility to change non-movable pages with movable. For the feature, this patch introduces functions related to migration to address_space_operations as well as some page flags.
If a driver want to make own pages movable, it should define three functions which are function pointers of struct address_space_operations.
1. bool (*isolate_page) (struct page *page, isolate_mode_t mode);
What VM expects on isolate_page function of driver is to return *true* if driver isolates page successfully. On returing true, VM marks the page as PG_isolated so concurrent isolation in several CPUs skip the page for isolation. If a driver cannot isolate the page, it should return *false*.
Once page is successfully isolated, VM uses page.lru fields so driver shouldn't expect to preserve values in that fields.
2. int (*migratepage) (struct address_space *mapping,
struct page *newpage, struct page *oldpage, enum migrate_mode);
After isolation, VM calls migratepage of driver with isolated page. The function of migratepage is to move content of the old page to new page and set up fields of struct page newpage. Keep in mind that you should clear PG_movable of oldpage via __ClearPageMovable under page_lock if you migrated the oldpage successfully and returns MIGRATEPAGE_SUCCESS. If driver cannot migrate the page at the moment, driver can return -EAGAIN. On -EAGAIN, VM will retry page migration in a short time because VM interprets -EAGAIN as "temporal migration failure". On returning any error except -EAGAIN, VM will give up the page migration without retrying in this time.
Driver shouldn't touch page.lru field VM using in the functions.
3. void (*putback_page)(struct page *);
If migration fails on isolated page, VM should return the isolated page to the driver so VM calls driver's putback_page with migration failed page. In this function, driver should put the isolated page back to the own data structure.
4. non-lru movable page flags
There are two page flags for supporting non-lru movable page.
* PG_movable
Driver should use the below function to make page movable under page_lock.
void __SetPageMovable(struct page *page, struct address_space *mapping)
It needs argument of address_space for registering migration family functions which will be called by VM. Exactly speaking, PG_movable is not a real flag of struct page. Rather than, VM reuses page->mapping's lower bits to represent it.
#define PAGE_MAPPING_MOVABLE 0x2 page->mapping = page->mapping | PAGE_MAPPING_MOVABLE;
so driver shouldn't access page->mapping directly. Instead, driver should use page_mapping which mask off the low two bits of page->mapping so it can get right struct address_space.
For testing of non-lru movable page, VM supports __PageMovable function. However, it doesn't guarantee to identify non-lru movable page because page->mapping field is unified with other variables in struct page. As well, if driver releases the page after isolation by VM, page->mapping doesn't have stable value although it has PAGE_MAPPING_MOVABLE (Look at __ClearPageMovable). But __PageMovable is cheap to catch whether page is LRU or non-lru movable once the page has been isolated. Because LRU pages never can have PAGE_MAPPING_MOVABLE in page->mapping. It is also good for just peeking to test non-lru movable pages before more expensive checking with lock_page in pfn scanning to select victim.
For guaranteeing non-lru movable page, VM provides PageMovable function. Unlike __PageMovable, PageMovable functions validates page->mapping and mapping->a_ops->isolate_page under lock_page. The lock_page prevents sudden destroying of page->mapping.
Driver using __SetPageMovable should clear the flag via __ClearMovablePage under page_lock before the releasing the page.
* PG_isolated
To prevent concurrent isolation among several CPUs, VM marks isolated page as PG_isolated under lock_page. So if a CPU encounters PG_isolated non-lru movable page, it can skip it. Driver doesn't need to manipulate the flag because VM will set/clear it automatically. Keep in mind that if driver sees PG_isolated page, it means the page have been isolated by VM so it shouldn't touch page.lru field.PG_isolated is alias with PG_reclaim flag so driver shouldn't use the flag for own purpose.
--- Documentation/filesystems/Locking | 4 + Documentation/filesystems/vfs.txt | 11 ++ Documentation/vm/page_migration | 107 +++++++++++++++++- include/linux/fs.h | 2 + include/linux/ksm.h | 3 +- include/linux/migrate.h | 5 + include/linux/mm.h | 1 + include/linux/page-flags.h | 29 +++-- mm/compaction.c | 47 +++++--- mm/ksm.c | 4 +- mm/migrate.c | 222 ++++++++++++++++++++++++++++++++++---- mm/page_alloc.c | 2 +- mm/util.c | 6 +- 13 files changed, 391 insertions(+), 52 deletions(-)
Documentation/filesystems/Locking +4 -0
@@ -195,7 +195,9 @@ unlocks and drops the reference. int (*releasepage) (struct page *, int); void (*freepage)(struct page *); int (*direct_IO)(struct kiocb *, struct iov_iter *iter); + bool (*isolate_page) (struct page *, isolate_mode_t); int (*migratepage)(struct address_space *, struct page *, struct page *); + void (*putback_page) (struct page *); int (*launder_page)(struct page *); int (*is_partially_uptodate)(struct page *, unsigned long, unsigned long); int (*error_remove_page)(struct address_space *, struct page *);
@@ -219,7 +221,9 @@ invalidatepage: yes releasepage: yes freepage: yes direct_IO: +isolate_page: yes migratepage: yes (both) +putback_page: yes launder_page: yes is_partially_uptodate: yes error_remove_page: yes
Documentation/filesystems/vfs.txt +11 -0
@@ -592,9 +592,14 @@ struct address_space_operations { int (*releasepage) (struct page *, int); void (*freepage)(struct page *); ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter); + /* isolate a page for migration */ + bool (*isolate_page) (struct page *, isolate_mode_t); /* migrate the contents of a page to the specified target */ int (*migratepage) (struct page *, struct page *); + /* put migration-failed page back to right list */ + void (*putback_page) (struct page *); int (*launder_page) (struct page *); + int (*is_partially_uptodate) (struct page *, unsigned long, unsigned long); void (*is_dirty_writeback) (struct page *, bool *, bool *);
@@ -747,6 +752,10 @@ struct address_space_operations { and transfer data directly between the storage and the application's address space. + isolate_page: Called by the VM when isolating a movable non-lru page. + If page is successfully isolated, VM marks the page as PG_isolated + via __SetPageIsolated. + migrate_page: This is used to compact the physical memory usage. If the VM wants to relocate a page (maybe off a memory card that is signalling imminent failure) it will pass a new page
@@ -754,6 +763,8 @@ struct address_space_operations { transfer any private data across and update any references that it has to the page. + putback_page: Called by the VM when isolated page's migration fails. + launder_page: Called before freeing a page - it writes back the dirty page. To prevent redirtying the page, it is kept locked during the whole operation.
Documentation/vm/page_migration +106 -1
111 lines not on this page · raw message
include/linux/fs.h +2 -0
@@ -403,6 +403,8 @@ struct address_space_operations {*/ int (*migratepage) (struct address_space *,struct page *,struct page *,enum migrate_mode ); +bool (*isolate_page)(struct page *,isolate_mode_t ); +void (*putback_page)(struct page *);int (*launder_page) (struct page *);int (*is_partially_uptodate) (struct page *,unsigned long ,unsigned long );
include/linux/ksm.h +1 -2
@@ -43,8 +43,7 @@ static inline struct stable_node *page_stable_node(struct page *page)static inline void set_page_stable_node (struct page *page,struct stable_node *stable_node) { - page->mapping = (void *)stable_node + - (PAGE_MAPPING_ANON |PAGE_MAPPING_KSM ); + page->mapping = (void *)((unsigned long )stable_node |PAGE_MAPPING_KSM ); }/*
include/linux/migrate.h +5 -0
@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);extern int migrate_prep (void );extern int migrate_prep_local (void );
include/linux/mm.h +1 -0
@@ -1021,6 +1021,7 @@ static inline pgoff_t page_file_index(struct page *page) }bool page_mapped (struct page *page); +struct address_space *page_mapping (struct page *page);/* * Return true only if the page has been allocated with
include/linux/page-flags.h +21 -8
@@ -129,6 +129,9 @@ enum pageflags {/* Compound pages. Stored in first tail page's flags */ PG_double_map = PG_private_2, + +/* non-lru isolated movable page */ + PG_isolated = PG_reclaim, };#ifndef __GENERATING_BOUNDS_H
@@ -361,25 +364,33 @@ PAGEFLAG(Idle, idle, PF_ANY)* and then page->mapping points, not to an anon_vma, but to a private * structure which KSM associates with that merged page. See ksm.h. * -* PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is currently never used. +* PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is used for non-lru movable +* page and then page->mapping points a struct address_space. * * Please note that, confusingly, "page_mapping" refers to the inode * address_space which maps the page from disk; whereas "page_mapped" * refers to user virtual address space into which the page is mapped. */ -#define PAGE_MAPPING_ANON 1 -#define PAGE_MAPPING_KSM 2 -#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM) +#define PAGE_MAPPING_ANON 0x1 +#define PAGE_MAPPING_MOVABLE 0x2 +#define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) +#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) -static __always_inline int PageAnonHead(struct page *page) +static __always_inline int PageMappingFlag(struct page *page) { -return ((unsigned long )page->mapping &PAGE_MAPPING_ANON ) !=0 ; +return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) !=0 ; } static __always_inline int PageAnon(struct page *page) { page =compound_head (page); -return PageAnonHead (page); +return ((unsigned long )page->mapping &PAGE_MAPPING_ANON ) !=0 ; +} + +static __always_inline int __PageMovable(struct page *page) +{ +return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) == +PAGE_MAPPING_MOVABLE ; }#ifdef CONFIG_KSM
@@ -393,7 +404,7 @@ static __always_inline int PageKsm(struct page *page) { page =compound_head (page);return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) == - (PAGE_MAPPING_ANON |PAGE_MAPPING_KSM ); +PAGE_MAPPING_KSM ; }#else TESTPAGEFLAG_FALSE (Ksm)
@@ -641,6 +652,8 @@ static inline void __ClearPageBalloon(struct page *page)atomic_set (&page->_mapcount,-1 ); } +__PAGEFLAG (Isolated, isolated,PF_ANY ); +/* * If network-based swap is enabled, sl*b must keep track of whether pages * were allocated from pfmemalloc reserves.
mm/compaction.c +31 -16
60 lines not on this page · raw message
mm/ksm.c +2 -2
@@ -532,8 +532,8 @@ static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it)void *expected_mapping;unsigned long kpfn; - expected_mapping = (void *)stable_node + - (PAGE_MAPPING_ANON |PAGE_MAPPING_KSM ); + expected_mapping = (void *)((unsigned long )stable_node | +PAGE_MAPPING_KSM ); again: kpfn =READ_ONCE (stable_node->kpfn); page =pfn_to_page (kpfn);
mm/migrate.c +202 -20
297 lines not on this page · raw message
mm/page_alloc.c +1 -1
@@ -1015,7 +1015,7 @@ static __always_inline bool free_pages_prepare(struct page *page, (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP ; } } -if (PageAnonHead (page)) +if (PageMappingFlag (page)) page->mapping =NULL ;if (check_free) bad +=free_pages_check (page);
mm/util.c +4 -2
@@ -399,10 +399,12 @@ struct address_space *page_mapping(struct page *page) } mapping = page->mapping; -if ((unsigned long )mapping &PAGE_MAPPING_FLAGS ) +if ((unsigned long )mapping &PAGE_MAPPING_ANON )return NULL ; -return mapping; + +return (void *)((unsigned long )mapping & ~PAGE_MAPPING_FLAGS ); } +EXPORT_SYMBOL (page_mapping);/* Slow path of page_mapcount() for compound pages */ int __page_mapcount (struct page *page)
Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
Quoted 8 lines · Minchan Kim
+++
b/include/linux/migrate.hinclude/linux/migrate.h +3
-0@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);
include/linux/migrate.h extern char *migrate_reason_names[MR_TYPES]; · line 47
Quoted 10 lines
include/linux/migrate.h +2
-0extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);extern int migrate_prep (void );extern int migrate_prep_local (void );
__ClearPageMovable() is under CONFIG_MIGRATION in include/linux/migrate.h, but zsmalloc checks for CONFIG_COMPACTION.
can we have stub declarations of movable functions for !CONFIG_MIGRATION builds? otherwise the users (zsmalloc, for example) have to do things like
static void reset_page(struct page *page)
{
#ifdef CONFIG_COMPACTION
__ClearPageMovable(page);
#endif
clear_bit(PG_private, &page->flags);
clear_bit(PG_private_2, &page->flags);
set_page_private(page, 0);
ClearPageHugeObject(page);
page->freelist = NULL;
}-ss
--
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>
Minchan Kim
maintainerRe: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
Quoted 17 lines · Sergey Senozhatsky
Quoted 16 lines · Minchan Kim
+++
b/include/linux/migrate.hinclude/linux/migrate.h +5
-0@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);
Quoted 5 lines
include/linux/migrate.h extern char *migrate_reason_names[MR_TYPES]; · line 47
Quoted 2 lines
include/linux/migrate.h +0
-0extern int migrate_prep (void );extern int migrate_prep_local (void );
__ClearPageMovable()is underCONFIG_MIGRATIONininclude/linux/migrate.h, but zsmalloc checks forCONFIG_COMPACTION.
Thanks!
PageMovable check function should be in compact.c, I think. I will fix it.
Quoted 16 lines
can we have stub declarations of movable functions for !CONFIG_MIGRATION builds? otherwise the users (zsmalloc, for example) have to do things like
static void
reset_page(struct page *page)
{#ifdef CONFIG_COMPACTION __ClearPageMovable(page); #endif clear_bit(PG_private, &page->flags); clear_bit(PG_private_2, &page->flags); set_page_private(page, 0); ClearPageHugeObject(page); page->freelist = NULL; }
Quoted 1 line
-ss
--
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>
Minchan Kim
maintainerRe: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
In reply to Sergey SenozhatskyQuoted 17 lines · Sergey Senozhatsky
Quoted 16 lines · Minchan Kim
+++
b/include/linux/migrate.hinclude/linux/migrate.h +5
-0@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);
Quoted 5 lines
include/linux/migrate.h extern char *migrate_reason_names[MR_TYPES]; · line 47
Quoted 2 lines
include/linux/migrate.h +0
-0extern int migrate_prep (void );extern int migrate_prep_local (void );
__ClearPageMovable()is underCONFIG_MIGRATIONininclude/linux/migrate.h, but zsmalloc checks forCONFIG_COMPACTION.
Thanks!
PageMovable check function should be in compact.c, I think. I will fix it.
Quoted 17 lines
can we have stub declarations of movable functions for !CONFIG_MIGRATION builds? otherwise the users (zsmalloc, for example) have to do things like
static void
reset_page(struct page *page)
{#ifdef CONFIG_COMPACTION __ClearPageMovable(page); #endif clear_bit(PG_private, &page->flags); clear_bit(PG_private_2, &page->flags); set_page_private(page, 0); ClearPageHugeObject(page); page->freelist = NULL; }-ss
Re: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
In reply to Minchan KimQuoted 8 lines · Minchan Kim
+++
b/include/linux/migrate.hinclude/linux/migrate.h +3
-0@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);
include/linux/migrate.h extern char *migrate_reason_names[MR_TYPES]; · line 47
Quoted 10 lines
include/linux/migrate.h +2
-0extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);extern int migrate_prep (void );extern int migrate_prep_local (void );
__ClearPageMovable() is under CONFIG_MIGRATION in include/linux/migrate.h, but zsmalloc checks for CONFIG_COMPACTION.
can we have stub declarations of movable functions for !CONFIG_MIGRATION builds? otherwise the users (zsmalloc, for example) have to do things like
static void reset_page(struct page *page)
{
#ifdef CONFIG_COMPACTION
__ClearPageMovable(page);
#endif
clear_bit(PG_private, &page->flags);
clear_bit(PG_private_2, &page->flags);
set_page_private(page, 0);
ClearPageHugeObject(page);
page->freelist = NULL;
}-ss
Re: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
In reply to Minchan KimOn (05/09/16 11:20), Minchan Kim wrote:
[..]
Quoted 8 lines
+++
b/include/linux/migrate.hinclude/linux/migrate.h +3
-0@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);
include/linux/migrate.h extern char *migrate_reason_names[MR_TYPES]; · line 47
Quoted 10 lines
include/linux/migrate.h +2
-0extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);extern int migrate_prep (void );extern int migrate_prep_local (void );
given that some of Movable users can be built as modules, shouldn't at least some of those symbols be exported via EXPORT_SYMBOL?
-ss
Minchan Kim
maintainerRe: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
Quoted 18 lines · Sergey Senozhatsky
On (05/09/16 11:20), Minchan Kim wrote:
[..]Quoted 16 lines
+++
b/include/linux/migrate.hinclude/linux/migrate.h +5
-0@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);
Quoted 5 lines
include/linux/migrate.h extern char *migrate_reason_names[MR_TYPES]; · line 47
Quoted 2 lines
include/linux/migrate.h +0
-0extern int migrate_prep (void );extern int migrate_prep_local (void );given that some of Movable users can be built as modules, shouldn't at least some of those symbols be exported via
EXPORT_SYMBOL?
Those functions aim for VM compaction so driver shouldn't use it. Only driver should be aware of are __SetPageMovable and __CleraPageMovable. I will export them.
Thanks for the review, Sergey!
Quoted 2 lines
-ss
Re: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
On (05/17/16 10:18), Minchan Kim wrote:
[..]
Quoted 19 lines
Quoted 13 lines
Quoted 13 lines
#ifdef
CONFIG_MIGRATIONinclude/linux/migrate.h +5
-0+extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);Quoted 5 lines
Quoted 2 lines
extern int
migrate_prep(void);
extern intmigrate_prep_local(void);given that some of Movable users can be built as modules, shouldn't at least some of those symbols be exported via
EXPORT_SYMBOL?
Quoted 4 lines
Those functions aim for VM compaction so driver shouldn't use it. Only driver should be aware of are
__SetPageMovableand__CleraPageMovable. I will export them.
and PageMovable(), probably?
zsmalloc():
VM_BUG_ON_PAGE(!PageMovable(page), page);
Quoted 1 line
Thanks for the review, Sergey!
no prob! sorry, I'm a bit slow and late here.
-ss
--
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>
Re: [PATCH v5 02/12] mm: migrate: support non-lru movable page migration
In reply to Minchan KimOn (05/17/16 10:18), Minchan Kim wrote:
[..]
Quoted 19 lines
Quoted 13 lines
Quoted 13 lines
#ifdef
CONFIG_MIGRATIONinclude/linux/migrate.h +5
-0+extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);Quoted 5 lines
Quoted 2 lines
extern int
migrate_prep(void);
extern intmigrate_prep_local(void);given that some of Movable users can be built as modules, shouldn't at least some of those symbols be exported via
EXPORT_SYMBOL?
Quoted 4 lines
Those functions aim for VM compaction so driver shouldn't use it. Only driver should be aware of are
__SetPageMovableand__CleraPageMovable. I will export them.
and PageMovable(), probably?
zsmalloc():
VM_BUG_ON_PAGE(!PageMovable(page), page);
Quoted 1 line
Thanks for the review, Sergey!
no prob! sorry, I'm a bit slow and late here.
-ss
Minchan Kim
maintainerPATCH v5 2/12 mm: migrate: support non-lru movable page migration
In reply to Minchan KimWe have allowed migration for only LRU pages until now and it was enough to make high-order pages. But recently, embedded system(e.g., webOS, android) uses lots of non-movable pages(e.g., zram, GPU memory) so we have seen several reports about troubles of small high-order allocation. For fixing the problem, there were several efforts (e,g,. enhance compaction algorithm, SLUB fallback to 0-order page, reserved memory, vmalloc and so on) but if there are lots of non-movable pages in system, their solutions are void in the long run.
So, this patch is to support facility to change non-movable pages with movable. For the feature, this patch introduces functions related to migration to address_space_operations as well as some page flags.
If a driver want to make own pages movable, it should define three functions which are function pointers of struct address_space_operations.
1. bool (*isolate_page) (struct page *page, isolate_mode_t mode);
What VM expects on isolate_page function of driver is to return *true* if driver isolates page successfully. On returing true, VM marks the page as PG_isolated so concurrent isolation in several CPUs skip the page for isolation. If a driver cannot isolate the page, it should return *false*.
Once page is successfully isolated, VM uses page.lru fields so driver shouldn't expect to preserve values in that fields.
2. int (*migratepage) (struct address_space *mapping,
struct page *newpage, struct page *oldpage, enum migrate_mode);
After isolation, VM calls migratepage of driver with isolated page. The function of migratepage is to move content of the old page to new page and set up fields of struct page newpage. Keep in mind that you should clear PG_movable of oldpage via __ClearPageMovable under page_lock if you migrated the oldpage successfully and returns MIGRATEPAGE_SUCCESS. If driver cannot migrate the page at the moment, driver can return -EAGAIN. On -EAGAIN, VM will retry page migration in a short time because VM interprets -EAGAIN as "temporal migration failure". On returning any error except -EAGAIN, VM will give up the page migration without retrying in this time.
Driver shouldn't touch page.lru field VM using in the functions.
3. void (*putback_page)(struct page *);
If migration fails on isolated page, VM should return the isolated page to the driver so VM calls driver's putback_page with migration failed page. In this function, driver should put the isolated page back to the own data structure.
4. non-lru movable page flags
There are two page flags for supporting non-lru movable page.
* PG_movable
Driver should use the below function to make page movable under page_lock.
void __SetPageMovable(struct page *page, struct address_space *mapping)
It needs argument of address_space for registering migration family functions which will be called by VM. Exactly speaking, PG_movable is not a real flag of struct page. Rather than, VM reuses page->mapping's lower bits to represent it.
#define PAGE_MAPPING_MOVABLE 0x2 page->mapping = page->mapping | PAGE_MAPPING_MOVABLE;
so driver shouldn't access page->mapping directly. Instead, driver should use page_mapping which mask off the low two bits of page->mapping so it can get right struct address_space.
For testing of non-lru movable page, VM supports __PageMovable function. However, it doesn't guarantee to identify non-lru movable page because page->mapping field is unified with other variables in struct page. As well, if driver releases the page after isolation by VM, page->mapping doesn't have stable value although it has PAGE_MAPPING_MOVABLE (Look at __ClearPageMovable). But __PageMovable is cheap to catch whether page is LRU or non-lru movable once the page has been isolated. Because LRU pages never can have PAGE_MAPPING_MOVABLE in page->mapping. It is also good for just peeking to test non-lru movable pages before more expensive checking with lock_page in pfn scanning to select victim.
For guaranteeing non-lru movable page, VM provides PageMovable function. Unlike __PageMovable, PageMovable functions validates page->mapping and mapping->a_ops->isolate_page under lock_page. The lock_page prevents sudden destroying of page->mapping.
Driver using __SetPageMovable should clear the flag via __ClearMovablePage under page_lock before the releasing the page.
* PG_isolated
To prevent concurrent isolation among several CPUs, VM marks isolated page as PG_isolated under lock_page. So if a CPU encounters PG_isolated non-lru movable page, it can skip it. Driver doesn't need to manipulate the flag because VM will set/clear it automatically. Keep in mind that if driver sees PG_isolated page, it means the page have been isolated by VM so it shouldn't touch page.lru field.PG_isolated is alias with PG_reclaim flag so driver shouldn't use the flag for own purpose.
--- Documentation/filesystems/Locking | 4 + Documentation/filesystems/vfs.txt | 11 ++ Documentation/vm/page_migration | 107 +++++++++++++++++- include/linux/fs.h | 2 + include/linux/ksm.h | 3 +- include/linux/migrate.h | 5 + include/linux/mm.h | 1 + include/linux/page-flags.h | 29 +++-- mm/compaction.c | 47 +++++--- mm/ksm.c | 4 +- mm/migrate.c | 222 ++++++++++++++++++++++++++++++++++---- mm/page_alloc.c | 2 +- mm/util.c | 6 +- 13 files changed, 391 insertions(+), 52 deletions(-)
Documentation/filesystems/Locking +4 -0
@@ -195,7 +195,9 @@ unlocks and drops the reference. int (*releasepage) (struct page *, int); void (*freepage)(struct page *); int (*direct_IO)(struct kiocb *, struct iov_iter *iter); + bool (*isolate_page) (struct page *, isolate_mode_t); int (*migratepage)(struct address_space *, struct page *, struct page *); + void (*putback_page) (struct page *); int (*launder_page)(struct page *); int (*is_partially_uptodate)(struct page *, unsigned long, unsigned long); int (*error_remove_page)(struct address_space *, struct page *);
@@ -219,7 +221,9 @@ invalidatepage: yes releasepage: yes freepage: yes direct_IO: +isolate_page: yes migratepage: yes (both) +putback_page: yes launder_page: yes is_partially_uptodate: yes error_remove_page: yes
Documentation/filesystems/vfs.txt +11 -0
@@ -592,9 +592,14 @@ struct address_space_operations { int (*releasepage) (struct page *, int); void (*freepage)(struct page *); ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter); + /* isolate a page for migration */ + bool (*isolate_page) (struct page *, isolate_mode_t); /* migrate the contents of a page to the specified target */ int (*migratepage) (struct page *, struct page *); + /* put migration-failed page back to right list */ + void (*putback_page) (struct page *); int (*launder_page) (struct page *); + int (*is_partially_uptodate) (struct page *, unsigned long, unsigned long); void (*is_dirty_writeback) (struct page *, bool *, bool *);
@@ -747,6 +752,10 @@ struct address_space_operations { and transfer data directly between the storage and the application's address space. + isolate_page: Called by the VM when isolating a movable non-lru page. + If page is successfully isolated, VM marks the page as PG_isolated + via __SetPageIsolated. + migrate_page: This is used to compact the physical memory usage. If the VM wants to relocate a page (maybe off a memory card that is signalling imminent failure) it will pass a new page
@@ -754,6 +763,8 @@ struct address_space_operations { transfer any private data across and update any references that it has to the page. + putback_page: Called by the VM when isolated page's migration fails. + launder_page: Called before freeing a page - it writes back the dirty page. To prevent redirtying the page, it is kept locked during the whole operation.
Documentation/vm/page_migration +106 -1
111 lines not on this page · raw message
include/linux/fs.h +2 -0
@@ -403,6 +403,8 @@ struct address_space_operations {*/ int (*migratepage) (struct address_space *,struct page *,struct page *,enum migrate_mode ); +bool (*isolate_page)(struct page *,isolate_mode_t ); +void (*putback_page)(struct page *);int (*launder_page) (struct page *);int (*is_partially_uptodate) (struct page *,unsigned long ,unsigned long );
include/linux/ksm.h +1 -2
@@ -43,8 +43,7 @@ static inline struct stable_node *page_stable_node(struct page *page)static inline void set_page_stable_node (struct page *page,struct stable_node *stable_node) { - page->mapping = (void *)stable_node + - (PAGE_MAPPING_ANON |PAGE_MAPPING_KSM ); + page->mapping = (void *)((unsigned long )stable_node |PAGE_MAPPING_KSM ); }/*
include/linux/migrate.h +5 -0
@@ -32,11 +32,16 @@ extern char *migrate_reason_names[MR_TYPES];#ifdef CONFIG_MIGRATION +extern int PageMovable (struct page *page); +extern void __SetPageMovable (struct page *page,struct address_space *mapping); +extern void __ClearPageMovable (struct page *page);extern void putback_movable_pages (struct list_head *l);extern int migrate_page (struct address_space *,struct page *,struct page *,enum migrate_mode );extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern bool isolate_movable_page (struct page *page,isolate_mode_t mode); +extern void putback_movable_page (struct page *page);extern int migrate_prep (void );extern int migrate_prep_local (void );
include/linux/mm.h +1 -0
@@ -1021,6 +1021,7 @@ static inline pgoff_t page_file_index(struct page *page) }bool page_mapped (struct page *page); +struct address_space *page_mapping (struct page *page);/* * Return true only if the page has been allocated with
include/linux/page-flags.h +21 -8
@@ -129,6 +129,9 @@ enum pageflags {/* Compound pages. Stored in first tail page's flags */ PG_double_map = PG_private_2, + +/* non-lru isolated movable page */ + PG_isolated = PG_reclaim, };#ifndef __GENERATING_BOUNDS_H
@@ -361,25 +364,33 @@ PAGEFLAG(Idle, idle, PF_ANY)* and then page->mapping points, not to an anon_vma, but to a private * structure which KSM associates with that merged page. See ksm.h. * -* PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is currently never used. +* PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is used for non-lru movable +* page and then page->mapping points a struct address_space. * * Please note that, confusingly, "page_mapping" refers to the inode * address_space which maps the page from disk; whereas "page_mapped" * refers to user virtual address space into which the page is mapped. */ -#define PAGE_MAPPING_ANON 1 -#define PAGE_MAPPING_KSM 2 -#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM) +#define PAGE_MAPPING_ANON 0x1 +#define PAGE_MAPPING_MOVABLE 0x2 +#define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) +#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) -static __always_inline int PageAnonHead(struct page *page) +static __always_inline int PageMappingFlag(struct page *page) { -return ((unsigned long )page->mapping &PAGE_MAPPING_ANON ) !=0 ; +return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) !=0 ; } static __always_inline int PageAnon(struct page *page) { page =compound_head (page); -return PageAnonHead (page); +return ((unsigned long )page->mapping &PAGE_MAPPING_ANON ) !=0 ; +} + +static __always_inline int __PageMovable(struct page *page) +{ +return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) == +PAGE_MAPPING_MOVABLE ; }#ifdef CONFIG_KSM
@@ -393,7 +404,7 @@ static __always_inline int PageKsm(struct page *page) { page =compound_head (page);return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) == - (PAGE_MAPPING_ANON |PAGE_MAPPING_KSM ); +PAGE_MAPPING_KSM ; }#else TESTPAGEFLAG_FALSE (Ksm)
@@ -641,6 +652,8 @@ static inline void __ClearPageBalloon(struct page *page)atomic_set (&page->_mapcount,-1 ); } +__PAGEFLAG (Isolated, isolated,PF_ANY ); +/* * If network-based swap is enabled, sl*b must keep track of whether pages * were allocated from pfmemalloc reserves.
mm/compaction.c +31 -16
60 lines not on this page · raw message
mm/ksm.c +2 -2
@@ -532,8 +532,8 @@ static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it)void *expected_mapping;unsigned long kpfn; - expected_mapping = (void *)stable_node + - (PAGE_MAPPING_ANON |PAGE_MAPPING_KSM ); + expected_mapping = (void *)((unsigned long )stable_node | +PAGE_MAPPING_KSM ); again: kpfn =READ_ONCE (stable_node->kpfn); page =pfn_to_page (kpfn);
mm/migrate.c +202 -20
297 lines not on this page · raw message
mm/page_alloc.c +1 -1
@@ -1015,7 +1015,7 @@ static __always_inline bool free_pages_prepare(struct page *page, (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP ; } } -if (PageAnonHead (page)) +if (PageMappingFlag (page)) page->mapping =NULL ;if (check_free) bad +=free_pages_check (page);
mm/util.c +4 -2
@@ -399,10 +399,12 @@ struct address_space *page_mapping(struct page *page) } mapping = page->mapping; -if ((unsigned long )mapping &PAGE_MAPPING_FLAGS ) +if ((unsigned long )mapping &PAGE_MAPPING_ANON )return NULL ; -return mapping; + +return (void *)((unsigned long )mapping & ~PAGE_MAPPING_FLAGS ); } +EXPORT_SYMBOL (page_mapping);/* Slow path of page_mapcount() for compound pages */ int __page_mapcount (struct page *page)
Signature · 1 line
1.9.1
Minchan Kim
maintainerPATCH v5 3/12 mm: balloon: use general non-lru movable page feature
In reply to Minchan KimNow, 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.
--- drivers/virtio/virtio_balloon.c | 52 +++++++++++++++++++-- include/linux/balloon_compaction.h | 51 ++++++--------------- 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, 83 insertions(+), 143 deletions(-)
drivers/virtio/virtio_balloon.c +47 -5
@@ -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_DEFAULT_PAGES;module_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;
@@ -486,6 +491,24 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info, return MIGRATEPAGE_SUCCESS; } + +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)
@@ -515,9 +538,6 @@ static int virtballoon_probe(struct virtio_device *vdev) 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)
@@ -527,13 +547,33 @@ static int virtballoon_probe(struct virtio_device *vdev) 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);
@@ -567,6 +607,8 @@ static void virtballoon_remove(struct virtio_device *vdev)cancel_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 +15 -36
90 lines not on this page · raw message
include/uapi/linux/magic.h +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 +17 -77
134 lines not on this page · raw message
mm/compaction.c +0 -7
@@ -757,13 +757,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,*/ is_lru =PageLRU (page);if (!is_lru) { -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 +2 -17
@@ -199,14 +199,12 @@ 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))) { -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))
@@ -1016,18 +1014,6 @@ static int __unmap_and_move(struct page *page, struct page *newpage,if (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;
@@ -1082,8 +1068,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,* 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 +1 -1
@@ -1254,7 +1254,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)) { + !__PageMovable (page)) {ClearPageActive (page);list_move (&page->lru, &clean_pages); }
Signature · 1 line
1.9.1
kbuild test robot
build botRe: [PATCH v5 03/12] mm: balloon: use general non-lru movable page feature
url: https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-use-put_page-to-free-page-instead-of-putback_lru_page/20160509-102355 config: i386-randconfig-s0-05161922 (attached as .config) compiler…
Hi,
[auto build test ERROR on next-20160506]
[cannot apply to v4.6-rc7 v4.6-rc6 v4.6-rc5 v4.6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-use-put_page-to-free-page-instead-of-putback_lru_page/20160509-102355
config: i386-randconfig-s0-05161922 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
>> ERROR: "__ClearPageMovable" [drivers/virtio/virtio_balloon.ko] undefined! >> ERROR: "__SetPageMovable" [drivers/virtio/virtio_balloon.ko] undefined!
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Minchan Kim
maintainerPATCH v5 4/12 zsmalloc: keep max_object in size_class
In reply to Minchan KimEvery zspage in a size_class has same number of max objects so we could move it to a size_class.
--- mm/zsmalloc.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
mm/zsmalloc.c +15 -17
@@ -32,8 +32,6 @@* page->freelist: points to the first free object in zspage. * Free objects are linked together using in-place * metadata. -* page->objects: maximum number of objects we can store in this -* zspage (class->zspage_order * PAGE_SIZE / class->size) * page->lru: links together first pages of various zspages. * Basically forming list of zspages in a fullness group. * page->mapping: class index and fullness group of the zspage
@@ -211,6 +209,7 @@ struct size_class {* of ZS_ALIGN. */ int size; +int objs_per_zspage;unsigned int index;struct zs_size_stat stats;
@@ -627,21 +626,22 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)* the pool (not yet implemented). This function returns fullness * status of the given page. */ -static enum fullness_group get_fullness_group (struct page *first_page) +static enum fullness_group get_fullness_group (struct size_class *class, +struct page *first_page) { -int inuse, max_objects; +int inuse, objs_per_zspage;enum fullness_group fg;VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); inuse = first_page->inuse; - max_objects = first_page->objects; + objs_per_zspage = class->objs_per_zspage;if (inuse ==0 ) fg =ZS_EMPTY ; -else if (inuse == max_objects) +else if (inuse == objs_per_zspage) fg =ZS_FULL ; -else if (inuse <=3 * max_objects / fullness_threshold_frac) +else if (inuse <=3 * objs_per_zspage / fullness_threshold_frac) fg =ZS_ALMOST_EMPTY ;else fg =ZS_ALMOST_FULL ;
@@ -728,7 +728,7 @@ static enum fullness_group fix_fullness_group(struct size_class *class,enum fullness_group currfg, newfg;get_zspage_mapping (first_page, &class_idx, &currfg); - newfg =get_fullness_group (first_page); + newfg =get_fullness_group (class, first_page);if (newfg == currfg) goto out;
@@ -1011,9 +1011,6 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)init_zspage (class, first_page); first_page->freelist =location_to_obj (first_page,0 ); -/* Maximum number of objects we can store in this zspage */ - first_page->objects = class->pages_per_zspage *PAGE_SIZE / class->size; - error =0 ;/* Success */ cleanup:
@@ -1241,11 +1238,11 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)return true; } -static bool zspage_full (struct page *first_page) +static bool zspage_full (struct size_class *class,struct page *first_page) {VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); -return first_page->inuse == first_page->objects; +return first_page->inuse == class->objs_per_zspage; }unsigned long zs_get_total_pages (struct zs_pool *pool)
@@ -1631,7 +1628,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class, }/* Stop if there is no more space */ -if (zspage_full (d_page)) { +if (zspage_full (class, d_page)) {unpin_tag (handle); ret = -ENOMEM ;break ;
@@ -1690,7 +1687,7 @@ static enum fullness_group putback_zspage(struct zs_pool *pool, {enum fullness_group fullness; - fullness =get_fullness_group (first_page); + fullness =get_fullness_group (class, first_page);insert_zspage (class, fullness, first_page);set_zspage_mapping (first_page, class->index, fullness);
@@ -1939,8 +1936,9 @@ struct zs_pool *zs_create_pool(const char *name) class->size = size; class->index = i; class->pages_per_zspage = pages_per_zspage; -if (pages_per_zspage ==1 && -get_maxobj_per_zspage (size, pages_per_zspage) ==1 ) + class->objs_per_zspage = class->pages_per_zspage * +PAGE_SIZE / class->size; +if (pages_per_zspage ==1 && class->objs_per_zspage ==1 ) class->huge = true;spin_lock_init (&class->lock); pool->size_class[i] = class;
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>
Minchan Kim
maintainerPATCH v5 5/12 zsmalloc: use bit_spin_lock
In reply to Minchan KimUse kernel standard bit spin-lock instead of custom mess. Even, it has a bug which doesn't disable preemption. The reason we don't have any problem is that we have used it during preemption disable section by class->lock spinlock. So no need to go to stable.
--- mm/zsmalloc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
mm/zsmalloc.c +3 -7
@@ -867,21 +867,17 @@ static unsigned long obj_idx_to_offset(struct page *page,static inline int trypin_tag (unsigned long handle) { -unsigned long *ptr = (unsigned long *)handle; - -return !test_and_set_bit_lock (HANDLE_PIN_BIT , ptr); +return bit_spin_trylock (HANDLE_PIN_BIT , (unsigned long *)handle); }static void pin_tag (unsigned long handle) { -while (!trypin_tag (handle)); +bit_spin_lock (HANDLE_PIN_BIT , (unsigned long *)handle); }static void unpin_tag (unsigned long handle) { -unsigned long *ptr = (unsigned long *)handle; - -clear_bit_unlock (HANDLE_PIN_BIT , ptr); +bit_spin_unlock (HANDLE_PIN_BIT , (unsigned long *)handle); }static void reset_page (struct page *page)
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>
Re: [PATCH v5 05/12] zsmalloc: use bit_spin_lock
Quoted 8 lines · Minchan Kim
Use kernel standard bit spin-lock instead of custom mess. Even, it has a bug which doesn't disable preemption. The reason we don't have any problem is that we have used it during preemption disable section by
class->lockspinlock. So no need to go to stable.Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>
good change.
-ss
--
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>
Minchan Kim
maintainerPATCH v5 6/12 zsmalloc: use accessor
In reply to Minchan KimUpcoming patch will change how to encode zspage meta so for easy review, this patch wraps code to access metadata as accessor.
--- mm/zsmalloc.c | 82 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 22 deletions(-)
mm/zsmalloc.c +60 -22
@@ -266,10 +266,14 @@ struct zs_pool {* A zspage's class index and fullness group * are encoded in its (first)page->mapping */ -#define CLASS_IDX_BITS 28#define FULLNESS_BITS 4 -#define CLASS_IDX_MASK ((1 << CLASS_IDX_BITS) - 1) -#define FULLNESS_MASK ((1 << FULLNESS_BITS) - 1) +#define CLASS_BITS 28 + +#define FULLNESS_SHIFT 0 +#define CLASS_SHIFT (FULLNESS_SHIFT + FULLNESS_BITS) + +#define FULLNESS_MASK ((1UL << FULLNESS_BITS) - 1) +#define CLASS_MASK ((1UL << CLASS_BITS) - 1)struct mapping_area {#ifdef CONFIG_PGTABLE_MAPPING
@@ -416,6 +420,41 @@ static int is_last_page(struct page *page)return PagePrivate2 (page); } +static inline int get_zspage_inuse (struct page *first_page) +{ +return first_page->inuse; +} + +static inline void set_zspage_inuse (struct page *first_page,int val) +{ + first_page->inuse = val; +} + +static inline void mod_zspage_inuse (struct page *first_page,int val) +{ + first_page->inuse += val; +} + +static inline int get_first_obj_offset (struct page *page) +{ +return page->index; +} + +static inline void set_first_obj_offset (struct page *page,int offset) +{ + page->index = offset; +} + +static inline unsigned long get_freeobj (struct page *first_page) +{ +return (unsigned long )first_page->freelist; +} + +static inline void set_freeobj (struct page *first_page,unsigned long obj) +{ + first_page->freelist = (void *)obj; +} +static void get_zspage_mapping (struct page *first_page,unsigned int *class_idx,enum fullness_group *fullness)
@@ -424,8 +463,8 @@ static void get_zspage_mapping(struct page *first_page,VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); m = (unsigned long )first_page->mapping; - *fullness = m &FULLNESS_MASK ; - *class_idx = (m >>FULLNESS_BITS ) &CLASS_IDX_MASK ; + *fullness = (m >>FULLNESS_SHIFT ) &FULLNESS_MASK ; + *class_idx = (m >>CLASS_SHIFT ) &CLASS_MASK ; } static void set_zspage_mapping(struct page *first_page,
@@ -435,8 +474,7 @@ static void set_zspage_mapping(struct page *first_page,unsigned long m;VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - m = ((class_idx &CLASS_IDX_MASK ) <<FULLNESS_BITS ) | - (fullness &FULLNESS_MASK ); + m = (class_idx <<CLASS_SHIFT ) | (fullness <<FULLNESS_SHIFT ); first_page->mapping = (struct address_space *)m; }
@@ -634,7 +672,7 @@ static enum fullness_group get_fullness_group(struct size_class *class,VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - inuse = first_page->inuse; + inuse =get_zspage_inuse (first_page); objs_per_zspage = class->objs_per_zspage;if (inuse ==0 )
@@ -680,7 +718,7 @@ static void insert_zspage(struct size_class *class,* empty/full. Put pages with higher ->inuse first. */ list_add_tail (&first_page->lru, &(*head)->lru); -if (first_page->inuse >= (*head)->inuse) +if (get_zspage_inuse (first_page) >=get_zspage_inuse (*head)) *head = first_page; }
@@ -860,7 +898,7 @@ static unsigned long obj_idx_to_offset(struct page *page,unsigned long off =0 ;if (!is_first_page (page)) - off = page->index; + off =get_first_obj_offset (page);return off + obj_idx * class_size; }
@@ -895,7 +933,7 @@ static void free_zspage(struct page *first_page)struct page *nextp, *tmp, *head_extra;VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); -VM_BUG_ON_PAGE (first_page->inuse, first_page); +VM_BUG_ON_PAGE (get_zspage_inuse (first_page), first_page); head_extra = (struct page *)page_private (first_page);
@@ -936,7 +974,7 @@ static void init_zspage(struct size_class *class, struct page *first_page)* head of corresponding zspage's freelist. */ if (page != first_page) - page->index = off; +set_first_obj_offset (page, off); vaddr =kmap_atomic (page); link = (struct link_free *)vaddr + off /sizeof (*link);
@@ -991,7 +1029,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)SetPagePrivate (page);set_page_private (page,0 ); first_page = page; - first_page->inuse =0 ; +set_zspage_inuse (first_page,0 ); }if (i ==1 )set_page_private (first_page, (unsigned long )page);
@@ -1006,7 +1044,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)init_zspage (class, first_page); - first_page->freelist =location_to_obj (first_page,0 ); +set_freeobj (first_page, (unsigned long )location_to_obj (first_page,0 )); error =0 ;/* Success */ cleanup:
@@ -1238,7 +1276,7 @@ static bool zspage_full(struct size_class *class, struct page *first_page) {VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); -return first_page->inuse == class->objs_per_zspage; +return get_zspage_inuse (first_page) == class->objs_per_zspage; }unsigned long zs_get_total_pages (struct zs_pool *pool)
@@ -1357,13 +1395,13 @@ static unsigned long obj_malloc(struct size_class *class,void *vaddr; handle |=OBJ_ALLOCATED_TAG ; - obj = (unsigned long )first_page->freelist; + obj =get_freeobj (first_page);obj_to_location (obj, &m_page, &m_objidx); m_offset =obj_idx_to_offset (m_page, m_objidx, class->size); vaddr =kmap_atomic (m_page); link = (struct link_free *)vaddr + m_offset /sizeof (*link); - first_page->freelist = link->next; +set_freeobj (first_page, (unsigned long )link->next);if (!class->huge)/* record handle in the header of allocated chunk */ link->handle = handle;
@@ -1371,7 +1409,7 @@ static unsigned long obj_malloc(struct size_class *class,/* record handle in first_page->private */ set_page_private (first_page, handle);kunmap_atomic (vaddr); - first_page->inuse++; +mod_zspage_inuse (first_page,1 );zs_stat_inc (class,OBJ_USED ,1 );return obj;
@@ -1451,12 +1489,12 @@ static void obj_free(struct size_class *class, unsigned long obj)/* Insert this object in containing zspage's freelist */ link = (struct link_free *)(vaddr + f_offset); - link->next = first_page->freelist; + link->next = (void *)get_freeobj (first_page);if (class->huge)set_page_private (first_page,0 );kunmap_atomic (vaddr); - first_page->freelist = (void *)obj; - first_page->inuse--; +set_freeobj (first_page, obj); +mod_zspage_inuse (first_page,-1 );zs_stat_dec (class,OBJ_USED ,1 ); }
@@ -1572,7 +1610,7 @@ static unsigned long find_alloced_obj(struct size_class *class,void *addr =kmap_atomic (page);if (!is_first_page (page)) - offset = page->index; + offset =get_first_obj_offset (page); offset += class->size * index;while (offset <PAGE_SIZE ) {
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>
Re: [PATCH v5 06/12] zsmalloc: use accessor
Quoted 5 lines · Minchan Kim
Upcoming patch will change how to encode zspage meta so for easy review, this patch wraps code to access metadata as accessor.
Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>
-ss
--
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>
Minchan Kim
maintainerPATCH v5 7/12 zsmalloc: factor page chain functionality out
In reply to Minchan KimFor page migration, we need to create page chain of zspage dynamically so this patch factors it out from alloc_zspage.
--- mm/zsmalloc.c | 59 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 24 deletions(-)
mm/zsmalloc.c +35 -24
@@ -959,7 +959,8 @@ static void init_zspage(struct size_class *class, struct page *first_page)unsigned long off =0 ;struct page *page = first_page; -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); + first_page->freelist =NULL ; +set_zspage_inuse (first_page,0 );while (page) {struct page *next_page;
@@ -995,15 +996,16 @@ static void init_zspage(struct size_class *class, struct page *first_page) page = next_page; off %=PAGE_SIZE ; } + +set_freeobj (first_page, (unsigned long )location_to_obj (first_page,0 )); } -/* -* Allocate a zspage for the given size class -*/ -static struct page *alloc_zspage (struct size_class *class,gfp_t flags) +static void create_page_chain (struct page *pages[],int nr_pages) { -int i, error; -struct page *first_page =NULL , *uninitialized_var (prev_page ); +int i; +struct page *page; +struct page *prev_page =NULL ; +struct page *first_page =NULL ;/* * Allocate individual pages and link them together as:
@@ -1016,20 +1018,14 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)* (i.e. no other sub-page has this flag set) and PG_private_2 to * identify the last page. */ - error = -ENOMEM ; -for (i =0 ; i < class->pages_per_zspage; i++) { -struct page *page; - - page =alloc_page (flags); -if (!page) - goto cleanup; +for (i =0 ; i < nr_pages; i++) { + page = pages[i];INIT_LIST_HEAD (&page->lru); -if (i ==0 ) {/* first page */ +if (i ==0 ) {SetPagePrivate (page);set_page_private (page,0 ); first_page = page; -set_zspage_inuse (first_page,0 ); }if (i ==1 )set_page_private (first_page, (unsigned long )page);
@@ -1037,22 +1033,37 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)set_page_private (page, (unsigned long )first_page);if (i >=2 )list_add (&page->lru, &prev_page->lru); -if (i == class->pages_per_zspage -1 )/* last page */ +if (i == nr_pages -1 )SetPagePrivate2 (page); prev_page = page; } +} -init_zspage (class, first_page); +/* +* Allocate a zspage for the given size class +*/ +static struct page *alloc_zspage (struct size_class *class,gfp_t flags) +{ +int i; +struct page *first_page =NULL ; +struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE ]; -set_freeobj (first_page, (unsigned long )location_to_obj (first_page,0 )); - error =0 ;/* Success */ +for (i =0 ; i < class->pages_per_zspage; i++) { +struct page *page; -cleanup: -if (unlikely (error) && first_page) { -free_zspage (first_page); - first_page =NULL ; + page =alloc_page (flags); +if (!page) { +while (--i >=0 ) +__free_page (pages[i]); +return NULL ; + } + pages[i] = page; } +create_page_chain (pages, class->pages_per_zspage); + first_page = pages[0 ]; +init_zspage (class, first_page); +return first_page; }
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>
Re: [PATCH v5 07/12] zsmalloc: factor page chain functionality out
Quoted 5 lines · Minchan Kim
For page migration, we need to create page chain of zspage dynamically so this patch factors it out from
alloc_zspage.Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>
[..]
mm/zsmalloc.c static struct page *alloc_zspage(struct size_class *class, gfp_t flags) · line 1057
Quoted 4 lines
mm/zsmalloc.c +4
-0+ page =alloc_page (flags); +if (!page) { +while (--i >=0 ) +__free_page (pages[i]);
put_page() ?
a minor nit, put_page() here probably will be in alignment with __free_zspage(), which does put_page().
-ss
mm/zsmalloc.c static struct page *alloc_zspage(struct size_class *class, gfp_t flags) · line 1068
Quoted 11 lines
mm/zsmalloc.c +7
-0+return NULL ; + } + pages[i] = page; } +create_page_chain (pages, class->pages_per_zspage); + first_page = pages[0 ]; +init_zspage (class, first_page); +return first_page; }
--
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>
Minchan Kim
maintainerRe: [PATCH v5 07/12] zsmalloc: factor page chain functionality out
Quoted 8 lines · Sergey Senozhatsky
Quoted 5 lines · Minchan Kim
For page migration, we need to create page chain of zspage dynamically so this patch factors it out from
alloc_zspage.Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>Reviewed-by Sergey Senozhatsky <[email protected]>
Thanks!
Quoted 11 lines
[..]
mm/zsmalloc.c static struct page *alloc_zspage(struct size_class *class, gfp_t flags) · line 1057
Quoted 4 lines
mm/zsmalloc.c +4
-0+ page =alloc_page (flags); +if (!page) { +while (--i >=0 ) +__free_page (pages[i]);put_page() ?a minor nit,
put_page()here probably will be in alignment with__free_zspage(), which doesput_page().
Normally, we use put_page in case that someone can grab a referece of the page so we cannot free the page. Otherwise, alloc_page and __free_page is more straight to me code readability POV.
Quoted 8 lines
-ssQuoted 5 lines
mm/zsmalloc.c +3
-0+return NULL ; + } + pages[i] = page; }
Quoted 6 lines
mm/zsmalloc.c static struct page *alloc_zspage(struct size_class *class, gfp_t flags) · line 1068
Quoted 6 lines
mm/zsmalloc.c +4
-0+create_page_chain (pages, class->pages_per_zspage); + first_page = pages[0 ]; +init_zspage (class, first_page); +return first_page; }
--
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>
Minchan Kim
maintainerPATCH v5 8/12 zsmalloc: introduce zspage structure
In reply to Minchan KimWe have squeezed meta data of zspage into first page's descriptor. So, to get meta data from subpage, we should get first page first of all. But it makes trouble to implment page migration feature of zsmalloc because any place where to get first page from subpage can be raced with first page migration. IOW, first page it got could be stale. For preventing it, I have tried several approahces but it made code complicated so finally, I concluded to separate metadata from first page. Of course, it consumes more memory. IOW, 16bytes per zspage on 32bit at the moment. It means we lost 1% at *worst case*(40B/4096B) which is not bad I think at the cost of maintenance.
--- mm/zsmalloc.c | 530 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 241 insertions(+), 289 deletions(-)
mm/zsmalloc.c +241 -289
@@ -16,26 +16,11 @@* struct page(s) to form a zspage. * * Usage of struct page fields: -* page->private: points to the first component (0-order) page -* page->index (union with page->freelist): offset of the first object -* starting in this page. For the first page, this is -* always 0, so we use this field (aka freelist) to point -* to the first free object in zspage. -* page->lru: links together all component pages (except the first page) -* of a zspage -* -* For _first_ page only: -* -* page->private: refers to the component page after the first page -* If the page is first_page for huge object, it stores handle. -* Look at size_class->huge. -* page->freelist: points to the first free object in zspage. -* Free objects are linked together using in-place -* metadata. -* page->lru: links together first pages of various zspages. -* Basically forming list of zspages in a fullness group. -* page->mapping: class index and fullness group of the zspage -* page->inuse: the number of objects that are used in this zspage +* page->private: points to zspage +* page->index: offset of the first object starting in this page. +* For the first page, this is always 0, so we use this field +* to store handle for huge object. +* page->next: links together all component pages of a zspage * * Usage of struct page flags: * PG_private: identifies the first component page
@@ -145,7 +130,7 @@* ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN * (reason above) */ -#define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8) +#define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> CLASS_BITS)/* * We do not maintain any list for completely empty or full pages
@@ -153,8 +138,6 @@enum fullness_group {ZS_ALMOST_FULL ,ZS_ALMOST_EMPTY , - _ZS_NR_FULLNESS_GROUPS, -ZS_EMPTY ,ZS_FULL };
@@ -203,7 +186,7 @@ static const int fullness_threshold_frac = 4;struct size_class {spinlock_t lock; -struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS]; +struct list_head fullness_list[2 ];/* * Size of objects stored in this class. Must be multiple * of ZS_ALIGN.
@@ -222,7 +205,7 @@ struct size_class {/* * Placed within free objects to form a singly linked list. -* For every zspage, first_page->freelist gives head of this list. +* For every zspage, zspage->freeobj gives head of this list. * * This must be power of 2 and less than or equal to ZS_ALIGN */
@@ -245,6 +228,7 @@ struct zs_pool {struct size_class **size_class;struct kmem_cache *handle_cachep; +struct kmem_cache *zspage_cachep;atomic_long_t pages_allocated;
@@ -266,14 +250,19 @@ struct zs_pool {* A zspage's class index and fullness group * are encoded in its (first)page->mapping */ -#define FULLNESS_BITS 4 -#define CLASS_BITS 28 +#define FULLNESS_BITS 2 +#define CLASS_BITS 8 -#define FULLNESS_SHIFT 0 -#define CLASS_SHIFT (FULLNESS_SHIFT + FULLNESS_BITS) - -#define FULLNESS_MASK ((1UL << FULLNESS_BITS) - 1) -#define CLASS_MASK ((1UL << CLASS_BITS) - 1) +struct zspage { +struct { +unsigned int fullness:FULLNESS_BITS ; +unsigned int class:CLASS_BITS ; + }; +unsigned int inuse; +void *freeobj; +struct page *first_page; +struct list_head list;/* fullness list */ +};struct mapping_area {#ifdef CONFIG_PGTABLE_MAPPING
@@ -285,29 +274,50 @@ struct mapping_area {enum zs_mapmode vm_mm;/* mapping mode */ }; -static int create_handle_cache (struct zs_pool *pool) +static int create_cache (struct zs_pool *pool) { pool->handle_cachep =kmem_cache_create ("zs_handle" ,ZS_HANDLE_SIZE ,0 ,0 ,NULL ); -return pool->handle_cachep ?0 :1 ; +if (!pool->handle_cachep) +return 1 ; + + pool->zspage_cachep =kmem_cache_create ("zspage" ,sizeof (struct zspage ), +0 ,0 ,NULL ); +if (!pool->zspage_cachep) { +kmem_cache_destroy (pool->handle_cachep); +return 1 ; + } + +return 0 ; } -static void destroy_handle_cache (struct zs_pool *pool) +static void destroy_cache (struct zs_pool *pool) {kmem_cache_destroy (pool->handle_cachep); +kmem_cache_destroy (pool->zspage_cachep); } -static unsigned long alloc_handle (struct zs_pool *pool,gfp_t gfp) +static unsigned long cache_alloc_handle (struct zs_pool *pool,gfp_t gfp) {return (unsigned long )kmem_cache_alloc (pool->handle_cachep, gfp & ~__GFP_HIGHMEM); } -static void free_handle (struct zs_pool *pool,unsigned long handle) +static void cache_free_handle (struct zs_pool *pool,unsigned long handle) {kmem_cache_free (pool->handle_cachep, (void *)handle); } +static struct zspage *cache_alloc_zspage (struct zs_pool *pool,gfp_t flags) +{ +return kmem_cache_alloc (pool->zspage_cachep, flags & ~__GFP_HIGHMEM); +}; + +static void cache_free_zspage (struct zs_pool *pool,struct zspage *zspage) +{ +kmem_cache_free (pool->zspage_cachep, zspage); +} +static void record_obj (unsigned long handle,unsigned long obj) {/*
@@ -415,67 +425,61 @@ static int is_first_page(struct page *page)return PagePrivate (page); } -static int is_last_page (struct page *page) -{ -return PagePrivate2 (page); -} - -static inline int get_zspage_inuse (struct page *first_page) +static inline int get_zspage_inuse (struct zspage *zspage) { -return first_page->inuse; +return zspage->inuse; } -static inline void set_zspage_inuse (struct page *first_page,int val) +static inline void set_zspage_inuse (struct zspage *zspage,int val) { - first_page->inuse = val; + zspage->inuse = val; } -static inline void mod_zspage_inuse (struct page *first_page,int val) +static inline void mod_zspage_inuse (struct zspage *zspage,int val) { - first_page->inuse += val; + zspage->inuse += val; }static inline int get_first_obj_offset (struct page *page) { +if (is_first_page (page)) +return 0 ; +return page->index; }static inline void set_first_obj_offset (struct page *page,int offset) { +if (is_first_page (page)) +return ; + page->index = offset; } -static inline unsigned long get_freeobj (struct page *first_page) +static inline unsigned long get_freeobj (struct zspage *zspage) { -return (unsigned long )first_page->freelist; +return (unsigned long )zspage->freeobj; } -static inline void set_freeobj (struct page *first_page,unsigned long obj) +static inline void set_freeobj (struct zspage *zspage,unsigned long obj) { - first_page->freelist = (void *)obj; + zspage->freeobj = (void *)obj; } -static void get_zspage_mapping (struct page *first_page, +static void get_zspage_mapping (struct zspage *zspage,unsigned int *class_idx,enum fullness_group *fullness) { -unsigned long m; -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - - m = (unsigned long )first_page->mapping; - *fullness = (m >>FULLNESS_SHIFT ) &FULLNESS_MASK ; - *class_idx = (m >>CLASS_SHIFT ) &CLASS_MASK ; + *fullness = zspage->fullness; + *class_idx = zspage->class; } -static void set_zspage_mapping (struct page *first_page, +static void set_zspage_mapping (struct zspage *zspage,unsigned int class_idx,enum fullness_group fullness) { -unsigned long m; -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - - m = (class_idx <<CLASS_SHIFT ) | (fullness <<FULLNESS_SHIFT ); - first_page->mapping = (struct address_space *)m; + zspage->class = class_idx; + zspage->fullness = fullness; }/*
@@ -665,14 +669,12 @@ static inline void zs_pool_stat_destroy(struct zs_pool *pool)* status of the given page. */ static enum fullness_group get_fullness_group (struct size_class *class, -struct page *first_page) +struct zspage *zspage) {int inuse, objs_per_zspage;enum fullness_group fg; -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - - inuse =get_zspage_inuse (first_page); + inuse =get_zspage_inuse (zspage); objs_per_zspage = class->objs_per_zspage;if (inuse ==0 )
@@ -694,32 +696,31 @@ static enum fullness_group get_fullness_group(struct size_class *class,* identified by <class, fullness_group>. */ static void insert_zspage (struct size_class *class, -enum fullness_group fullness, -struct page *first_page) +struct zspage *zspage, +enum fullness_group fullness) { -struct page **head; - -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); +struct zspage *head; -if (fullness >= _ZS_NR_FULLNESS_GROUPS) +if (fullness >=ZS_EMPTY )return ; + head =list_first_entry_or_null (&class->fullness_list[fullness], + struct zspage, list); +zs_stat_inc (class, fullness ==ZS_ALMOST_EMPTY ?CLASS_ALMOST_EMPTY :CLASS_ALMOST_FULL ,1 ); - head = &class->fullness_list[fullness]; -if (!*head) { - *head = first_page; -return ; - } -/* -* We want to see more ZS_FULL pages and less almost -* empty/full. Put pages with higher ->inuse first. +* We want to see more ZS_FULL pages and less almost empty/full. +* Put pages with higher ->inuse first. */ -list_add_tail (&first_page->lru, &(*head)->lru); -if (get_zspage_inuse (first_page) >=get_zspage_inuse (*head)) - *head = first_page; +if (head) { +if (get_zspage_inuse (zspage) <get_zspage_inuse (head)) { +list_add (&zspage->list, &head->list); +return ; + } + } +list_add (&zspage->list, &class->fullness_list[fullness]); }/*
@@ -727,25 +728,15 @@ static void insert_zspage(struct size_class *class,* by <class, fullness_group>. */ static void remove_zspage (struct size_class *class, -enum fullness_group fullness, -struct page *first_page) +struct zspage *zspage, +enum fullness_group fullness) { -struct page **head; - -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - -if (fullness >= _ZS_NR_FULLNESS_GROUPS) +if (fullness >=ZS_EMPTY )return ; - head = &class->fullness_list[fullness]; -VM_BUG_ON_PAGE (!*head, first_page); -if (list_empty (&(*head)->lru)) - *head =NULL ; -else if (*head == first_page) - *head = (struct page *)list_entry ((*head)->lru.next, - struct page, lru); +VM_BUG_ON (list_empty (&class->fullness_list[fullness])); -list_del_init (&first_page->lru); +list_del_init (&zspage->list);zs_stat_dec (class, fullness ==ZS_ALMOST_EMPTY ?CLASS_ALMOST_EMPTY :CLASS_ALMOST_FULL ,1 ); }
@@ -760,19 +751,19 @@ static void remove_zspage(struct size_class *class,* fullness group. */ static enum fullness_group fix_fullness_group (struct size_class *class, -struct page *first_page) +struct zspage *zspage) {int class_idx;enum fullness_group currfg, newfg; -get_zspage_mapping (first_page, &class_idx, &currfg); - newfg =get_fullness_group (class, first_page); +get_zspage_mapping (zspage, &class_idx, &currfg); + newfg =get_fullness_group (class, zspage);if (newfg == currfg) goto out; -remove_zspage (class, currfg, first_page); -insert_zspage (class, newfg, first_page); -set_zspage_mapping (first_page, class_idx, newfg); +remove_zspage (class, zspage, currfg); +insert_zspage (class, zspage, newfg); +set_zspage_mapping (zspage, class_idx, newfg); out:return newfg;
@@ -817,31 +808,15 @@ static int get_pages_per_zspage(int class_size)return max_usedpc_order; } -/* -* A single 'zspage' is composed of many system pages which are -* linked together using fields in struct page. This function finds -* the first/head page, given any component page of a zspage. -*/ -static struct page *get_first_page (struct page *page) + +static struct zspage *get_zspage (struct page *page) { -if (is_first_page (page)) -return page; -else -return (struct page *)page_private (page); +return (struct zspage *)page->private; }static struct page *get_next_page (struct page *page) { -struct page *next; - -if (is_last_page (page)) - next =NULL ; -else if (is_first_page (page)) - next = (struct page *)page_private (page); -else - next = list_entry(page->lru.next, struct page, lru); - -return next; +return page->next; }/*
@@ -887,7 +862,7 @@ static unsigned long obj_to_head(struct size_class *class, struct page *page, {if (class->huge) {VM_BUG_ON_PAGE (!is_first_page (page), page); -return page_private (page); +return page->index; }else return *(unsigned long *)obj; }
@@ -895,10 +870,9 @@ static unsigned long obj_to_head(struct size_class *class, struct page *page,static unsigned long obj_idx_to_offset (struct page *page,unsigned long obj_idx,int class_size) { -unsigned long off =0 ; +unsigned long off; -if (!is_first_page (page)) - off =get_first_obj_offset (page); + off =get_first_obj_offset (page);return off + obj_idx * class_size; }
@@ -923,44 +897,31 @@ static void reset_page(struct page *page)clear_bit (PG_private, &page->flags);clear_bit (PG_private_2, &page->flags);set_page_private (page,0 ); - page->mapping =NULL ; - page->freelist =NULL ; -page_mapcount_reset (page); + page->index =0 ; } -static void free_zspage (struct page *first_page) +static void free_zspage (struct zs_pool *pool,struct zspage *zspage) { -struct page *nextp, *tmp, *head_extra; +struct page *page, *next; -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); -VM_BUG_ON_PAGE (get_zspage_inuse (first_page), first_page); +VM_BUG_ON (get_zspage_inuse (zspage)); - head_extra = (struct page *)page_private (first_page); + next = page = zspage->first_page; +do { + next = page->next; +reset_page (page); +put_page (page); + page = next; + }while (page !=NULL ); -reset_page (first_page); -__free_page (first_page); - -/* zspage with only 1 system page */ -if (!head_extra) -return ; - -list_for_each_entry_safe (nextp, tmp, &head_extra->lru, lru) { -list_del (&nextp->lru); -reset_page (nextp); -__free_page (nextp); - } -reset_page (head_extra); -__free_page (head_extra); +cache_free_zspage (pool, zspage); }/* Initialize a newly allocated zspage */ -static void init_zspage (struct size_class *class,struct page *first_page) +static void init_zspage (struct size_class *class,struct zspage *zspage) {unsigned long off =0 ; -struct page *page = first_page; - - first_page->freelist =NULL ; -set_zspage_inuse (first_page,0 ); +struct page *page = zspage->first_page;while (page) {struct page *next_page;
@@ -968,14 +929,7 @@ static void init_zspage(struct size_class *class, struct page *first_page)unsigned int i =1 ;void *vaddr; -/* -* page->index stores offset of first object starting -* in the page. For the first page, this is always 0, -* so we use first_page->index (aka ->freelist) to store -* head of corresponding zspage's freelist. -*/ -if (page != first_page) -set_first_obj_offset (page, off); +set_first_obj_offset (page, off); vaddr =kmap_atomic (page); link = (struct link_free *)vaddr + off /sizeof (*link);
@@ -997,44 +951,38 @@ static void init_zspage(struct size_class *class, struct page *first_page) off %=PAGE_SIZE ; } -set_freeobj (first_page, (unsigned long )location_to_obj (first_page,0 )); +set_freeobj (zspage, + (unsigned long )location_to_obj (zspage->first_page,0 )); } -static void create_page_chain (struct page *pages[],int nr_pages) +static void create_page_chain (struct zspage *zspage,struct page *pages[], +int nr_pages) {int i;struct page *page;struct page *prev_page =NULL ; -struct page *first_page =NULL ;/* * Allocate individual pages and link them together as: -* 1. first page->private = first sub-page -* 2. all sub-pages are linked together using page->lru -* 3. each sub-page is linked to the first page using page->private +* 1. all pages are linked together using page->next +* 2. each sub-page point to zspage using page->private * -* For each size class, First/Head pages are linked together using -* page->lru. Also, we set PG_private to identify the first page -* (i.e. no other sub-page has this flag set) and PG_private_2 to -* identify the last page. +* we set PG_private to identify the first page (i.e. no other sub-page +* has this flag set) and PG_private_2 to identify the last page. */ for (i =0 ; i < nr_pages; i++) { page = pages[i]; - -INIT_LIST_HEAD (&page->lru); +set_page_private (page, (unsigned long )zspage);if (i ==0 ) { + zspage->first_page = page;SetPagePrivate (page); -set_page_private (page,0 ); - first_page = page; + }else { + prev_page->next = page; } -if (i ==1 ) -set_page_private (first_page, (unsigned long )page); -if (i >=1 ) -set_page_private (page, (unsigned long )first_page); -if (i >=2 ) -list_add (&page->lru, &prev_page->lru); -if (i == nr_pages -1 ) +if (i == nr_pages -1 ) {SetPagePrivate2 (page); + page->next =NULL ; + } prev_page = page; } }
@@ -1042,43 +990,51 @@ static void create_page_chain(struct page *pages[], int nr_pages)/* * Allocate a zspage for the given size class */ -static struct page *alloc_zspage (struct size_class *class,gfp_t flags) +static struct zspage *alloc_zspage (struct zs_pool *pool, +struct size_class *class, +gfp_t gfp) {int i; -struct page *first_page =NULL ;struct page *pages[ZS_MAX_PAGES_PER_ZSPAGE ]; +struct zspage *zspage =cache_alloc_zspage (pool, gfp); + +if (!zspage) +return NULL ; + +memset (zspage,0 ,sizeof (struct zspage ));for (i =0 ; i < class->pages_per_zspage; i++) {struct page *page; - page =alloc_page (flags); + page =alloc_page (gfp);if (!page) {while (--i >=0 )__free_page (pages[i]); +cache_free_zspage (pool, zspage);return NULL ; } pages[i] = page; } -create_page_chain (pages, class->pages_per_zspage); - first_page = pages[0 ]; -init_zspage (class, first_page); +create_page_chain (zspage, pages, class->pages_per_zspage); +init_zspage (class, zspage); -return first_page; +return zspage; } -static struct page *find_get_zspage (struct size_class *class) +static struct zspage *find_get_zspage (struct size_class *class) {int i; -struct page *page; +struct zspage *zspage; -for (i =0 ; i < _ZS_NR_FULLNESS_GROUPS; i++) { - page = class->fullness_list[i]; -if (page) +for (i =ZS_ALMOST_FULL ; i <=ZS_ALMOST_EMPTY ; i++) { + zspage =list_first_entry_or_null (&class->fullness_list[i], + struct zspage, list); +if (zspage)break ; } -return page; +return zspage; }#ifdef CONFIG_PGTABLE_MAPPING
@@ -1283,11 +1239,9 @@ static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)return true; } -static bool zspage_full (struct size_class *class,struct page *first_page) +static bool zspage_full (struct size_class *class,struct zspage *zspage) { -VM_BUG_ON_PAGE (!is_first_page (first_page), first_page); - -return get_zspage_inuse (first_page) == class->objs_per_zspage; +return get_zspage_inuse (zspage) == class->objs_per_zspage; }unsigned long zs_get_total_pages (struct zs_pool *pool)
@@ -1313,6 +1267,7 @@ EXPORT_SYMBOL_GPL(zs_get_total_pages);void *zs_map_object (struct zs_pool *pool,unsigned long handle,enum zs_mapmode mm) { +struct zspage *zspage;struct page *page;unsigned long obj, obj_idx, off;
@@ -1335,7 +1290,8 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, obj =handle_to_obj (handle);obj_to_location (obj, &page, &obj_idx); -get_zspage_mapping (get_first_page (page), &class_idx, &fg); + zspage =get_zspage (page); +get_zspage_mapping (zspage, &class_idx, &fg); class = pool->size_class[class_idx]; off =obj_idx_to_offset (page, obj_idx, class->size);
@@ -1364,6 +1320,7 @@ EXPORT_SYMBOL_GPL(zs_map_object);void zs_unmap_object (struct zs_pool *pool,unsigned long handle) { +struct zspage *zspage;struct page *page;unsigned long obj, obj_idx, off;
@@ -1374,7 +1331,8 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) obj =handle_to_obj (handle);obj_to_location (obj, &page, &obj_idx); -get_zspage_mapping (get_first_page (page), &class_idx, &fg); + zspage =get_zspage (page); +get_zspage_mapping (zspage, &class_idx, &fg); class = pool->size_class[class_idx]; off =obj_idx_to_offset (page, obj_idx, class->size);
@@ -1396,7 +1354,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle)EXPORT_SYMBOL_GPL (zs_unmap_object);static unsigned long obj_malloc (struct size_class *class, -struct page *first_page,unsigned long handle) +struct zspage *zspage,unsigned long handle) {unsigned long obj;struct link_free *link;
@@ -1406,21 +1364,22 @@ static unsigned long obj_malloc(struct size_class *class,void *vaddr; handle |=OBJ_ALLOCATED_TAG ; - obj =get_freeobj (first_page); + obj =get_freeobj (zspage);obj_to_location (obj, &m_page, &m_objidx); m_offset =obj_idx_to_offset (m_page, m_objidx, class->size); vaddr =kmap_atomic (m_page); link = (struct link_free *)vaddr + m_offset /sizeof (*link); -set_freeobj (first_page, (unsigned long )link->next); +set_freeobj (zspage, (unsigned long )link->next);if (!class->huge)/* record handle in the header of allocated chunk */ link->handle = handle;else -/* record handle in first_page->private */ -set_page_private (first_page, handle); +/* record handle to page->index */ + zspage->first_page->index = handle; +kunmap_atomic (vaddr); -mod_zspage_inuse (first_page,1 ); +mod_zspage_inuse (zspage,1 );zs_stat_inc (class,OBJ_USED ,1 );return obj;
@@ -1440,12 +1399,12 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) {unsigned long handle, obj;struct size_class *class; -struct page *first_page; +struct zspage *zspage;if (unlikely (!size || size >ZS_MAX_ALLOC_SIZE ))return 0 ; - handle =alloc_handle (pool, gfp); + handle =cache_alloc_handle (pool, gfp);if (!handle)return 0 ;
@@ -1454,17 +1413,17 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) class = pool->size_class[get_size_class_index (size)];spin_lock (&class->lock); - first_page =find_get_zspage (class); + zspage =find_get_zspage (class); -if (!first_page) { +if (!zspage) {spin_unlock (&class->lock); - first_page =alloc_zspage (class, gfp); -if (unlikely (!first_page)) { -free_handle (pool, handle); + zspage =alloc_zspage (pool, class, gfp); +if (unlikely (!zspage)) { +cache_free_handle (pool, handle);return 0 ; } -set_zspage_mapping (first_page, class->index,ZS_EMPTY ); +set_zspage_mapping (zspage, class->index,ZS_EMPTY );atomic_long_add (class->pages_per_zspage, &pool->pages_allocated);
@@ -1473,9 +1432,9 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) class->size, class->pages_per_zspage)); } - obj =obj_malloc (class, first_page, handle); + obj =obj_malloc (class, zspage, handle);/* Now move the zspage to another fullness group, if required */ -fix_fullness_group (class, first_page); +fix_fullness_group (class, zspage);record_obj (handle, obj);spin_unlock (&class->lock);
@@ -1486,13 +1445,14 @@ EXPORT_SYMBOL_GPL(zs_malloc);static void obj_free (struct size_class *class,unsigned long obj) {struct link_free *link; -struct page *first_page, *f_page; +struct zspage *zspage; +struct page *f_page;unsigned long f_objidx, f_offset;void *vaddr; obj &= ~OBJ_ALLOCATED_TAG ;obj_to_location (obj, &f_page, &f_objidx); - first_page =get_first_page (f_page); + zspage =get_zspage (f_page); f_offset =obj_idx_to_offset (f_page, f_objidx, class->size);
@@ -1500,18 +1460,17 @@ static void obj_free(struct size_class *class, unsigned long obj)/* Insert this object in containing zspage's freelist */ link = (struct link_free *)(vaddr + f_offset); - link->next = (void *)get_freeobj (first_page); -if (class->huge) -set_page_private (first_page,0 ); + link->next = (void *)get_freeobj (zspage);kunmap_atomic (vaddr); -set_freeobj (first_page, obj); -mod_zspage_inuse (first_page,-1 ); +set_freeobj (zspage, obj); +mod_zspage_inuse (zspage,-1 );zs_stat_dec (class,OBJ_USED ,1 ); }void zs_free (struct zs_pool *pool,unsigned long handle) { -struct page *first_page, *f_page; +struct zspage *zspage; +struct page *f_page;unsigned long obj, f_objidx;int class_idx;struct size_class *class;
@@ -1523,25 +1482,25 @@ void zs_free(struct zs_pool *pool, unsigned long handle)pin_tag (handle); obj =handle_to_obj (handle);obj_to_location (obj, &f_page, &f_objidx); - first_page =get_first_page (f_page); + zspage =get_zspage (f_page); -get_zspage_mapping (first_page, &class_idx, &fullness); +get_zspage_mapping (zspage, &class_idx, &fullness); class = pool->size_class[class_idx];spin_lock (&class->lock);obj_free (class, obj); - fullness =fix_fullness_group (class, first_page); + fullness =fix_fullness_group (class, zspage);if (fullness ==ZS_EMPTY ) {zs_stat_dec (class,OBJ_ALLOCATED ,get_maxobj_per_zspage ( class->size, class->pages_per_zspage));atomic_long_sub (class->pages_per_zspage, &pool->pages_allocated); -free_zspage (first_page); +free_zspage (pool, zspage); }spin_unlock (&class->lock);unpin_tag (handle); -free_handle (pool, handle); +cache_free_handle (pool, handle); }EXPORT_SYMBOL_GPL (zs_free);
@@ -1620,8 +1579,7 @@ static unsigned long find_alloced_obj(struct size_class *class,unsigned long handle =0 ;void *addr =kmap_atomic (page); -if (!is_first_page (page)) - offset =get_first_obj_offset (page); + offset =get_first_obj_offset (page); offset += class->size * index;while (offset <PAGE_SIZE ) {
@@ -1642,7 +1600,7 @@ static unsigned long find_alloced_obj(struct size_class *class, }struct zs_compact_control { -/* Source page for migration which could be a subpage of zspage. */ +/* Source spage for migration which could be a subpage of zspage */ struct page *s_page;/* Destination page for migration which should be a first page * of zspage. */
@@ -1673,14 +1631,14 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class, }/* Stop if there is no more space */ -if (zspage_full (class, d_page)) { +if (zspage_full (class,get_zspage (d_page))) {unpin_tag (handle); ret = -ENOMEM ;break ; } used_obj =handle_to_obj (handle); - free_obj =obj_malloc (class, d_page, handle); + free_obj =obj_malloc (class,get_zspage (d_page), handle);zs_object_copy (class, free_obj, used_obj); index++;/*
@@ -1702,39 +1660,46 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,return ret; } -static struct page *isolate_target_page (struct size_class *class) +static struct zspage *isolate_zspage (struct size_class *class,bool source) {int i; -struct page *page; +struct zspage *zspage; +enum fullness_group fg[2 ] = {ZS_ALMOST_EMPTY ,ZS_ALMOST_FULL }; -for (i =0 ; i < _ZS_NR_FULLNESS_GROUPS; i++) { - page = class->fullness_list[i]; -if (page) { -remove_zspage (class, i, page); -break ; +if (!source) { + fg[0 ] =ZS_ALMOST_FULL ; + fg[1 ] =ZS_ALMOST_EMPTY ; + } + +for (i =0 ; i <2 ; i++) { + zspage =list_first_entry_or_null (&class->fullness_list[fg[i]], + struct zspage, list); +if (zspage) { +remove_zspage (class, zspage, fg[i]); +return zspage; } } -return page; +return zspage; }/* -* putback_zspage - add @first_page into right class's fullness list +* putback_zspage - add @zspage into right class's fullness list * @pool: target pool * @class: destination class -* @first_page: target page +* @zspage: target page * -* Return @fist_page's fullness_group +* Return @zspage's fullness_group */ static enum fullness_group putback_zspage (struct zs_pool *pool,struct size_class *class, -struct page *first_page) +struct zspage *zspage) {enum fullness_group fullness; - fullness =get_fullness_group (class, first_page); -insert_zspage (class, fullness, first_page); -set_zspage_mapping (first_page, class->index, fullness); + fullness =get_fullness_group (class, zspage); +insert_zspage (class, zspage, fullness); +set_zspage_mapping (zspage, class->index, fullness);if (fullness ==ZS_EMPTY ) { zs_stat_dec(class, OBJ_ALLOCATED, get_maxobj_per_zspage(
@@ -1742,29 +1707,12 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,atomic_long_sub (class->pages_per_zspage, &pool->pages_allocated); -free_zspage (first_page); +free_zspage (pool, zspage); }return fullness; } -static struct page *isolate_source_page (struct size_class *class) -{ -int i; -struct page *page =NULL ; - -for (i =ZS_ALMOST_EMPTY ; i >=ZS_ALMOST_FULL ; i--) { - page = class->fullness_list[i]; -if (!page) -continue ; - -remove_zspage (class, i, page); -break ; - } - -return page; -} -/* * * Based on the number of unused allocated objects calculate
@@ -1786,20 +1734,20 @@ static unsigned long zs_can_compact(struct size_class *class)static void __zs_compact (struct zs_pool *pool,struct size_class *class) {struct zs_compact_control cc; -struct page *src_page; -struct page *dst_page =NULL ; +struct zspage *src_zspage; +struct zspage *dst_zspage =NULL ;spin_lock (&class->lock); -while ((src_page =isolate_source_page (class))) { +while ((src_zspage =isolate_zspage (class, true))) {if (!zs_can_compact (class))break ; cc.index =0 ; - cc.s_page = src_page; + cc.s_page = src_zspage->first_page; -while ((dst_page =isolate_target_page (class))) { - cc.d_page = dst_page; +while ((dst_zspage =isolate_zspage (class, false))) { + cc.d_page = dst_zspage->first_page;/* * If there is no more space in dst_page, resched * and see if anyone had allocated another zspage.
@@ -1807,23 +1755,23 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)if (!migrate_zspage (pool, class, &cc))break ; -putback_zspage (pool, class, dst_page); +putback_zspage (pool, class, dst_zspage); }/* Stop if we couldn't find slot */ -if (dst_page ==NULL ) +if (dst_zspage ==NULL )break ; -putback_zspage (pool, class, dst_page); -if (putback_zspage (pool, class, src_page) ==ZS_EMPTY ) +putback_zspage (pool, class, dst_zspage); +if (putback_zspage (pool, class, src_zspage) ==ZS_EMPTY ) pool->stats.pages_compacted += class->pages_per_zspage;spin_unlock (&class->lock);cond_resched ();spin_lock (&class->lock); } -if (src_page) -putback_zspage (pool, class, src_page); +if (src_zspage) +putback_zspage (pool, class, src_zspage);spin_unlock (&class->lock); }
@@ -1941,7 +1889,7 @@ struct zs_pool *zs_create_pool(const char *name)if (!pool->name) goto err; -if (create_handle_cache (pool)) +if (create_cache (pool)) goto err;/*
@@ -1952,6 +1900,7 @@ struct zs_pool *zs_create_pool(const char *name)int size;int pages_per_zspage;struct size_class *class; +int fullness =0 ; size =ZS_MIN_ALLOC_SIZE + i *ZS_SIZE_CLASS_DELTA ;if (size >ZS_MAX_ALLOC_SIZE )
@@ -1987,6 +1936,9 @@ struct zs_pool *zs_create_pool(const char *name) class->huge = true;spin_lock_init (&class->lock); pool->size_class[i] = class; +for (fullness =ZS_ALMOST_FULL ; fullness <=ZS_ALMOST_EMPTY ; + fullness++) +INIT_LIST_HEAD (&class->fullness_list[fullness]); prev_class = class; }
@@ -2025,8 +1977,8 @@ void zs_destroy_pool(struct zs_pool *pool)if (class->index != i)continue ; -for (fg =0 ; fg < _ZS_NR_FULLNESS_GROUPS; fg++) { -if (class->fullness_list[fg]) { +for (fg =ZS_ALMOST_FULL ; fg <=ZS_ALMOST_EMPTY ; fg++) { +if (!list_empty (&class->fullness_list[fg])) {pr_info ("Freeing non-empty class with size %db, fullness group %d\n" , class->size, fg); }
@@ -2034,7 +1986,7 @@ void zs_destroy_pool(struct zs_pool *pool)kfree (class); } -destroy_handle_cache (pool); +destroy_cache (pool);kfree (pool->size_class);kfree (pool->name);kfree (pool);
Signature · 1 line
1.9.1
Re: [PATCH v5 08/12] zsmalloc: introduce zspage structure
Quoted 14 lines · Minchan Kim
We have squeezed meta data of zspage into first page's descriptor. So, to get meta data from subpage, we should get first page first of all. But it makes trouble to implment page migration feature of zsmalloc because any place where to get first page from subpage can be raced with first page migration. IOW, first page it got could be stale. For preventing it, I have tried several approahces but it made code complicated so finally, I concluded to separate metadata from first page. Of course, it consumes more memory. IOW, 16bytes per zspage on 32bit at the moment. It means we lost 1% at *worst case*(40B/4096B) which is not bad I think at the cost of maintenance.
Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>
[..]
Quoted 10 lines
mm/zsmalloc.c +0
-2@@ -153,8 +138,6 @@enum fullness_group {ZS_ALMOST_FULL ,ZS_ALMOST_EMPTY , - _ZS_NR_FULLNESS_GROUPS, -ZS_EMPTY ,ZS_FULL };
mm/zsmalloc.c static const int fullness_threshold_frac = 4; · line 189
Quoted 5 lines
mm/zsmalloc.c +1
-1@@ -203,7 +186,7 @@ static const int fullness_threshold_frac = 4;struct size_class {spinlock_t lock; -struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS]; +struct list_head fullness_list[2 ];
seems that it also has some cleaup bits in it.
[..]
mm/zsmalloc.c struct mapping_area { · line 287
Quoted 13 lines
mm/zsmalloc.c +1
-1-static int create_handle_cache (struct zs_pool *pool) +static int create_cache (struct zs_pool *pool) { pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,mm/zsmalloc.c +7
-10, 0, NULL); -return pool->handle_cachep ?0 :1 ; +if (!pool->handle_cachep) +return 1 ; + + pool->zspage_cachep =kmem_cache_create ("zspage" ,sizeof (struct zspage ), +0 ,0 ,NULL ); +if (!pool->zspage_cachep) { +kmem_cache_destroy (pool->handle_cachep);
^^^^^
do you need to NULL a pool->handle_cachep here?
zs_create_pool()
if (create_cache() == 1) {
pool->zspage_cachep NULL
pool->handle_cachep !NULL already freed -> kmem_cache_destroy()
return 1;
goto err
}
err:
zs_destroy_pool()
destroy_cache() {
kmem_cache_destroy(pool->handle_cachep); !NULL and freed
kmem_cache_destroy(pool->zspage_cachep); NULL ok
}can we also switch create_cache() to errnos? I just like a bit better
return -ENOMEM; else return 0;
than
return 1; else return 0;
mm/zsmalloc.c static void init_zspage(struct size_class *class, struct page *first_page) · line 955
Quoted 7 lines
mm/zsmalloc.c +2
-1@@ -997,44 +951,38 @@ static void init_zspage(struct size_class *class, struct page *first_page) off %=PAGE_SIZE ; } -set_freeobj (first_page, (unsigned long )location_to_obj (first_page,0 )); +set_freeobj (zspage, + (unsigned long )location_to_obj (zspage->first_page,0 ));
static unsigned long location_to_obj()
it's already returning "(unsigned long)", so here and in several other places this cast can be dropped.
[..]
mm/zsmalloc.c static int migrate_zspage(struct zs_pool *pool, struct size_class *class, · line 1674
Quoted 10 lines
mm/zsmalloc.c +9
-0+static struct zspage *isolate_zspage (struct size_class *class,bool source) { +struct zspage *zspage; +enum fullness_group fg[2 ] = {ZS_ALMOST_EMPTY ,ZS_ALMOST_FULL }; +if (!source) { + fg[0 ] =ZS_ALMOST_FULL ; + fg[1 ] =ZS_ALMOST_EMPTY ; + } + +for (i =0 ; i <2 ; i++) {
sorry, why not "for (i = ZS_ALMOST_EMPTY; i <= ZS_ALMOST_FULL ..." ?
mm/zsmalloc.c static int migrate_zspage(struct zs_pool *pool, struct size_class *class, · line 1684
Quoted 11 lines
mm/zsmalloc.c +6
-1+ zspage =list_first_entry_or_null (&class->fullness_list[fg[i]], + struct zspage, list); +if (zspage) { +remove_zspage (class, zspage, fg[i]); +return zspage; } } -return page; +return zspage; }
-ss
--
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>
Minchan Kim
maintainerRe: [PATCH v5 08/12] zsmalloc: introduce zspage structure
Quoted 50 lines · Sergey Senozhatsky
Quoted 14 lines · Minchan Kim
We have squeezed meta data of zspage into first page's descriptor. So, to get meta data from subpage, we should get first page first of all. But it makes trouble to implment page migration feature of zsmalloc because any place where to get first page from subpage can be raced with first page migration. IOW, first page it got could be stale. For preventing it, I have tried several approahces but it made code complicated so finally, I concluded to separate metadata from first page. Of course, it consumes more memory. IOW, 16bytes per zspage on 32bit at the moment. It means we lost 1% at *worst case*(40B/4096B) which is not bad I think at the cost of maintenance.
Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>[..]
Quoted 10 lines
mm/zsmalloc.c +0
-2@@ -153,8 +138,6 @@enum fullness_group {ZS_ALMOST_FULL ,ZS_ALMOST_EMPTY , - _ZS_NR_FULLNESS_GROUPS, -ZS_EMPTY ,ZS_FULL };mm/zsmalloc.c static const int fullness_threshold_frac = 4; · line 189
Quoted 5 lines
mm/zsmalloc.c +1
-1@@ -203,7 +186,7 @@ static const int fullness_threshold_frac = 4;struct size_class {spinlock_t lock; -struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS]; +struct list_head fullness_list[2 ];seems that it also has some cleaup bits in it.
[..]
mm/zsmalloc.c struct mapping_area { · line 287
Quoted 13 lines
mm/zsmalloc.c +1
-1-static int create_handle_cache (struct zs_pool *pool) +static int create_cache (struct zs_pool *pool) { pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,mm/zsmalloc.c +7
-10, 0, NULL); -return pool->handle_cachep ?0 :1 ; +if (!pool->handle_cachep) +return 1 ; + + pool->zspage_cachep =kmem_cache_create ("zspage" ,sizeof (struct zspage ), +0 ,0 ,NULL ); +if (!pool->zspage_cachep) { +kmem_cache_destroy (pool->handle_cachep);^^^^^
Quoted 1 line
do you need to NULL a
pool->handle_cachephere?
Thanks, Will fix.
Quoted 22 lines
zs_create_pool()if (create_cache() == 1) { pool->zspage_cachep NULL pool->handle_cachep !NULL already freed -> kmem_cache_destroy() return 1; goto err } err: zs_destroy_pool() destroy_cache() { kmem_cache_destroy(pool->handle_cachep); !NULL and freed kmem_cache_destroy(pool->zspage_cachep); NULL ok }can we also switch
create_cache()to errnos? I just like a bit betterreturn -ENOMEM; else return 0;
Quoted 6 lines
than
return 1; else return 0;
Hmm, of course, I can do it easily.
But zs_create_pool returns NULL without error propagation from sub functions so I don't see any gain from returning errno from create_cache. I don't mean I hate it but just need a justificaion to persuade grumpy me.
Quoted 5 lines
Quoted 5 lines
mm/zsmalloc.c +0
-0@@ -997,44 +951,38 @@ static void init_zspage(struct size_class *class, struct page *first_page) off %=PAGE_SIZE ; }
Quoted 8 lines
mm/zsmalloc.c static void init_zspage(struct size_class *class, struct page *first_page) · line 955
Quoted 3 lines
mm/zsmalloc.c +2
-1-set_freeobj (first_page, (unsigned long )location_to_obj (first_page,0 )); +set_freeobj (zspage, + (unsigned long )location_to_obj (zspage->first_page,0 ));static unsigned long
location_to_obj()it's already returning "(unsigned long)", so here and in several other places this cast can be dropped.
Yeb.
Quoted 14 lines
[..]
mm/zsmalloc.c static int migrate_zspage(struct zs_pool *pool, struct size_class *class, · line 1674
Quoted 10 lines
mm/zsmalloc.c +9
-0+static struct zspage *isolate_zspage (struct size_class *class,bool source) { +struct zspage *zspage; +enum fullness_group fg[2 ] = {ZS_ALMOST_EMPTY ,ZS_ALMOST_FULL }; +if (!source) { + fg[0 ] =ZS_ALMOST_FULL ; + fg[1 ] =ZS_ALMOST_EMPTY ; + } + +for (i =0 ; i <2 ; i++) {sorry, why not "for (i =
ZS_ALMOST_EMPTY; i <=ZS_ALMOST_FULL..." ?
For source zspage, the policy is to find a fragment object from ZS_ALMOST_EMPTY. For target zspage, the policy is to find a fragment object from ZS_ALMOST_FULL.
Do I misunderstand your question?
Quoted 9 lines
Quoted 9 lines
mm/zsmalloc.c +5
-0+ zspage =list_first_entry_or_null (&class->fullness_list[fg[i]], + struct zspage, list); +if (zspage) { +remove_zspage (class, zspage, fg[i]); +return zspage; } }
Quoted 5 lines
mm/zsmalloc.c static void create_page_chain(struct page *pages[], int nr_pages) · line 1038
Quoted 3 lines
mm/zsmalloc.c +1
-1-return page; +return zspage; }-ss
--
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>
Re: [PATCH v5 08/12] zsmalloc: introduce zspage structure
On (05/17/16 10:14), Minchan Kim wrote:
[..]
Quoted 13 lines
Quoted 6 lines
can we also switch
create_cache()to errnos? I just like a bit betterreturn -ENOMEM; else return 0;Quoted 6 lines
than
return 1; else return 0;
Quoted 5 lines
Hmm, of course, I can do it easily.
Butzs_create_poolreturns NULL without error propagation from sub functions so I don't see any gain from returning errno fromcreate_cache. I don't mean I hate it but just need a justificaion to persuade grumpy me.
:) not married to those errnos. can skip it.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
mm/zsmalloc.c +3
-0+static struct zspage *isolate_zspage (struct size_class *class,bool source) { +struct zspage *zspage; +enum fullness_group fg[2 ] = {ZS_ALMOST_EMPTY ,ZS_ALMOST_FULL };Quoted 8 lines
mm/zsmalloc.c static int migrate_zspage(struct zs_pool *pool, struct size_class *class, · line 1674
Quoted 6 lines
mm/zsmalloc.c +6
-0+if (!source) { + fg[0 ] =ZS_ALMOST_FULL ; + fg[1 ] =ZS_ALMOST_EMPTY ; + } + +for (i =0 ; i <2 ; i++) {sorry, why not "for (i =
ZS_ALMOST_EMPTY; i <=ZS_ALMOST_FULL..." ?
Quoted 4 lines
For source zspage, the policy is to find a fragment object from
ZS_ALMOST_EMPTY. For target zspage, the policy is to find a fragment object fromZS_ALMOST_FULL.Do I misunderstand your question?
ahhh... sorry, it's just me being silly. I got it now.
-ss
--
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>
Minchan Kim
maintainerPATCH v5 9/12 zsmalloc: separate free_zspage from putback_zspage
In reply to Minchan KimCurrently, putback_zspage does free zspage under class->lock if fullness become ZS_EMPTY but it makes trouble to implement locking scheme for new zspage migration.
So, this patch is to separate free_zspage from putback_zspage and free zspage out of class->lock which is preparation for zspage migration.
--- mm/zsmalloc.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
mm/zsmalloc.c +11 -16
@@ -1685,14 +1685,12 @@ static struct zspage *isolate_zspage(struct size_class *class, bool source)/* * putback_zspage - add @zspage into right class's fullness list -* @pool: target pool * @class: destination class * @zspage: target page * * Return @zspage's fullness_group */ -static enum fullness_group putback_zspage (struct zs_pool *pool, -struct size_class *class, +static enum fullness_group putback_zspage (struct size_class *class,struct zspage *zspage) {enum fullness_group fullness;
@@ -1701,15 +1699,6 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,insert_zspage (class, zspage, fullness);set_zspage_mapping (zspage, class->index, fullness); -if (fullness ==ZS_EMPTY ) { -zs_stat_dec (class,OBJ_ALLOCATED ,get_maxobj_per_zspage ( - class->size, class->pages_per_zspage)); -atomic_long_sub (class->pages_per_zspage, - &pool->pages_allocated); - -free_zspage (pool, zspage); - } -return fullness; }
@@ -1755,23 +1744,29 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)if (!migrate_zspage (pool, class, &cc))break ; -putback_zspage (pool, class, dst_zspage); +putback_zspage (class, dst_zspage); }/* Stop if we couldn't find slot */ if (dst_zspage ==NULL )break ; -putback_zspage (pool, class, dst_zspage); -if (putback_zspage (pool, class, src_zspage) ==ZS_EMPTY ) +putback_zspage (class, dst_zspage); +if (putback_zspage (class, src_zspage) ==ZS_EMPTY ) { +zs_stat_dec (class,OBJ_ALLOCATED ,get_maxobj_per_zspage ( + class->size, class->pages_per_zspage)); +atomic_long_sub (class->pages_per_zspage, + &pool->pages_allocated); +free_zspage (pool, src_zspage); pool->stats.pages_compacted += class->pages_per_zspage; + }spin_unlock (&class->lock);cond_resched ();spin_lock (&class->lock); }if (src_zspage) -putback_zspage (pool, class, src_zspage); +putback_zspage (class, src_zspage);spin_unlock (&class->lock); }
Signature · 1 line
1.9.1
Re: [PATCH v5 09/12] zsmalloc: separate free_zspage from putback_zspage
Quoted 9 lines · Minchan Kim
Currently,
putback_zspagedoes free zspage underclass->lockif fullness becomeZS_EMPTYbut it makes trouble to implement locking scheme for new zspage migration.
So, this patch is to separatefree_zspagefromputback_zspageand free zspage out ofclass->lockwhich is preparation for zspage migration.Cc Sergey Senozhatsky <[email protected]>Signed-off-by Minchan Kim <[email protected]>
-ss
Quoted 83 lines
--- mm/zsmalloc.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)mm/zsmalloc.c +11
-16@@ -1685,14 +1685,12 @@ static struct zspage *isolate_zspage(struct size_class *class, bool source)/* * putback_zspage - add @zspage into right class's fullness list -* @pool: target pool * @class: destination class * @zspage: target page * * Return @zspage's fullness_group */ -static enum fullness_group putback_zspage (struct zs_pool *pool, -struct size_class *class, +static enum fullness_group putback_zspage (struct size_class *class,struct zspage *zspage) {enum fullness_group fullness;@@ -1701,15 +1699,6 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,insert_zspage (class, zspage, fullness);set_zspage_mapping (zspage, class->index, fullness); -if (fullness ==ZS_EMPTY ) { -zs_stat_dec (class,OBJ_ALLOCATED ,get_maxobj_per_zspage ( - class->size, class->pages_per_zspage)); -atomic_long_sub (class->pages_per_zspage, - &pool->pages_allocated); - -free_zspage (pool, zspage); - } -return fullness; }@@ -1755,23 +1744,29 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)if (!migrate_zspage (pool, class, &cc))break ; -putback_zspage (pool, class, dst_zspage); +putback_zspage (class, dst_zspage); }/* Stop if we couldn't find slot */ if (dst_zspage ==NULL )break ; -putback_zspage (pool, class, dst_zspage); -if (putback_zspage (pool, class, src_zspage) ==ZS_EMPTY ) +putback_zspage (class, dst_zspage); +if (putback_zspage (class, src_zspage) ==ZS_EMPTY ) { +zs_stat_dec (class,OBJ_ALLOCATED ,get_maxobj_per_zspage ( + class->size, class->pages_per_zspage)); +atomic_long_sub (class->pages_per_zspage, + &pool->pages_allocated); +free_zspage (pool, src_zspage); pool->stats.pages_compacted += class->pages_per_zspage; + }spin_unlock (&class->lock);cond_resched ();spin_lock (&class->lock); }if (src_zspage) -putback_zspage (pool, class, src_zspage); +putback_zspage (class, src_zspage);spin_unlock (&class->lock); }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>
--
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>
Minchan Kim
maintainerPATCH v5 10/12 zsmalloc: use freeobj for index
In reply to Minchan KimZsmalloc stores first free object's <PFN, obj_idx> position into freeobj in each zspage. If we change it with index from first_page instead of position, it makes page migration simple because we don't need to correct other entries for linked list if a page is migrated out.
--- mm/zsmalloc.c | 139 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 73 insertions(+), 66 deletions(-)
mm/zsmalloc.c +73 -66
@@ -69,9 +69,7 @@* Object location (<PFN>, <obj_idx>) is encoded as * as single (unsigned long) handle value. * -* Note that object index <obj_idx> is relative to system -* page <PFN> it is stored in, so for each sub-page belonging -* to a zspage, obj_idx starts with 0. +* Note that object index <obj_idx> starts from 0. * * This is made more complicated by various memory models and PAE. */
@@ -212,10 +210,10 @@ struct size_class {struct link_free {union {/* -* Position of next free chunk (encodes <PFN, obj_idx>) +* Free object index; * It's valid for non-allocated object */ -void *next; +unsigned long next;/* * Handle of allocated object. */
@@ -259,7 +257,7 @@ struct zspage { unsigned int class:CLASS_BITS; };unsigned int inuse; -void *freeobj; +unsigned int freeobj;struct page *first_page;struct list_head list;/* fullness list */ };
@@ -456,14 +454,14 @@ static inline void set_first_obj_offset(struct page *page, int offset) page->index = offset; } -static inline unsigned long get_freeobj (struct zspage *zspage) +static inline unsigned int get_freeobj (struct zspage *zspage) { -return (unsigned long )zspage->freeobj; +return zspage->freeobj; } -static inline void set_freeobj (struct zspage *zspage,unsigned long obj) +static inline void set_freeobj (struct zspage *zspage,unsigned int obj) { - zspage->freeobj = (void *)obj; + zspage->freeobj = obj; } static void get_zspage_mapping(struct zspage *zspage,
@@ -808,6 +806,10 @@ static int get_pages_per_zspage(int class_size)return max_usedpc_order; } +static struct page *get_first_page (struct zspage *zspage) +{ +return zspage->first_page; +}static struct zspage *get_zspage (struct page *page) {
@@ -819,37 +821,33 @@ static struct page *get_next_page(struct page *page)return page->next; } -/* -* Encode <page, obj_idx> as a single handle value. -* We use the least bit of handle for tagging. +/** +* obj_to_location - get (<page>, <obj_idx>) from encoded object value +* @page: page object resides in zspage +* @obj_idx: object index */ -static void *location_to_obj (struct page *page,unsigned long obj_idx) +static void obj_to_location (unsigned long obj,struct page **page, +unsigned int *obj_idx) { -unsigned long obj; + obj >>=OBJ_TAG_BITS ; + *page =pfn_to_page (obj >>OBJ_INDEX_BITS ); + *obj_idx = (obj &OBJ_INDEX_MASK ); +} -if (!page) { -VM_BUG_ON (obj_idx); -return NULL ; - } +/** +* location_to_obj - get obj value encoded from (<page>, <obj_idx>) +* @page: page object resides in zspage +* @obj_idx: object index +*/ +static unsigned long location_to_obj (struct page *page,unsigned int obj_idx) +{ +unsigned long obj; obj =page_to_pfn (page) <<OBJ_INDEX_BITS ; - obj |= ((obj_idx) &OBJ_INDEX_MASK ); + obj |= obj_idx &OBJ_INDEX_MASK ; obj <<=OBJ_TAG_BITS ; -return (void *)obj; -} - -/* -* Decode <page, obj_idx> pair from the given object handle. We adjust the -* decoded obj_idx back to its original value since it was adjusted in -* location_to_obj(). -*/ -static void obj_to_location (unsigned long obj,struct page **page, -unsigned long *obj_idx) -{ - obj >>=OBJ_TAG_BITS ; - *page =pfn_to_page (obj >>OBJ_INDEX_BITS ); - *obj_idx = (obj &OBJ_INDEX_MASK ); +return obj; }static unsigned long handle_to_obj (unsigned long handle)
@@ -867,16 +865,6 @@ static unsigned long obj_to_head(struct size_class *class, struct page *page,return *(unsigned long *)obj; } -static unsigned long obj_idx_to_offset (struct page *page, -unsigned long obj_idx,int class_size) -{ -unsigned long off; - - off =get_first_obj_offset (page); - -return off + obj_idx * class_size; -} -static inline int trypin_tag (unsigned long handle) {return bit_spin_trylock (HANDLE_PIN_BIT , (unsigned long *)handle);
@@ -920,13 +908,13 @@ static void free_zspage(struct zs_pool *pool, struct zspage *zspage)/* Initialize a newly allocated zspage */ static void init_zspage (struct size_class *class,struct zspage *zspage) { +unsigned int freeobj =1 ;unsigned long off =0 ;struct page *page = zspage->first_page;while (page) {struct page *next_page;struct link_free *link; -unsigned int i =1 ;void *vaddr;set_first_obj_offset (page, off);
@@ -935,7 +923,7 @@ static void init_zspage(struct size_class *class, struct zspage *zspage) link = (struct link_free *)vaddr + off /sizeof (*link);while ((off += class->size) <PAGE_SIZE ) { - link->next =location_to_obj (page, i++); + link->next = freeobj++ <<OBJ_ALLOCATED_TAG ; link += class->size /sizeof (*link); }
@@ -945,14 +933,21 @@ static void init_zspage(struct size_class *class, struct zspage *zspage)* page (if present) */ next_page =get_next_page (page); - link->next =location_to_obj (next_page,0 ); +if (next_page) { + link->next = freeobj++ <<OBJ_ALLOCATED_TAG ; + }else { +/* +* Reset OBJ_ALLOCATED_TAG bit to last link to tell +* whether it's allocated object or not. +*/ + link->next =-1 <<OBJ_ALLOCATED_TAG ; + }kunmap_atomic (vaddr); page = next_page; off %=PAGE_SIZE ; } -set_freeobj (zspage, - (unsigned long )location_to_obj (zspage->first_page,0 )); +set_freeobj (zspage,0 ); } static void create_page_chain(struct zspage *zspage, struct page *pages[],
@@ -1269,7 +1264,8 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, {struct zspage *zspage;struct page *page; -unsigned long obj, obj_idx, off; +unsigned long obj, off; +unsigned int obj_idx;unsigned int class_idx;enum fullness_group fg;
@@ -1293,7 +1289,7 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, zspage =get_zspage (page);get_zspage_mapping (zspage, &class_idx, &fg); class = pool->size_class[class_idx]; - off =obj_idx_to_offset (page, obj_idx, class->size); + off = (class->size * obj_idx) & ~PAGE_MASK ; area = &get_cpu_var (zs_map_area); area->vm_mm = mm;
@@ -1322,7 +1318,8 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) {struct zspage *zspage;struct page *page; -unsigned long obj, obj_idx, off; +unsigned long obj, off; +unsigned int obj_idx;unsigned int class_idx;enum fullness_group fg;
@@ -1334,7 +1331,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) zspage =get_zspage (page);get_zspage_mapping (zspage, &class_idx, &fg); class = pool->size_class[class_idx]; - off =obj_idx_to_offset (page, obj_idx, class->size); + off = (class->size * obj_idx) & ~PAGE_MASK ; area =this_cpu_ptr (&zs_map_area);if (off + class->size <=PAGE_SIZE )
@@ -1356,21 +1353,28 @@ EXPORT_SYMBOL_GPL(zs_unmap_object);static unsigned long obj_malloc (struct size_class *class,struct zspage *zspage,unsigned long handle) { +int i, nr_page, offset;unsigned long obj;struct link_free *link;struct page *m_page; -unsigned long m_objidx, m_offset; +unsigned long m_offset;void *vaddr; handle |=OBJ_ALLOCATED_TAG ; obj =get_freeobj (zspage); -obj_to_location (obj, &m_page, &m_objidx); - m_offset =obj_idx_to_offset (m_page, m_objidx, class->size); + + offset = obj * class->size; + nr_page = offset >>PAGE_SHIFT ; + m_offset = offset & ~PAGE_MASK ; + m_page =get_first_page (zspage); + +for (i =0 ; i < nr_page; i++) + m_page =get_next_page (m_page); vaddr =kmap_atomic (m_page); link = (struct link_free *)vaddr + m_offset /sizeof (*link); -set_freeobj (zspage, (unsigned long )link->next); +set_freeobj (zspage, link->next >>OBJ_ALLOCATED_TAG );if (!class->huge)/* record handle in the header of allocated chunk */ link->handle = handle;
@@ -1382,6 +1386,8 @@ static unsigned long obj_malloc(struct size_class *class,mod_zspage_inuse (zspage,1 );zs_stat_inc (class,OBJ_USED ,1 ); + obj =location_to_obj (m_page, obj); +return obj; }
@@ -1447,22 +1453,22 @@ static void obj_free(struct size_class *class, unsigned long obj)struct link_free *link;struct zspage *zspage;struct page *f_page; -unsigned long f_objidx, f_offset; +unsigned long f_offset; +unsigned int f_objidx;void *vaddr; obj &= ~OBJ_ALLOCATED_TAG ;obj_to_location (obj, &f_page, &f_objidx); + f_offset = (class->size * f_objidx) & ~PAGE_MASK ; zspage =get_zspage (f_page); - f_offset =obj_idx_to_offset (f_page, f_objidx, class->size); - vaddr =kmap_atomic (f_page);/* Insert this object in containing zspage's freelist */ link = (struct link_free *)(vaddr + f_offset); - link->next = (void *)get_freeobj (zspage); + link->next =get_freeobj (zspage) <<OBJ_ALLOCATED_TAG ;kunmap_atomic (vaddr); -set_freeobj (zspage, obj); +set_freeobj (zspage, f_objidx);mod_zspage_inuse (zspage,-1 );zs_stat_dec (class,OBJ_USED ,1 ); }
@@ -1471,7 +1477,8 @@ void zs_free(struct zs_pool *pool, unsigned long handle) {struct zspage *zspage;struct page *f_page; -unsigned long obj, f_objidx; +unsigned long obj; +unsigned int f_objidx;int class_idx;struct size_class *class;enum fullness_group fullness;
@@ -1508,7 +1515,7 @@ static void zs_object_copy(struct size_class *class, unsigned long dst, unsigned long src) {struct page *s_page, *d_page; -unsigned long s_objidx, d_objidx; +unsigned int s_objidx, d_objidx;unsigned long s_off, d_off;void *s_addr, *d_addr;int s_size, d_size, size;
@@ -1519,8 +1526,8 @@ static void zs_object_copy(struct size_class *class, unsigned long dst,obj_to_location (src, &s_page, &s_objidx);obj_to_location (dst, &d_page, &d_objidx); - s_off =obj_idx_to_offset (s_page, s_objidx, class->size); - d_off =obj_idx_to_offset (d_page, d_objidx, class->size); + s_off = (class->size * s_objidx) & ~PAGE_MASK ; + d_off = (class->size * d_objidx) & ~PAGE_MASK ;if (s_off + class->size >PAGE_SIZE ) s_size =PAGE_SIZE - s_off;
Signature · 1 line
1.9.1
Minchan Kim
maintainerPATCH v5 11/12 zsmalloc: page migration support
In reply to Minchan KimThis patch introduces run-time migration feature for zspage.
For migration, VM uses page.lru field so it would be better to not use page.next field which is unified with page.lru for own purpose. For that, firstly, we can get first object offset of the page via runtime calculation instead of using page.index so we can use page.index as link for page chaining instead of page.next.
In case of huge object, it stores handle to page.index instead of next link of page chaining because huge object doesn't need to next link for page chaining. So get_next_page need to identify huge object to return NULL. For it, this patch uses PG_owner_priv_1 flag of the page flag.
For migration, it supports three functions
* zs_page_isolate
It isolates a zspage which includes a subpage VM want to migrate from class so anyone cannot allocate new object from the zspage.
We could try to isolate a zspage by the number of subpage so subsequent isolation trial of other subpage of the zpsage shouldn't fail. For that, we introduce zspage.isolated count. With that, zs_page_isolate can know whether zspage is already isolated or not for migration so if it is isolated for migration, subsequent isolation trial can be successful without trying further isolation.
* zs_page_migrate
First of all, it holds write-side zspage->lock to prevent migrate other subpage in zspage. Then, lock all objects in the page VM want to migrate. The reason we should lock all objects in the page is due to race between zs_map_object and zs_page_migrate.
zs_map_object zs_page_migrate
pin_tag(handle)
obj = handle_to_obj(handle)obj_to_location(obj, &page, &obj_idx);
write_lock(&zspage->lock) if (!trypin_tag(handle)) goto unpin_object
zspage = get_zspage(page);read_lock(&zspage->lock);
If zs_page_migrate doesn't do trypin_tag, zs_map_object's page can be stale by migration so it goes crash.
If it locks all of objects successfully, it copies content from old page to new one, finally, create new zspage chain with new page. And if it's last isolated subpage in the zspage, put the zspage back to class.
* zs_page_putback
It returns isolated zspage to right fullness_group list if it fails to migrate a page. If it find a zspage is ZS_EMPTY, it queues zspage freeing to workqueue. See below about async zspage freeing.
This patch introduces asynchronous zspage free. The reason to need it is we need page_lock to clear PG_movable but unfortunately, zs_free path should be atomic so the apporach is try to grab page_lock. If it got page_lock of all of pages successfully, it can free zspage immediately. Otherwise, it queues free request and free zspage via workqueue in process context.
If zs_free finds the zspage is isolated when it try to free zspage, it delays the freeing until zs_page_putback finds it so it will free free the zspage finally.
In this patch, we expand fullness_list from ZS_EMPTY to ZS_FULL. First of all, it will use ZS_EMPTY list for delay freeing. And with adding ZS_FULL list, it makes to identify whether zspage is isolated or not via list_empty(&zspage->list) test.
--- include/uapi/linux/magic.h | 1 + mm/zsmalloc.c | 796 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 675 insertions(+), 122 deletions(-)
include/uapi/linux/magic.h +1 -0
@@ -81,5 +81,6 @@/* Since UDF 2.01 is ISO 13346 based... */ #define UDF_SUPER_MAGIC 0x15013346#define BALLOON_KVM_MAGIC 0x13661366 +#define ZSMALLOC_MAGIC 0x58295829#endif /* __LINUX_MAGIC_H__ */
mm/zsmalloc.c +674 -122
1,218 lines not on this page · raw message
Signature · 1 line
1.9.1
kbuild test robot
build botRe: [PATCH v5 11/12] zsmalloc: page migration support
url: https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-use-put_page-to-free-page-instead-of-putback_lru_page/20160509-102355 config: i386-randconfig-s0-05161922 (attached as .config) compiler…
Hi,
[auto build test ERROR on next-20160506]
[cannot apply to v4.6-rc7 v4.6-rc6 v4.6-rc5 v4.6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-use-put_page-to-free-page-instead-of-putback_lru_page/20160509-102355
config: i386-randconfig-s0-05161922 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
>> ERROR: "__SetPageMovable" [mm/zsmalloc.ko] undefined! >> ERROR: "PageMovable" [mm/zsmalloc.ko] undefined! >> ERROR: "__ClearPageMovable" [mm/zsmalloc.ko] undefined!
ERROR: "__ClearPageMovable" [drivers/virtio/virtio_balloon.ko] undefined!
ERROR: "__SetPageMovable" [drivers/virtio/virtio_balloon.ko] undefined!
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Minchan Kim
maintainerPATCH v5 12/12 zram: use __GFP_MOVABLE for memory allocation
In reply to Minchan KimZsmalloc is ready for page migration so zram can use __GFP_MOVABLE from now on.
I did test to see how it helps to make higher order pages. Test scenario is as follows.
KVM guest, 1G memory, ext4 formated zram block device,
for i in seq 1 8;
do
dd if=/dev/vda1 of=mnt/test$i.txt bs=128M count=1 &
done
wait pidof dd
for i in seq 1 2 8;
do
rm -rf mnt/test$i.txt
done
fstrim -v mnt
echo "init"
cat /proc/buddyinfo
echo "compaction"
echo 1 > /proc/sys/vm/compact_memory
cat /proc/buddyinfo
old:
init
Node 0, zone DMA 208 120 51 41 11 0 0 0 0 0 0 Node 0, zone DMA32 16380 13777 9184 3805 789 54 3 0 0 0 0 compaction Node 0, zone DMA 132 82 40 39 16 2 1 0 0 0 0 Node 0, zone DMA32 5219 5526 4969 3455 1831 677 139 15 0 0 0
new:
init
Node 0, zone DMA 379 115 97 19 2 0 0 0 0 0 0 Node 0, zone DMA32 18891 16774 10862 3947 637 21 0 0 0 0 0 compaction 1 Node 0, zone DMA 214 66 87 29 10 3 0 0 0 0 0 Node 0, zone DMA32 1612 3139 3154 2469 1745 990 384 94 7 0 0
As you can see, compaction made so many high-order pages. Yay!
--- drivers/block/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/block/zram/zram_drv.c +4 -2
@@ -714,13 +714,15 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, handle =zs_malloc (meta->mem_pool, clen, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN | - __GFP_HIGHMEM); + __GFP_HIGHMEM | + __GFP_MOVABLE);if (!handle) {zcomp_strm_release (zram->comp, zstrm); zstrm =NULL ; handle =zs_malloc (meta->mem_pool, clen, -GFP_NOIO | __GFP_HIGHMEM); +GFP_NOIO | __GFP_HIGHMEM | + __GFP_MOVABLE);if (handle) goto compress_again;
Signature · 1 line
1.9.1