On Tue, 2022-06-14 at 17:30 -0700, Wei Xu wrote: Thanks for your comments. > When we don't know which pages are being charged, we should still > charge the usage to toptier (assuming that toptier always include the > default tier), e.g. from try_charge_memcg(). > I delayed the charging of the toptier a bit till we know which page is being used and the memcg is being assigned to the page. That's when mem_cgroup_charge_toptier is invoked. Otherwise if we charge to toptier first, we will have additional work to deduct the count when pages used are not toptier. > The idea is that when lower tier memory is not used, memcg->toptier > and memcg->memory should have the same value. Otherwise, it can cause > confusions about where the pages of (memcg->memory - memcg->toptier) > go. Any difference should be very small as the charge will go into toptier too quickly. The values will be different even if memcg->memory is read at slightly different time anyway. Tim