Skip to content

Commit fbe23b8

Browse files
YangYang866winzkh
authored andcommitted
ANDROID: mm: add vendor hooks to adjust memory reclamation
Add vendor hooks to adjust page reclamation operations based on the running task and kernel memory pressure. Determine if file pages should be skipped in response to file faults and memory pressure. Bug: 448016266 Change-Id: I39c223876ef82af443407234e35f39bcbbeb17cb Signed-off-by: Yang Yang <[email protected]> (cherry picked from commit b0807745d4495c1614bcdbc4e5394d7bcabbf698)
1 parent a655345 commit fbe23b8

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

drivers/android/vendor_hooks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_alloc_pages_direct_reclaim_enter);
401401
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_alloc_pages_direct_reclaim_exit);
402402
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_alloc_pages_may_oom_exit);
403403
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_vmscan_kswapd_done);
404+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_shrink_folio_list);
405+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_inode_lru_isolate);
406+
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_invalidate_mapping_pagevec);
404407
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_compaction_begin);
405408
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_compaction_end);
406409
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_kcompactd_cpu_online);

fs/inode.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <trace/events/writeback.h>
2424
#include "internal.h"
2525

26+
#undef CREATE_TRACE_POINTS
27+
#include <trace/hooks/vmscan.h>
28+
2629
/*
2730
* Inode locking rules:
2831
*
@@ -869,6 +872,7 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
869872
{
870873
struct list_head *freeable = arg;
871874
struct inode *inode = container_of(item, struct inode, i_lru);
875+
bool skip = false;
872876

873877
/*
874878
* We are inverting the lru lock/inode->i_lock here, so use a
@@ -877,6 +881,12 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
877881
if (!spin_trylock(&inode->i_lock))
878882
return LRU_SKIP;
879883

884+
trace_android_vh_inode_lru_isolate(inode, &skip);
885+
if (skip) {
886+
spin_unlock(&inode->i_lock);
887+
return LRU_SKIP;
888+
}
889+
880890
/*
881891
* Inodes can get referenced, redirtied, or repopulated while
882892
* they're already on the LRU, and this can make them

include/trace/hooks/vmscan.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ DECLARE_HOOK(android_vh_vmscan_kswapd_done,
5757
TP_PROTO(int node_id, unsigned int highest_zoneidx, unsigned int alloc_order,
5858
unsigned int reclaim_order),
5959
TP_ARGS(node_id, highest_zoneidx, alloc_order, reclaim_order));
60+
DECLARE_HOOK(android_vh_shrink_folio_list,
61+
TP_PROTO(struct folio *folio, bool dirty, bool writeback,
62+
bool *activate, bool *keep),
63+
TP_ARGS(folio, dirty, writeback, activate, keep));
64+
DECLARE_HOOK(android_vh_inode_lru_isolate,
65+
TP_PROTO(struct inode *inode, bool *skip),
66+
TP_ARGS(inode, skip));
67+
DECLARE_HOOK(android_vh_invalidate_mapping_pagevec,
68+
TP_PROTO(struct address_space *mapping, bool *skip),
69+
TP_ARGS(mapping, skip));
70+
DECLARE_RESTRICTED_HOOK(android_rvh_vmscan_kswapd_wake,
71+
TP_PROTO(int node_id, unsigned int highest_zoneidx, unsigned int alloc_order),
72+
TP_ARGS(node_id, highest_zoneidx, alloc_order), 1);
73+
DECLARE_RESTRICTED_HOOK(android_rvh_vmscan_kswapd_done,
74+
TP_PROTO(int node_id, unsigned int highest_zoneidx, unsigned int alloc_order,
75+
unsigned int reclaim_order),
76+
TP_ARGS(node_id, highest_zoneidx, alloc_order, reclaim_order), 1);
6077
DECLARE_HOOK(android_vh_handle_trylock_failed_folio,
6178
TP_PROTO(struct list_head *folio_list),
6279
TP_ARGS(folio_list));

mm/truncate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <linux/rmap.h>
2525
#include "internal.h"
2626

27+
#undef CREATE_TRACE_POINTS
28+
#include <trace/hooks/vmscan.h>
29+
2730
/*
2831
* Regular page slots are stabilized by the page lock even without the tree
2932
* itself locked. These unlocked entries need verification under the tree
@@ -516,6 +519,11 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping,
516519
unsigned long ret;
517520
unsigned long count = 0;
518521
int i;
522+
bool skip = false;
523+
524+
trace_android_vh_invalidate_mapping_pagevec(mapping, &skip);
525+
if (skip)
526+
return count;
519527

520528
folio_batch_init(&fbatch);
521529
while (find_lock_entries(mapping, index, end, &fbatch, indices)) {

mm/vmscan.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
17101710
enum folio_references references = FOLIOREF_RECLAIM;
17111711
bool dirty, writeback;
17121712
unsigned int nr_pages;
1713+
bool activate = false;
1714+
bool keep = false;
17131715

17141716
cond_resched();
17151717

@@ -1762,6 +1764,15 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
17621764
* folios if the tail of the LRU is all dirty unqueued folios.
17631765
*/
17641766
folio_check_dirty_writeback(folio, &dirty, &writeback);
1767+
1768+
trace_android_vh_shrink_folio_list(folio, dirty, writeback,
1769+
&activate, &keep);
1770+
if (activate)
1771+
goto activate_locked;
1772+
1773+
if (keep)
1774+
goto keep_locked;
1775+
17651776
if (dirty || writeback)
17661777
stat->nr_dirty += nr_pages;
17671778

0 commit comments

Comments
 (0)