Commit b77d5b1
mm: slab: optimize memcg_slab_free_hook()
Most callers of memcg_slab_free_hook() already know the slab, which could
be passed to memcg_slab_free_hook() directly to reduce the overhead of an
another call of virt_to_slab(). For bulk freeing of objects, the call of
slab_objcgs() in the loop in memcg_slab_free_hook() is redundant as well.
Rework memcg_slab_free_hook() and build_detached_freelist() to reduce
those unnecessary overhead and make memcg_slab_free_hook() can handle bulk
freeing in slab_free().
Move the calling site of memcg_slab_free_hook() from do_slab_free() to
slab_free() for slub to make the code clearer since the logic is weird
(e.g. the caller need to judge whether it needs to call
memcg_slab_free_hook()). It is easy to make mistakes like missing calling
of memcg_slab_free_hook() like fixes of:
commit d1b2cf6 ("mm: memcg/slab: uncharge during kmem_cache_free_bulk()")
commit ae085d7 ("mm: kfence: fix missing objcg housekeeping for SLAB")
This optimization is mainly for bulk objects freeing. The following numbers
is shown for 16-object freeing.
before after
kmem_cache_free_bulk: ~430 ns ~400 ns
The overhead is reduced by about 7% for 16-object freeing.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Link: https://lore.kernel.org/r/20220429123044.37885-1-songmuchun@bytedance.com
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>1 parent b347aa7 commit b77d5b1
3 files changed
Lines changed: 32 additions & 68 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3406 | 3406 | | |
3407 | 3407 | | |
3408 | 3408 | | |
| 3409 | + | |
| 3410 | + | |
3409 | 3411 | | |
3410 | 3412 | | |
3411 | | - | |
3412 | 3413 | | |
3413 | 3414 | | |
3414 | 3415 | | |
| |||
3441 | 3442 | | |
3442 | 3443 | | |
3443 | 3444 | | |
3444 | | - | |
3445 | 3445 | | |
3446 | 3446 | | |
3447 | 3447 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
550 | | - | |
| 550 | + | |
551 | 551 | | |
552 | 552 | | |
553 | | - | |
554 | 553 | | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | 554 | | |
559 | 555 | | |
560 | 556 | | |
561 | 557 | | |
562 | 558 | | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
575 | 562 | | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
580 | 566 | | |
581 | 567 | | |
582 | 568 | | |
| |||
628 | 614 | | |
629 | 615 | | |
630 | 616 | | |
631 | | - | |
| 617 | + | |
632 | 618 | | |
633 | 619 | | |
634 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3464 | 3464 | | |
3465 | 3465 | | |
3466 | 3466 | | |
3467 | | - | |
3468 | | - | |
3469 | | - | |
3470 | 3467 | | |
3471 | 3468 | | |
3472 | 3469 | | |
| |||
3526 | 3523 | | |
3527 | 3524 | | |
3528 | 3525 | | |
3529 | | - | |
| 3526 | + | |
3530 | 3527 | | |
3531 | 3528 | | |
| 3529 | + | |
3532 | 3530 | | |
3533 | 3531 | | |
3534 | 3532 | | |
| |||
3550 | 3548 | | |
3551 | 3549 | | |
3552 | 3550 | | |
3553 | | - | |
| 3551 | + | |
3554 | 3552 | | |
3555 | 3553 | | |
3556 | 3554 | | |
| |||
3591 | 3589 | | |
3592 | 3590 | | |
3593 | 3591 | | |
3594 | | - | |
3595 | 3592 | | |
3596 | 3593 | | |
3597 | 3594 | | |
3598 | | - | |
3599 | | - | |
3600 | | - | |
3601 | | - | |
3602 | | - | |
3603 | | - | |
3604 | | - | |
3605 | | - | |
3606 | | - | |
3607 | | - | |
3608 | | - | |
3609 | | - | |
| 3595 | + | |
3610 | 3596 | | |
| 3597 | + | |
3611 | 3598 | | |
3612 | 3599 | | |
3613 | 3600 | | |
3614 | 3601 | | |
3615 | 3602 | | |
3616 | | - | |
| 3603 | + | |
3617 | 3604 | | |
3618 | 3605 | | |
3619 | 3606 | | |
3620 | | - | |
3621 | | - | |
| 3607 | + | |
| 3608 | + | |
3622 | 3609 | | |
3623 | | - | |
| 3610 | + | |
3624 | 3611 | | |
3625 | 3612 | | |
3626 | 3613 | | |
3627 | | - | |
3628 | | - | |
3629 | | - | |
3630 | | - | |
3631 | | - | |
3632 | | - | |
3633 | | - | |
3634 | 3614 | | |
3635 | | - | |
3636 | | - | |
3637 | 3615 | | |
3638 | 3616 | | |
3639 | | - | |
3640 | 3617 | | |
3641 | 3618 | | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
3642 | 3625 | | |
3643 | 3626 | | |
3644 | | - | |
3645 | | - | |
3646 | | - | |
3647 | 3627 | | |
3648 | 3628 | | |
3649 | 3629 | | |
3650 | 3630 | | |
3651 | 3631 | | |
3652 | 3632 | | |
3653 | | - | |
3654 | | - | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
3655 | 3636 | | |
3656 | 3637 | | |
3657 | 3638 | | |
3658 | 3639 | | |
3659 | 3640 | | |
3660 | 3641 | | |
3661 | | - | |
3662 | | - | |
3663 | | - | |
3664 | 3642 | | |
3665 | 3643 | | |
3666 | | - | |
| 3644 | + | |
3667 | 3645 | | |
3668 | 3646 | | |
3669 | 3647 | | |
| |||
3672 | 3650 | | |
3673 | 3651 | | |
3674 | 3652 | | |
3675 | | - | |
3676 | 3653 | | |
3677 | 3654 | | |
3678 | 3655 | | |
3679 | 3656 | | |
3680 | 3657 | | |
3681 | 3658 | | |
3682 | 3659 | | |
3683 | | - | |
| 3660 | + | |
| 3661 | + | |
3684 | 3662 | | |
3685 | 3663 | | |
3686 | 3664 | | |
| |||
4581 | 4559 | | |
4582 | 4560 | | |
4583 | 4561 | | |
4584 | | - | |
| 4562 | + | |
4585 | 4563 | | |
4586 | 4564 | | |
4587 | 4565 | | |
| |||
0 commit comments