Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

android: binder: Add shrinker tracepoints

Add tracepoints in binder transaction allocator to
record lru hits and alloc/free page.

Signed-off-by: Sherry Yang <sherryy@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sherry Yang and committed by
Greg Kroah-Hartman
e41e164c f2517eb7

+80 -2
+25 -2
drivers/android/binder_alloc.c
··· 237 237 for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) { 238 238 int ret; 239 239 bool on_lru; 240 + size_t index; 240 241 241 - page = &alloc->pages[(page_addr - alloc->buffer) / PAGE_SIZE]; 242 + index = (page_addr - alloc->buffer) / PAGE_SIZE; 243 + page = &alloc->pages[index]; 242 244 243 245 if (page->page_ptr) { 246 + trace_binder_alloc_lru_start(alloc, index); 247 + 244 248 on_lru = list_lru_del(&binder_alloc_lru, &page->lru); 245 249 WARN_ON(!on_lru); 250 + 251 + trace_binder_alloc_lru_end(alloc, index); 246 252 continue; 247 253 } 248 254 249 255 if (WARN_ON(!vma)) 250 256 goto err_page_ptr_cleared; 251 257 258 + trace_binder_alloc_page_start(alloc, index); 252 259 page->page_ptr = alloc_page(GFP_KERNEL | 253 260 __GFP_HIGHMEM | 254 261 __GFP_ZERO); ··· 285 278 alloc->pid, user_page_addr); 286 279 goto err_vm_insert_page_failed; 287 280 } 281 + 282 + trace_binder_alloc_page_end(alloc, index); 288 283 /* vm_insert_page does not seem to increment the refcount */ 289 284 } 290 285 if (mm) { ··· 299 290 for (page_addr = end - PAGE_SIZE; page_addr >= start; 300 291 page_addr -= PAGE_SIZE) { 301 292 bool ret; 293 + size_t index; 302 294 303 - page = &alloc->pages[(page_addr - alloc->buffer) / PAGE_SIZE]; 295 + index = (page_addr - alloc->buffer) / PAGE_SIZE; 296 + page = &alloc->pages[index]; 297 + 298 + trace_binder_free_lru_start(alloc, index); 304 299 305 300 ret = list_lru_add(&binder_alloc_lru, &page->lru); 306 301 WARN_ON(!ret); 302 + 303 + trace_binder_free_lru_end(alloc, index); 307 304 continue; 308 305 309 306 err_vm_insert_page_failed: ··· 903 888 if (!down_write_trylock(&mm->mmap_sem)) 904 889 goto err_down_write_mmap_sem_failed; 905 890 891 + trace_binder_unmap_user_start(alloc, index); 892 + 906 893 zap_page_range(alloc->vma, 907 894 page_addr + alloc->user_buffer_offset, 908 895 PAGE_SIZE); 896 + 897 + trace_binder_unmap_user_end(alloc, index); 909 898 910 899 up_write(&mm->mmap_sem); 911 900 mmput(mm); 912 901 } 913 902 903 + trace_binder_unmap_kernel_start(alloc, index); 904 + 914 905 unmap_kernel_range(page_addr, PAGE_SIZE); 915 906 __free_page(page->page_ptr); 916 907 page->page_ptr = NULL; 908 + 909 + trace_binder_unmap_kernel_end(alloc, index); 917 910 918 911 list_lru_isolate(lru, item); 919 912
+55
drivers/android/binder_trace.h
··· 291 291 __entry->offset, __entry->size) 292 292 ); 293 293 294 + DECLARE_EVENT_CLASS(binder_lru_page_class, 295 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 296 + TP_ARGS(alloc, page_index), 297 + TP_STRUCT__entry( 298 + __field(int, proc) 299 + __field(size_t, page_index) 300 + ), 301 + TP_fast_assign( 302 + __entry->proc = alloc->pid; 303 + __entry->page_index = page_index; 304 + ), 305 + TP_printk("proc=%d page_index=%zu", 306 + __entry->proc, __entry->page_index) 307 + ); 308 + 309 + DEFINE_EVENT(binder_lru_page_class, binder_alloc_lru_start, 310 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 311 + TP_ARGS(alloc, page_index)); 312 + 313 + DEFINE_EVENT(binder_lru_page_class, binder_alloc_lru_end, 314 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 315 + TP_ARGS(alloc, page_index)); 316 + 317 + DEFINE_EVENT(binder_lru_page_class, binder_free_lru_start, 318 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 319 + TP_ARGS(alloc, page_index)); 320 + 321 + DEFINE_EVENT(binder_lru_page_class, binder_free_lru_end, 322 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 323 + TP_ARGS(alloc, page_index)); 324 + 325 + DEFINE_EVENT(binder_lru_page_class, binder_alloc_page_start, 326 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 327 + TP_ARGS(alloc, page_index)); 328 + 329 + DEFINE_EVENT(binder_lru_page_class, binder_alloc_page_end, 330 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 331 + TP_ARGS(alloc, page_index)); 332 + 333 + DEFINE_EVENT(binder_lru_page_class, binder_unmap_user_start, 334 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 335 + TP_ARGS(alloc, page_index)); 336 + 337 + DEFINE_EVENT(binder_lru_page_class, binder_unmap_user_end, 338 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 339 + TP_ARGS(alloc, page_index)); 340 + 341 + DEFINE_EVENT(binder_lru_page_class, binder_unmap_kernel_start, 342 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 343 + TP_ARGS(alloc, page_index)); 344 + 345 + DEFINE_EVENT(binder_lru_page_class, binder_unmap_kernel_end, 346 + TP_PROTO(const struct binder_alloc *alloc, size_t page_index), 347 + TP_ARGS(alloc, page_index)); 348 + 294 349 TRACE_EVENT(binder_command, 295 350 TP_PROTO(uint32_t cmd), 296 351 TP_ARGS(cmd),