per-process reclaim
Subsystems (7)
cover per-process reclaim
Hi all,
http://thread.gmane.org/gmane.linux.kernel/1480728
I sent per-process reclaim patchset three years ago. Then, last feedback from akpm was that he want to know real usecase scenario.
Since then, I got question from several embedded people of various company "why it's not merged into mainline" and heard they have used the feature as in-house patch and recenlty, I noticed android from Qualcomm started to use it.
Of course, our product have used it and released it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------
vanilla | 85 | 171 perproc reclaim | 184 | 72
"
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
As perproc reclaim way with new management policy, we could reduce cold launching a lot(i.e., 171-72) so that it reduces app startup a lot.
Another useful function from this feature is to make swapout easily which is useful for testing swapout stress and workloads.
Thanks.
Minchan Kim (3):
mm: vmscan: refactoring force_reclaim
mm: vmscan: shrink_page_list with multiple zones
mm: per-process reclaim
Documentation/filesystems/proc.txt | 15 ++++ fs/proc/base.c | 1 + fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 149 +++++++++++++++++++++++++++++++++++++ include/linux/rmap.h | 4 + mm/vmscan.c | 85 ++++++++++++++++----- 6 files changed, 235 insertions(+), 20 deletions(-)
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>
PATCH 1/3 mm: vmscan: refactoring force_reclaim
local variable references has PAGEREF_RECLAIM_CLEAN default value so that it can prevent dirty page writeout effectively for reclaim latency(introduced by [1]) if force_reclaim is true.
However, it is irony because user wanted *force reclaim* but we prohibit dirty page writeout.
Let's make it more clear.
This patch is refactoring so it shouldn't change any behavior.
[1] <02c6de8d757c, mm: cma: discard clean pages during contiguous allocation instead of migration>
--- mm/vmscan.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
mm/vmscan.c +20 -15
@@ -95,6 +95,9 @@ struct scan_control {/* Can cgroups be reclaimed below their normal consumption range? */ unsigned int may_thrash:1; +/* reclaim pages unconditionally */ + unsigned int force_reclaim:1; + unsigned int hibernation_mode:1;/* One of the zones is ready for compaction */
@@ -783,6 +786,7 @@ void putback_lru_page(struct page *page) }enum page_references { +PAGEREF_NONE ,PAGEREF_RECLAIM ,PAGEREF_RECLAIM_CLEAN ,PAGEREF_KEEP ,
@@ -884,8 +888,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,unsigned long *ret_nr_unqueued_dirty, unsigned long *ret_nr_congested, unsigned long *ret_nr_writeback, - unsigned long *ret_nr_immediate, - bool force_reclaim) + unsigned long *ret_nr_immediate) {LIST_HEAD (ret_pages );LIST_HEAD (free_pages);
@@ -903,7 +906,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,struct address_space *mapping;struct page *page;int may_enter_fs; -enum page_references references =PAGEREF_RECLAIM_CLEAN ; +enum page_references references =PAGEREF_NONE ;bool dirty, writeback;bool lazyfree = false;int ret =SWAP_SUCCESS ;
@@ -927,13 +930,15 @@ static unsigned long shrink_page_list(struct list_head *page_list,if (!sc->may_unmap &&page_mapped (page)) goto keep_locked; -/* Double the slab pressure for mapped and swapcache pages */ -if (page_mapped (page) ||PageSwapCache (page)) - sc->nr_scanned++; - may_enter_fs = (sc->gfp_mask & __GFP_FS) || (PageSwapCache (page) && (sc->gfp_mask & __GFP_IO)); +if (sc->force_reclaim) + goto force_reclaim; + +/* Double the slab pressure for mapped and swapcache pages */ +if (page_mapped (page) ||PageSwapCache (page)) + sc->nr_scanned++;/* * The number of dirty pages determines if a zone is marked * reclaim_congested which affects wait_iff_congested. kswapd
@@ -1028,19 +1033,18 @@ static unsigned long shrink_page_list(struct list_head *page_list, } } -if (!force_reclaim) - references =page_check_references (page, sc); + references =page_check_references (page, sc);switch (references) {case PAGEREF_ACTIVATE : goto activate_locked;case PAGEREF_KEEP : goto keep_locked; -case PAGEREF_RECLAIM : -case PAGEREF_RECLAIM_CLEAN : - ;/* try to reclaim the page below */ +default : +break ;/* try to reclaim the page below */ } +force_reclaim:/* * Anonymous process memory has backing store? * Try to allocate it some swap space here.
@@ -1253,6 +1257,8 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, .gfp_mask = GFP_KERNEL, .priority = DEF_PRIORITY, .may_unmap = 1, + .may_writepage = 0, + .force_reclaim = 1, };unsigned long ret, dummy1, dummy2, dummy3, dummy4, dummy5;struct page *page, *next;
@@ -1268,7 +1274,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, ret =shrink_page_list (&clean_pages, zone, &sc,TTU_UNMAP |TTU_IGNORE_ACCESS , - &dummy1, &dummy2, &dummy3, &dummy4, &dummy5, true); + &dummy1, &dummy2, &dummy3, &dummy4, &dummy5);list_splice (&clean_pages, page_list);mod_zone_page_state (zone,NR_ISOLATED_FILE , -ret);return ret;
@@ -1623,8 +1629,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, nr_reclaimed =shrink_page_list (&page_list, zone, sc,TTU_UNMAP , &nr_dirty, &nr_unqueued_dirty, &nr_congested, - &nr_writeback, &nr_immediate, - false); + &nr_writeback, &nr_immediate);spin_lock_irq (&zone->lru_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>
PATCH 2/3 mm: vmscan: shrink_page_list with multiple zones
In reply to Minchan KimWe have been reclaimed pages per zone but upcoming patch will pass pages from multiple zones into shrink_page_list so this patch prepares it.
--- mm/vmscan.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/vmscan.c +5 -5
@@ -881,7 +881,6 @@ static void page_check_dirty_writeback(struct page *page,* shrink_page_list() returns the number of reclaimed pages */ static unsigned long shrink_page_list(struct list_head *page_list, - struct zone *zone, struct scan_control *sc, enum ttu_flags ttu_flags, unsigned long *ret_nr_dirty,
@@ -910,6 +909,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,bool dirty, writeback;bool lazyfree = false;int ret =SWAP_SUCCESS ; +struct zone *zone;cond_resched ();
@@ -919,8 +919,8 @@ static unsigned long shrink_page_list(struct list_head *page_list,if (!trylock_page (page)) goto keep; + zone =page_zone (page);VM_BUG_ON_PAGE (PageActive (page), page); -VM_BUG_ON_PAGE (page_zone (page) != zone, page); sc->nr_scanned++;
@@ -933,6 +933,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, may_enter_fs = (sc->gfp_mask & __GFP_FS) || (PageSwapCache (page) && (sc->gfp_mask & __GFP_IO)); + mapping =page_mapping (page);if (sc->force_reclaim) goto force_reclaim;
@@ -958,7 +959,6 @@ static unsigned long shrink_page_list(struct list_head *page_list,* pages marked for immediate reclaim are making it to the * end of the LRU a second time. */ - mapping =page_mapping (page);if (((dirty || writeback) && mapping &&inode_write_congested (mapping->host)) || (writeback &&PageReclaim (page)))
@@ -1272,7 +1272,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, } } - ret =shrink_page_list (&clean_pages, zone, &sc, + ret =shrink_page_list (&clean_pages, &sc,TTU_UNMAP |TTU_IGNORE_ACCESS , &dummy1, &dummy2, &dummy3, &dummy4, &dummy5);list_splice (&clean_pages, page_list);
@@ -1627,7 +1627,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,if (nr_taken ==0 )return 0 ; - nr_reclaimed =shrink_page_list (&page_list, zone, sc,TTU_UNMAP , + nr_reclaimed =shrink_page_list (&page_list, sc,TTU_UNMAP , &nr_dirty, &nr_unqueued_dirty, &nr_congested, &nr_writeback, &nr_immediate);
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>
PATCH 3/3 mm: per-process reclaim
In reply to Minchan KimThese day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
One of useful usecase is to avoid process killing for getting free memory in android, which was really terrible experience because I lost my best score of game I had ever after I switch the phone call while I enjoyed the game as well as slow start-up by cold launching.
Our product have used it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------
vanilla | 85 | 171 perproc reclaim | 184 | 72
"
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
As perproc reclaim way with new management policy, we could reduce cold launching a lot(i.e., 171-72) so that it reduces app startup a lot.
Another useful function from this feature is to make swapout easily which is useful for testing swapout stress and workloads.
Interface:
Reclaim file-backed pages only.
echo 1 > /proc/<pid>/reclaim
Reclaim anonymous pages only.
echo 2 > /proc/<pid>/reclaim
Reclaim all pages
echo 3 > /proc/<pid>/reclaim
bit 1 : file, bit 2 : anon, bit 1 & 2 : all
Note:
If a page is shared by other processes(i.e., page_mapcount(page) > 1), it couldn't be reclaimed.
--- Documentation/filesystems/proc.txt | 15 ++++ fs/proc/base.c | 1 + fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 149 +++++++++++++++++++++++++++++++++++++ include/linux/rmap.h | 4 + mm/vmscan.c | 40 ++++++++++ 6 files changed, 210 insertions(+)
Documentation/filesystems/proc.txt +15 -0
@@ -138,6 +138,7 @@ Table 1-1: Process specific entries in /proc maps Memory maps to executables and library files (2.4) mem Memory held by this process root Link to the root directory of this process + reclaim Reclaim pages in this process stat Process status statm Process memory status information status Process status in human readable form
@@ -536,6 +537,20 @@ To reset the peak resident set size ("high water mark") to the process's Any other value written to /proc/PID/clear_refs will have no effect. +The file /proc/PID/reclaim is used to reclaim pages in this process. +bit 1: file, bit 2: anon, bit 3: all + +To reclaim file-backed pages, + > echo 1 > /proc/PID/reclaim + +To reclaim anonymous pages, + > echo 2 > /proc/PID/reclaim + +To reclaim all pages, + > echo 3 > /proc/PID/reclaim + +If a page is shared by several processes, it cannot be reclaimed. + The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags using /proc/kpageflags and number of times a page is mapped using /proc/kpagecount. For detailed explanation, see Documentation/vm/pagemap.txt.
fs/proc/base.c +1 -0
@@ -2848,6 +2848,7 @@ static const struct pid_entry tgid_base_stuff[] = {REG ("mounts" ,S_IRUGO , proc_mounts_operations),REG ("mountinfo" ,S_IRUGO , proc_mountinfo_operations),REG ("mountstats" ,S_IRUSR , proc_mountstats_operations), +REG ("reclaim" ,S_IWUSR , proc_reclaim_operations), #ifdef CONFIG_PROC_PAGE_MONITORREG ("clear_refs" ,S_IWUSR , proc_clear_refs_operations), REG("smaps", S_IRUGO, proc_pid_smaps_operations),
fs/proc/internal.h +1 -0
@@ -209,6 +209,7 @@ struct pde_opener {extern const struct inode_operations proc_link_inode_operations;extern const struct inode_operations proc_pid_link_inode_operations; +extern const struct file_operations proc_reclaim_operations;extern void proc_init_inodecache (void );extern struct inode *proc_get_inode (struct super_block *,struct proc_dir_entry *);
fs/proc/task_mmu.c +149 -0
161 lines not on this page · raw message
include/linux/rmap.h +4 -0
@@ -10,6 +10,10 @@#include <linux/rwsem.h> #include <linux/memcontrol.h> +extern int isolate_lru_page (struct page *page); +extern void putback_lru_page (struct page *page); +extern unsigned long reclaim_pages_from_list (struct list_head *page_list); +/* * The anon_vma heads a list of private "related" vmas, to scan if * an anonymous page pointing to this anon_vma needs to be unmapped:
mm/vmscan.c +40 -0
@@ -1212,6 +1212,13 @@ static unsigned long shrink_page_list(struct list_head *page_list,* appear not as the counts should be low */ list_add (&page->lru, &free_pages); +/* +* If pagelist are from multiple zones, we should decrease +* NR_ISOLATED_ANON + x on freed pages in here. +*/ +if (!zone) +dec_zone_page_state (page,NR_ISOLATED_ANON + +page_is_file_cache (page));continue ; cull_mlocked:
@@ -1280,6 +1287,39 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,return ret; } +unsigned long reclaim_pages_from_list (struct list_head *page_list) +{ +struct scan_control sc = { + .gfp_mask =GFP_KERNEL , + .priority =DEF_PRIORITY , + .may_writepage =1 , + .may_unmap =1 , + .may_swap =1 , + .force_reclaim =1 , + }; + +unsigned long nr_reclaimed, dummy1, dummy2, dummy3, dummy4, dummy5; +struct page *page; + +list_for_each_entry (page, page_list, lru) +ClearPageActive (page); + + nr_reclaimed =shrink_page_list (page_list, &sc, +TTU_UNMAP |TTU_IGNORE_ACCESS , + &dummy1, &dummy2, &dummy3, + &dummy4, &dummy5); + +while (!list_empty (page_list)) { + page =lru_to_page (page_list); +list_del (&page->lru); +dec_zone_page_state (page,NR_ISOLATED_ANON + +page_is_file_cache (page)); +putback_lru_page (page); + } + +return nr_reclaimed; +} +/* * Attempt to remove the specified page from its LRU. Only take this page * if it is of the appropriate PageActive status. Pages which are being
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>
Hi Minchan,
Quoted 34 lines · Minchan Kim
Hi all,
http://thread.gmane.org/gmane.linux.kernel/1480728
I sent per-process reclaim patchset three years ago. Then, last feedback from akpm was that he want to know real usecase scenario.
Since then, I got question from several embedded people of various company "why it's not merged into mainline" and heard they have used the feature as in-house patch and recenlty, I noticed android from Qualcomm started to use it.
Of course, our product have used it and released it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------vanilla | 85 | 171 perproc reclaim | 184 | 72"
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
Quoted 7 lines
As perproc reclaim way with new management policy, we could reduce cold launching a
lot(i.e., 171-72)so that it reduces app startup a lot.Another useful function from this feature is to make swapout easily which is useful for testing swapout stress and workloads.
Thanks Minchan.
Yes, this is useful interface when there are memory pressure and let the userspace(Android) to pick process for reclaim. We also take there series into our platform.
But I have a question on the reduce app startup time. Can you also share your theory(management policy) on how can the app reduce it's startup time?
Quoted 14 lines
Thanks.
Cc Redmond <[email protected]>Cc ZhaoJunmin Zhao(Junmin) <[email protected]>Cc Vinayak Menon <[email protected]>Cc Juneho Choi <[email protected]>Cc Sangwoo Park <[email protected]>Cc Chan Gyun Jeong <[email protected]>Minchan Kim (3):
mm: vmscan: refactoringforce_reclaim
mm: vmscan:shrink_page_listwith multiple zones
mm: per-process reclaim
Quoted 8 lines
Documentation/filesystems/proc.txt | 15 ++++ fs/proc/base.c | 1 + fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 149 +++++++++++++++++++++++++++++++++++++ include/linux/rmap.h | 4 + mm/vmscan.c | 85 ++++++++++++++++----- 6 files changed, 235 insertions(+), 20 deletions(-)
--
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>
a?? 2016/6/13 19:50, Chen Feng a??e??:
Quoted 44 lines
Hi Minchan,
Quoted 34 lines · Minchan Kim
Hi all,
http://thread.gmane.org/gmane.linux.kernel/1480728
I sent per-process reclaim patchset three years ago. Then, last feedback from akpm was that he want to know real usecase scenario.
Since then, I got question from several embedded people of various company "why it's not merged into mainline" and heard they have used the feature as in-house patch and recenlty, I noticed android from Qualcomm started to use it.
Of course, our product have used it and released it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------vanilla | 85 | 171 perproc reclaim | 184 | 72"
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
Quoted 7 lines
As perproc reclaim way with new management policy, we could reduce cold launching a
lot(i.e., 171-72)so that it reduces app startup a lot.Another useful function from this feature is to make swapout easily which is useful for testing swapout stress and workloads.
Quoted 10 lines
Thanks Minchan.
Yes, this is useful interface when there are memory pressure and let the userspace(Android) to pick process for reclaim. We also take there series into our platform.
But I have a question on the reduce app startup time. Can you also share your theory(management policy) on how can the app reduce it's startup time?
Quoted 1 line
Thanks.
Yes, In Huawei device, we use the interface now! Now according to procsss LRU state in ActivityManagerService, we can reclaim some process in proactive way.
Quoted 23 lines
Quoted 13 lines
Cc Redmond <[email protected]>Cc ZhaoJunmin Zhao(Junmin) <[email protected]>Cc Vinayak Menon <[email protected]>Cc Juneho Choi <[email protected]>Cc Sangwoo Park <[email protected]>Cc Chan Gyun Jeong <[email protected]>Minchan Kim (3):
mm: vmscan: refactoringforce_reclaim
mm: vmscan:shrink_page_listwith multiple zones
mm: per-process reclaimQuoted 8 lines
Documentation/filesystems/proc.txt | 15 ++++ fs/proc/base.c | 1 + fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 149 +++++++++++++++++++++++++++++++++++++ include/linux/rmap.h | 4 + mm/vmscan.c | 85 ++++++++++++++++----- 6 files changed, 235 insertions(+), 20 deletions(-)
Quoted 2 lines
.
--
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>
Quoted 30 lines · Minchan Kim
Hi all,
http://thread.gmane.org/gmane.linux.kernel/1480728
I sent per-process reclaim patchset three years ago. Then, last feedback from akpm was that he want to know real usecase scenario.
Since then, I got question from several embedded people of various company "why it's not merged into mainline" and heard they have used the feature as in-house patch and recenlty, I noticed android from Qualcomm started to use it.
Of course, our product have used it and released it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------vanilla | 85 | 171 perproc reclaim | 184 | 72"
Quoted 8 lines
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
As perproc reclaim way with new management policy, we could reduce cold launching a
lot(i.e., 171-72)so that it reduces app startup a lot.
Thanks Minchan for bringing this up. When we had tried the earlier patchset in its original form,
the resume of the app that was reclaimed, was taking a lot of time. But from the data shown above it looks to be improving the resume time. Is that the resume time of "other" apps which were able to retain their working set because of the more efficient swapping of low priority apps with per process reclaim ?
Because of the higher resume time we had to modify the logic a bit and device a way to pick a "set" of low priority (oom_score_adj) tasks and reclaim certain number of pages (only anon) from each of them (the number of pages reclaimed from each task being proportional to task size). This deviates from the original intention of the patch to rescue a particular app of interest, but still using the hints on working set provided by userspace and avoiding high resume stalls. The increased swapping was helping in maintaining a better memory state and lesser page cache reclaim, resulting in better app resume time, and lesser task kills.
So would it be better if a userspace knob is provided to tell the kernel, the max number of pages to be reclaimed from a task ? This way userspace can make calculations depending on priority, task size etc and reclaim the required number of pages from each task, and thus avoid the resume stall because of reclaiming an entire task.
And also, would it be possible to implement the same using per task memcg by setting the limits and swappiness in such a way that it results inthe same thing that per process reclaim does ?
Thanks,
Vinayak
--
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>
Johannes Weiner
maintainerRe: [PATCH v1 3/3] mm: per-process reclaim
In reply to Minchan KimHi Minchan,
Quoted 8 lines · Minchan Kim
These day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
Cgroups are our canonical way to control system resources on a per process or group-of-processes level. I don't like the idea of adding ad-hoc interfaces for single-use cases like this.
For this particular case, you can already stick each app into its own cgroup and use memory.force_empty to target-reclaim them.
Or better yet, set the soft limits / memory.low to guide physical memory pressure, once it actually occurs, toward the least-important apps? We usually prefer doing work on-demand rather than proactively.
The one-cgroup-per-app model would give Android much more control and would also remove a *lot* of overhead during task switches, see this:
https://lkml.org/lkml/2014/12/19/358
--
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 v1 3/3] mm: per-process reclaim
In reply to Minchan KimQuoted 9 lines · Minchan Kim
These day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
Could it make sense to invoke this automatically,
perhaps from the Android low memory killer code?
Signature · 1 line
All Rights Reversed.
Re: [PATCH v1 3/3] mm: per-process reclaim
In reply to Johannes WeinerHi Johannes,
Quoted 19 lines · Johannes Weiner
Hi Minchan,
Quoted 8 lines · Minchan Kim
These day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
Cgroups are our canonical way to control system resources on a per process or group-of-processes level. I don't like the idea of adding ad-hoc interfaces for single-use cases like this.
For this particular case, you can already stick each app into its own cgroup and use memory.force_empty to target-reclaim them.
Quoted 7 lines
Or better yet, set the soft limits / memory.low to guide physical memory pressure, once it actually occurs, toward the least-important apps? We usually prefer doing work on-demand rather than proactively.
The one-cgroup-per-app model would give Android much more control and would also remove a *lot* of overhead during task switches, see this:
https://lkml.org/lkml/2014/12/19/358
I didn't notice that. Thanks for the pointing. I read the thread you pointed out and read memcg code.
Firstly, I thought one-cgroup-per-app model is abuse of memcg but now I feel your suggestion does make sense that it's right direction for control memory from the userspace. Just a concern is that not sure how hard we can map memory management model from global memory pressure to per-app pressure model smoothly.
A question is it seems cgroup2 doesn't have per-cgroup swappiness. Why?
I think we need it in one-cgroup-per-app model.
--
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>
Hi Chen,
Quoted 44 lines · Chen Feng
Hi Minchan,
Quoted 34 lines · Minchan Kim
Hi all,
http://thread.gmane.org/gmane.linux.kernel/1480728
I sent per-process reclaim patchset three years ago. Then, last feedback from akpm was that he want to know real usecase scenario.
Since then, I got question from several embedded people of various company "why it's not merged into mainline" and heard they have used the feature as in-house patch and recenlty, I noticed android from Qualcomm started to use it.
Of course, our product have used it and released it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------vanilla | 85 | 171 perproc reclaim | 184 | 72"
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
Quoted 7 lines
As perproc reclaim way with new management policy, we could reduce cold launching a
lot(i.e., 171-72)so that it reduces app startup a lot.Another useful function from this feature is to make swapout easily which is useful for testing swapout stress and workloads.
Quoted 7 lines
Thanks Minchan.
Yes, this is useful interface when there are memory pressure and let the userspace(Android) to pick process for reclaim. We also take there series into our platform.
But I have a question on the reduce app startup time. Can you also share your theory(management policy) on how can the app reduce it's startup time?
What I meant about start-up time is as follows,
If a app is killed, it should launch from start so if it was the game app, it should load lots of resource file which takes a long time. However, if the game was not killed, we can enjoy the game without cold start so it is very fast startup.
Sorry for confusing.
--
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>
Quoted 35 lines · Vinayak Menon
Quoted 34 lines · Minchan Kim
Hi all,
http://thread.gmane.org/gmane.linux.kernel/1480728
I sent per-process reclaim patchset three years ago. Then, last feedback from akpm was that he want to know real usecase scenario.
Since then, I got question from several embedded people of various company "why it's not merged into mainline" and heard they have used the feature as in-house patch and recenlty, I noticed android from Qualcomm started to use it.
Of course, our product have used it and released it in real procuct.
Quote from Sangwoo Park <[email protected]> Thanks for the data, Sangwoo!
"
- Test scenaro
- platform: android
- target: MSM8952, 2G DDR, 16G eMMC
- scenario
retry app launch and Back Home with 16 apps and 16 turns (total app launch count is 256)
- result:
resume count | cold launching count
-----------------------------------------------------------------vanilla | 85 | 171 perproc reclaim | 184 | 72"
Higher resume count is better because cold launching needs loading lots of resource data which takes above 15 ~ 20 seconds for some games while successful resume just takes 1~5 second.
Quoted 8 lines
Quoted 4 lines
As perproc reclaim way with new management policy, we could reduce cold launching a
lot(i.e., 171-72)so that it reduces app startup a lot.Thanks Minchan for bringing this up. When we had tried the earlier patchset in its original form, the resume of the app that was reclaimed, was taking a lot of time. But from the data shown above it looks to be improving the resume time. Is that the resume time of "other" apps which were able to retain their working set because of the more efficient swapping of low priority apps with per process reclaim ?
Sorry for confusing. I meant the app should start from the scratch if it was killed, which might need load a hundread megabytes while resume needs to load just workingset memory which would be smaller.
Quoted 6 lines
Because of the higher resume time we had to modify the logic a bit and device a way to pick a "set" of low priority (
oom_score_adj) tasks and reclaim certain number of pages (only anon) from each of them (the number of pages reclaimed from each task being proportional to task size). This deviates from the original intention of the patch to rescue a particular app of interest, but still using the hints on working set provided by userspace and avoiding high resume stalls. The increased swapping was helping in maintaining a better memory state and lesser page cache reclaim, resulting in better app resume time, and lesser task kills.
Fair enough.
Quoted 7 lines
So would it be better if a userspace knob is provided to tell the kernel, the max number of pages to be reclaimed from a task ? This way userspace can make calculations depending on priority, task size etc and reclaim the required number of pages from each task, and thus avoid the resume stall because of reclaiming an entire task.
And also, would it be possible to implement the same using per task memcg by setting the limits and swappiness in such a way that it results inthe same thing that per process reclaim does ?
Yeb, I read Johannes's thread which suggests one-cgroup-per-app model. It does make sense to me. It is worth to try although I guess it's not easy to control memory usage on demand, not proactively.
If we can do, maybe we don't need per-process reclaim policy which is rather coarse-grained model of reclaim POV.
However, a concern with one-cgroup-per-app model is LRU list size of a cgroup is much smaller so how LRU aging works well and LRU churing(e.g., compaction) effect would be severe than old.
I guess codeaurora tried memcg model for android.
Could you share if you know something?
Thanks.
Quoted 3 lines
Thanks,
Vinayak
--
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 v1 3/3] mm: per-process reclaim
In reply to Rik van RielQuoted 6 lines · Rik van Riel
Quoted 5 lines · Minchan Kim
These day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
Quoted 7 lines
Quoted 4 lines
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
Could it make sense to invoke this automatically,
perhaps from the Android low memory killer code?
It's doable. In fact, It was first internal implementation of our product. However, I wanted to use it on platforms which don't have lowmemory killer. :)
--
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>
Quoted 9 lines · Minchan Kim
Yeb, I read Johannes's thread which suggests one-cgroup-per-app model. It does make sense to me. It is worth to try although I guess it's not easy to control memory usage on demand, not proactively.
If we can do, maybe we don't need per-process reclaim policy which is rather coarse-grained model of reclaim POV.
However, a concern with one-cgroup-per-app model is LRU list size of a cgroup is much smaller so how LRU aging works well and LRUchuring(e.g., compaction)effect would be severe than old.
And I was thinking what would vmpressure mean and how to use it when cgroup is per task.
Quoted 4 lines
I guess codeaurora tried memcg model for android.
Could you share if you know something?
We tried, but had issues with charge migration and then Johannes suggested per task cgroup. But that's not tried yet.
Thanks
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
reviewerRe: [PATCH v1 3/3] mm: per-process reclaim
In reply to Minchan KimOn Wed 15-06-16 09:40:27, Minchan Kim wrote:
[...]
Quoted 2 lines
A question is it seems cgroup2 doesn't have per-cgroup swappiness. Why?
There was no strong use case for it AFAICT.
Quoted 1 line
I think we need it in one-cgroup-per-app model.
I wouldn't be opposed if it is really needed.
Signature · 8 lines
Michal Hocko SUSE Labs -- 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>
Johannes Weiner
maintainerRe: [PATCH v1 3/3] mm: per-process reclaim
In reply to Minchan KimQuoted 4 lines · Minchan Kim
A question is it seems cgroup2 doesn't have per-cgroup swappiness. Why?
I think we need it in one-cgroup-per-app model.
Can you explain why you think that?
As we have talked about this recently in the LRU balancing thread, swappiness is the cost factor between file IO and swapping, so the only situation I can imagine you'd need a memcg swappiness setting is when you have different cgroups use different storage devices that do not have comparable speeds.
So I'm not sure I understand the relationship to an app-group model.
--
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 v1 3/3] mm: per-process reclaim
Hi Hannes,
Quoted 8 lines · Johannes Weiner
Quoted 4 lines · Minchan Kim
A question is it seems cgroup2 doesn't have per-cgroup swappiness. Why?
I think we need it in one-cgroup-per-app model.
Can you explain why you think that?
Quoted 7 lines
As we have talked about this recently in the LRU balancing thread, swappiness is the cost factor between file IO and swapping, so the only situation I can imagine you'd need a memcg swappiness setting is when you have different cgroups use different storage devices that do not have comparable speeds.
So I'm not sure I understand the relationship to an app-group model.
Sorry for lacking the inforamtion. I should have written more clear. In fact, what we need is *per-memcg-swap-device*.
What I want is to avoid kill background application although memory is overflow because cold launcing of app takes a very long time compared to resume(ie, just switching). I also want to keep a mount of free pages in the memory so that new application startup cannot be stuck by reclaim activities.
To get free memory, I want to reclaim less important app rather than killing. In this time, we can support two swap devices.
A one is zram, other is slow storage but much bigger than zram size. Then, we can use storage swap to reclaim pages for not-important app while we can use zram swap for for important app(e.g., forground app, system services, daemon and so on).
IOW, we want to support mutiple swap device with one-cgroup-per-app and the storage speed is totally different.
--
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 v1 3/3] mm: per-process reclaim
In reply to Johannes WeinerQuoted 19 lines · Johannes Weiner
Hi Minchan,
Quoted 8 lines · Minchan Kim
These day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
Cgroups are our canonical way to control system resources on a per process or group-of-processes level. I don't like the idea of adding ad-hoc interfaces for single-use cases like this.
For this particular case, you can already stick each app into its own cgroup and use memory.force_empty to target-reclaim them.
Quoted 7 lines
Or better yet, set the soft limits / memory.low to guide physical memory pressure, once it actually occurs, toward the least-important apps? We usually prefer doing work on-demand rather than proactively.
The one-cgroup-per-app model would give Android much more control and would also remove a *lot* of overhead during task switches, see this:
https://lkml.org/lkml/2014/12/19/358
Yes, I'd agree. cgroups can group many tasks, but the group size can be 1 as well. Could you try the same test with the recommended approach and see if it works as desired?
Balbir Singh
Re: [PATCH v1 3/3] mm: per-process reclaim
Quoted 24 lines · Balbir Singh
Quoted 22 lines · Johannes Weiner
Hi Minchan,
Quoted 8 lines · Minchan Kim
These day, there are many platforms available in the embedded market and sometime, they has more hints about workingset than kernel so they want to involve memory management more heavily like android's lowmemory killer and ashmem or user-daemon with lowmemory notifier.
This patch adds add new method for userspace to manage memory efficiently via knob "/proc/<pid>/reclaim" so platform can reclaim any process anytime.
Cgroups are our canonical way to control system resources on a per process or group-of-processes level. I don't like the idea of adding ad-hoc interfaces for single-use cases like this.
For this particular case, you can already stick each app into its own cgroup and use memory.force_empty to target-reclaim them.
Or better yet, set the soft limits / memory.low to guide physical memory pressure, once it actually occurs, toward the least-important apps? We usually prefer doing work on-demand rather than proactively.
Quoted 7 lines
Quoted 3 lines
The one-cgroup-per-app model would give Android much more control and would also remove a *lot* of overhead during task switches, see this:
https://lkml.org/lkml/2014/12/19/358Yes, I'd agree. cgroups can group many tasks, but the group size can be 1 as well. Could you try the same test with the recommended approach and see if it works as desired?
With cgroup v2, IIUC there can be only a single hierarchy where all controllers exist, and a process can be part of only one cgroup. If that is true, with per task cgroup, a task can be present only in its own cgroup. That being the case would it be feasible to have other parallel controllers like CPU which would not be able to work efficiently with per task cgroup ?
--
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>