On Wed, Feb 22, 2023 at 01:08:19PM +0900, David Stevens wrote: > > > out: > > > VM_BUG_ON(!list_empty(&pagelist)); > > > - if (hpage) { > > > - mem_cgroup_uncharge(page_folio(hpage)); > > > - put_page(hpage); > > > - } > > > > Moving this chunk seems wrong, as it can leak the huge page if > > alloc_charge_hpage() failed on mem charging, iiuc. > > > > And I found that keeping it seems wrong either, because if mem charge > > failed we'll uncharge even without charging it before. But that's nothing > > about this patch alone. > > > > Posted a patch for this: > > > > https://lore.kernel.org/all/20230221214344.609226-1-peterx@xxxxxxxxxx/ [1] > > > > I _think_ this patch will make sense after rebasing to that fix if that's > > correct, but please review it and double check. > > > > Ah, good catch. I didn't notice that alloc_charge_hpage could allocate > *hpage even on failure. The failure path should work properly with > your fix. Thanks for confirming. If we can merge above [1] before this patch, then I think this patch is correct. Only if so: Acked-by: Peter Xu <peterx@xxxxxxxxxx> -- Peter Xu