On Tue, Oct 05, 2021 at 11:57:54AM -0700, Mike Kravetz wrote: > It is the smallest. > > CMA uses a per-region bit map to track allocations. When setting up the > region, you specify how many pages each bit represents. Currently, > only gigantic pages are allocated/freed from CMA so the region is set up > such that one bit represents a gigantic page size allocation. > > With demote, a gigantic page (allocation) could be split into smaller > size pages. And, these smaller size pages will be freed to CMA. So, > since the per-region bit map needs to be set up to represent the smallest > allocation/free size, it now needs to be set to the smallest huge page > size which can be freed to CMA. > > Unfortunately, we set up the CMA region for huge pages before we set up > huge pages sizes (hstates). So, technically we do not know the smallest > huge page size as this can change via command line options and > architecture specific code. Therefore, at region setup time we need some > constant value for smallest possible huge page size. That is why > HUGETLB_PAGE_ORDER is used. Do you know if that is done for a reason? Setting up CMA for hugetlb before initialiting hugetlb itself? Would not make more sense to do it the other way around? The way I see it is that it is a bit unfortunate that we cannot only demote gigantic pages per se, so 1GB on x86_64 and 16G on arm64 with 64k page size. I guess nothing to be worried about now as this is an early stage, but maybe something to think about in the future in we case we want to allow for more flexibility. > I should probably add all that to the changelog for clarity? Yes, I think it would be great to have that as a context. > After your comment yesterday about rewriting this code for clarity, this > now becomes: > > /* > * Set demote order for each hstate. Note that > * h->demote_order is initially 0. > * - We can not demote gigantic pages if runtime freeing > * is not supported, so skip this. > * - If CMA allocation is possible, we can not demote > * HUGETLB_PAGE_ORDER or smaller size pages. > */ > if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) > continue; > if (hugetlb_cma_size && h->order <= HUGETLB_PAGE_ORDER) > continue; > for_each_hstate(h2) { > if (h2 == h) > continue; > if (h2->order < h->order && > h2->order > h->demote_order) > h->demote_order = h2->order; > } > > Hopefully, that is more clear. Defintiely, this looks better to me. -- Oscar Salvador SUSE Labs