On Sat, Aug 17, 2024 at 9:17 AM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote: > > On Fri, Aug 16, 2024 at 11:06:12AM +1200, Barry Song wrote: > > When memcg approaches its limit, charging mTHP becomes difficult. > > At this point, when the charge fails, we fallback to the next order > > to avoid repeatedly retrying larger orders. > > Why do you always find the ugliest possible solution to a problem? > had definitely thought about charging order-0 as well in alloc_swap_folio() when sending this quick fix mainly for quick verification it can fix the problem. v7 will definitely charge order-0 in alloc_swap_folio(). > > @@ -4244,7 +4248,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > } > > need_clear_cache = true; > > > > - if (mem_cgroup_swapin_charge_folio(folio, > > + if (nr_pages == 1 && mem_cgroup_swapin_charge_folio(folio, > > vma->vm_mm, GFP_KERNEL, > > entry)) { > > ret = VM_FAULT_OOM; > > Just make alloc_swap_folio() always charge the folio, even for order-0. > > And you'll have to uncharge it in the swapcache_prepare() failure case. I suppose this is done by folio_put() automatically. Thanks Barry