Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 356512
b: refs/heads/master
c: 6677e3e
h: refs/heads/master
v: v3
  • Loading branch information
Yasuaki Ishimatsu authored and Linus Torvalds committed Feb 24, 2013
1 parent 85254c7 commit 71a84ca
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 993c1aad8f316dbafae6a0ec660ec846676838d6
refs/heads/master: 6677e3eaf4d78abd7b09133414c05dc3ec353e7f
6 changes: 6 additions & 0 deletions trunk/drivers/base/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ int offline_memory_block(struct memory_block *mem)
return ret;
}

/* return true if the memory block is offlined, otherwise, return false */
bool is_memblock_offlined(struct memory_block *mem)
{
return mem->state == MEM_OFFLINE;
}

/*
* Initialize the sysfs support for memory devices...
*/
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/memory_hotplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ extern int add_memory(int nid, u64 start, u64 size);
extern int arch_add_memory(int nid, u64 start, u64 size);
extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
extern int offline_memory_block(struct memory_block *mem);
extern bool is_memblock_offlined(struct memory_block *mem);
extern int remove_memory(u64 start, u64 size);
extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
int nr_pages);
Expand Down
48 changes: 48 additions & 0 deletions trunk/mm/memory_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,54 @@ int remove_memory(u64 start, u64 size)
goto repeat;
}

lock_memory_hotplug();

/*
* we have offlined all memory blocks like this:
* 1. lock memory hotplug
* 2. offline a memory block
* 3. unlock memory hotplug
*
* repeat step1-3 to offline the memory block. All memory blocks
* must be offlined before removing memory. But we don't hold the
* lock in the whole operation. So we should check whether all
* memory blocks are offlined.
*/

mem = NULL;
for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
section_nr = pfn_to_section_nr(pfn);
if (!present_section_nr(section_nr))
continue;

section = __nr_to_section(section_nr);
/* same memblock? */
if (mem)
if ((section_nr >= mem->start_section_nr) &&
(section_nr <= mem->end_section_nr))
continue;

mem = find_memory_block_hinted(section, mem);
if (!mem)
continue;

ret = is_memblock_offlined(mem);
if (!ret) {
pr_warn("removing memory fails, because memory "
"[%#010llx-%#010llx] is onlined\n",
PFN_PHYS(section_nr_to_pfn(mem->start_section_nr)),
PFN_PHYS(section_nr_to_pfn(mem->end_section_nr + 1)) - 1);

kobject_put(&mem->dev.kobj);
unlock_memory_hotplug();
return ret;
}
}

if (mem)
kobject_put(&mem->dev.kobj);
unlock_memory_hotplug();

return 0;
}
#else
Expand Down

0 comments on commit 71a84ca

Please sign in to comment.