/* * Return the number of free pages in an lgroup. * * For query of LGRP_MEM_SIZE_FREE, return the number of base pagesize * pages on freelists. For query of LGRP_MEM_SIZE_AVAIL, return the * number of allocatable base pagesize pages corresponding to the * lgroup (e.g. do not include page_t's, BOP_ALLOC()'ed memory, ..) * For query of LGRP_MEM_SIZE_INSTALL, return the amount of physical * memory installed, regardless of whether or not it's usable. */ pgcnt_t lgrp_plat_mem_size(lgrp_handle_t plathand, lgrp_mem_query_t query) { int mnode; pgcnt_t npgs = (pgcnt_t)0; extern struct memlist *phys_avail; extern struct memlist *phys_install; if (lgrp_topo_ht_limit() == 1 || max_mem_nodes == 1 || mpo_disabled || plathand == LGRP_DEFAULT_HANDLE) return (lgrp_plat_mem_size_default(plathand, query)); if (plathand != LGRP_NULL_HANDLE) { mnode = plat_lgrphand_to_mem_node(plathand); if (mnode >= 0 && mem_node_config[mnode].exists) { switch (query) { case LGRP_MEM_SIZE_FREE: npgs = MNODE_PGCNT(mnode); break; case LGRP_MEM_SIZE_AVAIL: npgs = mem_node_memlist_pages(mnode, phys_avail); break; case LGRP_MEM_SIZE_INSTALL: npgs = mem_node_memlist_pages(mnode, phys_install); break; default: break; } } } return (npgs); }
/* * Remove a PFN range from a memnode. On some platforms, * the memnode will be created with physbase at the first * allocatable PFN, but later deleted with the MC slice * base address converted to a PFN, in which case we need * to assume physbase and up. */ void mem_node_del_slice(pfn_t start, pfn_t end) { int mnode; pgcnt_t delta_pgcnt, node_size; mnodeset_t omask, nmask; if (mem_node_physalign) { start &= ~(btop(mem_node_physalign) - 1); end = roundup(end, btop(mem_node_physalign)) - 1; } mnode = PFN_2_MEM_NODE(start); ASSERT(mnode < max_mem_nodes); ASSERT(mem_node_config[mnode].exists == 1); delta_pgcnt = end - start; node_size = mem_node_config[mnode].physmax - mem_node_config[mnode].physbase; if (node_size > delta_pgcnt) { /* * Subtract the slice from the memnode. */ if (start <= mem_node_config[mnode].physbase) mem_node_config[mnode].physbase = end + 1; ASSERT(end <= mem_node_config[mnode].physmax); if (end == mem_node_config[mnode].physmax) mem_node_config[mnode].physmax = start - 1; } else { /* * Let the common lgrp framework know the mnode is * leaving */ lgrp_config(LGRP_CONFIG_MEM_DEL, mnode, MEM_NODE_2_LGRPHAND(mnode)); /* * Delete the whole node. */ ASSERT(MNODE_PGCNT(mnode) == 0); do { omask = memnodes_mask; nmask = omask & ~(1ull << mnode); } while (atomic_cas_64(&memnodes_mask, omask, nmask) != omask); atomic_dec_16(&num_memnodes); mem_node_config[mnode].exists = 0; } }