Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 332474
b: refs/heads/master
c: e90bdb7
h: refs/heads/master
v: v3
  • Loading branch information
Wen Congyang authored and Linus Torvalds committed Oct 9, 2012
1 parent edcbcf8 commit 0186c5b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a16cee10c7ab994546ed98d9abfd4de74050124a
refs/heads/master: e90bdb7f52f94204c78fb40b0804645defdebd71
31 changes: 27 additions & 4 deletions trunk/drivers/base/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,11 @@ memory_block_action(unsigned long phys_index, unsigned long action)
return ret;
}

static int memory_block_change_state(struct memory_block *mem,
static int __memory_block_change_state(struct memory_block *mem,
unsigned long to_state, unsigned long from_state_req)
{
int ret = 0;

mutex_lock(&mem->state_mutex);

if (mem->state != from_state_req) {
ret = -EINVAL;
goto out;
Expand Down Expand Up @@ -309,10 +307,20 @@ static int memory_block_change_state(struct memory_block *mem,
break;
}
out:
mutex_unlock(&mem->state_mutex);
return ret;
}

static int memory_block_change_state(struct memory_block *mem,
unsigned long to_state, unsigned long from_state_req)
{
int ret;

mutex_lock(&mem->state_mutex);
ret = __memory_block_change_state(mem, to_state, from_state_req);
mutex_unlock(&mem->state_mutex);

return ret;
}
static ssize_t
store_mem_state(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
Expand Down Expand Up @@ -652,6 +660,21 @@ int unregister_memory_section(struct mem_section *section)
return remove_memory_block(0, section, 0);
}

/*
* offline one memory block. If the memory block has been offlined, do nothing.
*/
int offline_memory_block(struct memory_block *mem)
{
int ret = 0;

mutex_lock(&mem->state_mutex);
if (mem->state != MEM_OFFLINE)
ret = __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
mutex_unlock(&mem->state_mutex);

return ret;
}

/*
* Initialize the sysfs support for memory devices...
*/
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/memory_hotplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct page;
struct zone;
struct pglist_data;
struct mem_section;
struct memory_block;

#ifdef CONFIG_MEMORY_HOTPLUG

Expand Down Expand Up @@ -234,6 +235,7 @@ extern int mem_online_node(int nid);
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 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
33 changes: 32 additions & 1 deletion trunk/mm/memory_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,42 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages)

int remove_memory(u64 start, u64 size)
{
struct memory_block *mem = NULL;
struct mem_section *section;
unsigned long start_pfn, end_pfn;
unsigned long pfn, section_nr;
int ret;

start_pfn = PFN_DOWN(start);
end_pfn = start_pfn + PFN_DOWN(size);
return __offline_pages(start_pfn, end_pfn, 120 * HZ);

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 = offline_memory_block(mem);
if (ret) {
kobject_put(&mem->dev.kobj);
return ret;
}
}

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

return 0;
}
#else
int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
Expand Down

0 comments on commit 0186c5b

Please sign in to comment.