mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 11:41:38 -04:00
memory-hotplug: add sysfs removable attribute for hotplug memory remove
Memory may be hot-removed on a per-memory-block basis, particularly on POWER where the SPARSEMEM section size often matches the memory-block size. A user-level agent must be able to identify which sections of memory are likely to be removable before attempting the potentially expensive operation. This patch adds a file called "removable" to the memory directory in sysfs to help such an agent. In this patch, a memory block is considered removable if; o It contains only MOVABLE pageblocks o It contains only pageblocks with free pages regardless of pageblock type On the other hand, a memory block starting with a PageReserved() page will never be considered removable. Without this patch, the user-agent is forced to choose a memory block to remove randomly. Sample output of the sysfs files: ./memory/memory0/removable: 0 ./memory/memory1/removable: 0 ./memory/memory2/removable: 0 ./memory/memory3/removable: 0 ./memory/memory4/removable: 0 ./memory/memory5/removable: 0 ./memory/memory6/removable: 0 ./memory/memory7/removable: 1 ./memory/memory8/removable: 0 ./memory/memory9/removable: 0 ./memory/memory10/removable: 0 ./memory/memory11/removable: 0 ./memory/memory12/removable: 0 ./memory/memory13/removable: 0 ./memory/memory14/removable: 0 ./memory/memory15/removable: 0 ./memory/memory16/removable: 0 ./memory/memory17/removable: 1 ./memory/memory18/removable: 1 ./memory/memory19/removable: 1 ./memory/memory20/removable: 1 ./memory/memory21/removable: 1 ./memory/memory22/removable: 1 Signed-off-by: Badari Pulavarty <[email protected]> Signed-off-by: Mel Gorman <[email protected]> Acked-by: KAMEZAWA Hiroyuki <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
2f7f24eca3
commit
5c755e9fd8
4 changed files with 115 additions and 0 deletions
|
|
@ -100,6 +100,21 @@ static ssize_t show_mem_phys_index(struct sys_device *dev,
|
|||
return sprintf(buf, "%08lx\n", mem->phys_index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show whether the section of memory is likely to be hot-removable
|
||||
*/
|
||||
static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
|
||||
{
|
||||
unsigned long start_pfn;
|
||||
int ret;
|
||||
struct memory_block *mem =
|
||||
container_of(dev, struct memory_block, sysdev);
|
||||
|
||||
start_pfn = section_nr_to_pfn(mem->phys_index);
|
||||
ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION);
|
||||
return sprintf(buf, "%d\n", ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* online, offline, going offline, etc.
|
||||
*/
|
||||
|
|
@ -262,6 +277,7 @@ static ssize_t show_phys_device(struct sys_device *dev,
|
|||
static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
|
||||
static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
|
||||
static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
|
||||
static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
|
||||
|
||||
#define mem_create_simple_file(mem, attr_name) \
|
||||
sysdev_create_file(&mem->sysdev, &attr_##attr_name)
|
||||
|
|
@ -350,6 +366,8 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
|
|||
ret = mem_create_simple_file(mem, state);
|
||||
if (!ret)
|
||||
ret = mem_create_simple_file(mem, phys_device);
|
||||
if (!ret)
|
||||
ret = mem_create_simple_file(mem, removable);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -394,6 +412,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
|
|||
mem_remove_simple_file(mem, phys_index);
|
||||
mem_remove_simple_file(mem, state);
|
||||
mem_remove_simple_file(mem, phys_device);
|
||||
mem_remove_simple_file(mem, removable);
|
||||
unregister_memory(mem, section);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue