Commit cab143a
mm/mglru: restructure the reclaim loop
The current loop will calculate the scan number on each iteration. The
number of folios to scan is based on the LRU length, with some unclear
behaviors, eg, the scan number is only shifted by reclaim priority when
aging is not needed or when at the default priority, and it couples
the number calculation with aging and rotation.
Adjust, simplify it, and decouple aging and rotation. Just calculate the
scan number for once at the beginning of the reclaim, always respect the
reclaim priority, and make the aging and rotation more explicit.
This slightly changes how aging and offline memcg reclaim works:
Previously, aging was always skipped at DEF_PRIORITY even when
eviction was impossible. Now, aging is always triggered when it
is necessary to make progress. The old behavior may waste a reclaim
iteration only to escalate priority, potentially causing over-reclaim
of slab and breaking reclaim balance in multi-cgroup setups.
Similar for offline memcg. Previously, offline memcg wouldn't be
aged unless it didn't have any evictable folios. Now, we might age
it if it has only 3 generations and the reclaim priority is less
than DEF_PRIORITY, which should be fine. On one hand, offline memcg
might still hold long-term folios, and in fact, a long-existing offline
memcg must be pinned by some long-term folios like shmem. These folios
might be used by other memcg, so aging them as ordinary memcg seems
correct. Besides, aging enables further reclaim of an offlined memcg,
which will certainly happen if we keep shrinking it. And offline
memcg might soon be no longer an issue with reparenting.
Overall, the memcg LRU rotation, as described in mmzone.h,
remains the same.
Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>
Signed-off-by: Kairui Song <kasong@tencent.com>1 parent 77bbf72 commit cab143a
1 file changed
Lines changed: 40 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4781 | 4781 | | |
4782 | 4782 | | |
4783 | 4783 | | |
4784 | | - | |
| 4784 | + | |
4785 | 4785 | | |
4786 | 4786 | | |
4787 | 4787 | | |
4788 | | - | |
4789 | 4788 | | |
4790 | 4789 | | |
4791 | 4790 | | |
4792 | 4791 | | |
4793 | | - | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
| 4795 | + | |
4794 | 4796 | | |
4795 | 4797 | | |
4796 | 4798 | | |
4797 | 4799 | | |
4798 | | - | |
4799 | | - | |
4800 | | - | |
4801 | | - | |
4802 | | - | |
4803 | | - | |
| 4800 | + | |
| 4801 | + | |
4804 | 4802 | | |
4805 | | - | |
4806 | | - | |
4807 | | - | |
4808 | | - | |
4809 | | - | |
4810 | | - | |
4811 | | - | |
4812 | | - | |
4813 | | - | |
| 4803 | + | |
4814 | 4804 | | |
| 4805 | + | |
| 4806 | + | |
4815 | 4807 | | |
4816 | | - | |
| 4808 | + | |
4817 | 4809 | | |
4818 | 4810 | | |
4819 | 4811 | | |
4820 | 4812 | | |
4821 | | - | |
4822 | | - | |
4823 | | - | |
| 4813 | + | |
| 4814 | + | |
| 4815 | + | |
| 4816 | + | |
| 4817 | + | |
| 4818 | + | |
| 4819 | + | |
4824 | 4820 | | |
4825 | | - | |
4826 | | - | |
| 4821 | + | |
4827 | 4822 | | |
4828 | 4823 | | |
4829 | 4824 | | |
| |||
4857 | 4852 | | |
4858 | 4853 | | |
4859 | 4854 | | |
| 4855 | + | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
4860 | 4860 | | |
4861 | 4861 | | |
| 4862 | + | |
4862 | 4863 | | |
4863 | | - | |
4864 | 4864 | | |
| 4865 | + | |
4865 | 4866 | | |
4866 | | - | |
| 4867 | + | |
| 4868 | + | |
4867 | 4869 | | |
| 4870 | + | |
4868 | 4871 | | |
4869 | | - | |
4870 | | - | |
| 4872 | + | |
| 4873 | + | |
4871 | 4874 | | |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
4872 | 4882 | | |
4873 | 4883 | | |
4874 | 4884 | | |
4875 | 4885 | | |
4876 | 4886 | | |
4877 | 4887 | | |
4878 | | - | |
4879 | | - | |
4880 | | - | |
4881 | | - | |
4882 | 4888 | | |
4883 | 4889 | | |
4884 | 4890 | | |
| 4891 | + | |
4885 | 4892 | | |
4886 | 4893 | | |
4887 | 4894 | | |
| |||
4907 | 4914 | | |
4908 | 4915 | | |
4909 | 4916 | | |
4910 | | - | |
4911 | | - | |
| 4917 | + | |
4912 | 4918 | | |
4913 | 4919 | | |
4914 | 4920 | | |
| |||
0 commit comments