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

Configure Feed

Select the types of activity you want to include in your feed.

mm/madvise: split out populate behavior check logic

madvise_do_behavior() has a long open-coded 'behavior' check for
MADV_POPULATE_{READ,WRITE}. It adds multiple layers[1] and make the code
arguably take longer time to read. Like is_memory_failure(), split out
the check to a separate function. This is not technically removing the
additional layer but discourage further extending the switch-case. Also
it makes madvise_do_behavior() code shorter and therefore easier to read.

[1] https://lore.kernel.org/bd6d0bf1-c79e-46bd-a810-9791efb9ad73@lucifer.local

Link: https://lkml.kernel.org/r/20250312164750.59215-3-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Liam R. Howlett <howlett@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
f4a578d3 9ecd2f83

+13 -7
+13 -7
mm/madvise.c
··· 1640 1640 return true; 1641 1641 } 1642 1642 1643 + static bool is_madvise_populate(int behavior) 1644 + { 1645 + switch (behavior) { 1646 + case MADV_POPULATE_READ: 1647 + case MADV_POPULATE_WRITE: 1648 + return true; 1649 + default: 1650 + return false; 1651 + } 1652 + } 1653 + 1643 1654 static int madvise_do_behavior(struct mm_struct *mm, 1644 1655 unsigned long start, size_t len_in, size_t len, int behavior) 1645 1656 { ··· 1664 1653 end = start + len; 1665 1654 1666 1655 blk_start_plug(&plug); 1667 - switch (behavior) { 1668 - case MADV_POPULATE_READ: 1669 - case MADV_POPULATE_WRITE: 1656 + if (is_madvise_populate(behavior)) 1670 1657 error = madvise_populate(mm, start, end, behavior); 1671 - break; 1672 - default: 1658 + else 1673 1659 error = madvise_walk_vmas(mm, start, end, behavior, 1674 1660 madvise_vma_behavior); 1675 - break; 1676 - } 1677 1661 blk_finish_plug(&plug); 1678 1662 return error; 1679 1663 }