ANDROID: defer zeroing to allocation context in init_on_free

zeroing on free but defering the zeroing to allocation context
to avoid slow memory reclaiming

Bug: 383166773
Signed-off-by: Minchan Kim <minchan@google.com>
(cherry picked from https://android-review.googlesource.com/q/commit:7e1ae40ab7521834e2c3513931dbe8e816acf711)
Change-Id: I746f4fbc20df5cf394d7644ff2cd6f25916c9790
This commit is contained in:
Minchan Kim
2024-12-17 21:56:15 +00:00
committed by Todd Kjos
parent 2d8da7e086
commit 85fdf22a76
3 changed files with 27 additions and 6 deletions
+3
View File
@@ -381,6 +381,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_track_hash);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_adjust_kvmalloc_flags);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_exit_signal);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_process_madvise_bypass);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_free_pages_prepare_init);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_post_alloc_hook);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_new_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_madvise_pageout_return_error);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_process_madvise_return_error);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_madvise_pageout_bypass);
+9
View File
@@ -320,6 +320,15 @@ DECLARE_HOOK(android_vh_free_pages_ok_bypass,
TP_PROTO(struct page *page, unsigned int order,
int __bitwise flags, bool *skip_free_pages_ok),
TP_ARGS(page, order, flags, skip_free_pages_ok));
DECLARE_HOOK(android_vh_free_pages_prepare_init,
TP_PROTO(struct page *page, int nr_pages, bool *init),
TP_ARGS(page, nr_pages, init));
DECLARE_HOOK(android_vh_post_alloc_hook,
TP_PROTO(struct page *page, unsigned int order, bool *init),
TP_ARGS(page, order, init));
DECLARE_HOOK(android_vh_check_new_page,
TP_PROTO(unsigned long *flags),
TP_ARGS(flags));
DECLARE_HOOK(android_vh_split_large_folio_bypass,
TP_PROTO(bool *bypass),
TP_ARGS(bypass));
+15 -6
View File
@@ -1300,8 +1300,11 @@ __always_inline bool free_pages_prepare(struct page *page,
if (kasan_has_integrated_init())
init = false;
}
if (init)
kernel_init_pages(page, 1 << order);
if (init) {
trace_android_vh_free_pages_prepare_init(page, 1 << order, &init);
if (init)
kernel_init_pages(page, 1 << order);
}
/*
* arch_free_page() can make the page's contents inaccessible. s390
@@ -1630,8 +1633,11 @@ static void check_new_page_bad(struct page *page)
*/
static bool check_new_page(struct page *page)
{
if (likely(page_expected_state(page,
PAGE_FLAGS_CHECK_AT_PREP|__PG_HWPOISON)))
unsigned long check_flags = PAGE_FLAGS_CHECK_AT_PREP|__PG_HWPOISON;
trace_android_vh_check_new_page(&check_flags);
if (likely(page_expected_state(page, check_flags)))
return false;
check_new_page_bad(page);
@@ -1683,10 +1689,13 @@ static inline bool should_skip_init(gfp_t flags)
inline void post_alloc_hook(struct page *page, unsigned int order,
gfp_t gfp_flags)
{
int i;
bool zero_tags;
bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags) &&
!should_skip_init(gfp_flags);
bool zero_tags = init && (gfp_flags & __GFP_ZEROTAGS);
int i;
trace_android_vh_post_alloc_hook(page, order, &init);
zero_tags = init && (gfp_flags & __GFP_ZEROTAGS);
set_page_private(page, 0);
set_page_refcounted(page);