> The change here is reasonable. While maybe we still miss the counting at some > other points. > > For example: > > a. > > sparse_init_nid() > __populate_section_memmap() > > If !CONFIG_SPARSEMEM_VMEMMAP, and sparse_buffer_alloc() return NULL, it > allocate extra memory from bootmem, which looks not counted. Currently, the accounting is done upfront in sparse_buffer_init(), where memmap_boot_pages_add() is called for !CONFIG_SPARSEMEM_VMEMMAP. The function sparse_buffer_alloc() can return NULL in two scenarios: * During sparse_buffer_init(), if memmap_alloc() fails, sparsemap_buf will be NULL. * Inside sparse_buffer_alloc(), if ptr + size exceeds sparsemap_buf_end, then ptr is set to NULL. Considering this, perhaps memmap_boot_pages_add() could be moved into __populate_section_memmap(), with the accounting done only if the operation is successful. What do you think? > section_activate() > populate_section_memmap() > > If !CONFIG_SPARSEMEM_VMEMMAP, it just call kvmalloc_node(), which looks not > counted. Sounds right. This means nr_memmap_pages adjustment is needed for !CONFIG_SPARSEMEM_VMEMMAP here. I will recheck this. Thank you