From 8c36f82adf8e8e42ee61bc33ce291ac4778e1f06 Mon Sep 17 00:00:00 2001 From: lvwenhuan Date: Fri, 15 Sep 2023 20:03:10 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks for adjusting alloc_flags the reason why we add a vendor hook adjusting alloc_flags: 1 the user only pass parameter size and gfp_flags once. if we mask the __GFP_RECLAIM, we can't distinguish high-order and low-order, they all will not rise reclaim behavior, it's wrong. 2 for __iommu_dma_alloc_pages, there is a loop to try to alloc pages from high-order to low-order fallback, and we add hook callsite to only change the high-order( > costly order) alloc behavior(which high probability will result more overhead than benifit). which allow low order alloc to do reclaim behavior still, otherwise may end up with alloc fail. 3 in android ION(drivers/dma-buf/heaps/system_heap.c ) there is same logic, high-order alloc will not do reclaim behavior. so this change and a vendor hook for adjusting alloc_flags, and add a callsite in __iommu_dma_alloc_pages to turn the reclaim behavior. Bug: 300857012 Change-Id: I30bd634d8ede1cc29c83d52bdd9276c8cf72ac1e Signed-off-by: lvwenhuan Signed-off-by: huzhanyuan --- drivers/android/vendor_hooks.c | 1 + drivers/iommu/dma-iommu.c | 1 + include/trace/hooks/iommu.h | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index ea43e294aa3e..964d510caa75 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -152,6 +152,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_alloc); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cma_alloc_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_isolate_freepages); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_oom_check_panic); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_adjust_alloc_flags); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_wait_for_work); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_oem_binder_struct); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_transaction_received); diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index a6e6068506c0..03ff114098f6 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -921,6 +921,7 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, order_size = 1U << order; if (order_mask > order_size) alloc_flags |= __GFP_NORETRY; + trace_android_vh_adjust_alloc_flags(order, &alloc_flags); page = alloc_pages_node(nid, alloc_flags, order); if (!page) continue; diff --git a/include/trace/hooks/iommu.h b/include/trace/hooks/iommu.h index d965a23c1c92..7afc06e450b9 100644 --- a/include/trace/hooks/iommu.h +++ b/include/trace/hooks/iommu.h @@ -23,6 +23,10 @@ DECLARE_HOOK(android_vh_iommu_iovad_free_iova, TP_PROTO(struct iova_domain *iovad, dma_addr_t iova, size_t size), TP_ARGS(iovad, iova, size)); +DECLARE_HOOK(android_vh_adjust_alloc_flags, + TP_PROTO(unsigned int order, gfp_t *alloc_flags), + TP_ARGS(order, alloc_flags)); + #endif /* _TRACE_HOOK_IOMMU_H */ /* This part must be outside protection */