To free all space utilized for persistent memory, one can write 0 to /sys/kernel/pram. This will destroy all PRAM nodes that are not currently being read or written. --- mm/pram.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/mm/pram.c b/mm/pram.c index 3ad769b..43ad85f 100644 --- a/mm/pram.c +++ b/mm/pram.c @@ -697,6 +697,32 @@ static void pram_truncate_node(struct pram_node *node) } +/* + * Free all nodes that are not under operation. + */ +static void pram_truncate(void) +{ + struct page *page, *tmp; + struct pram_node *node; + LIST_HEAD(dispose); + + mutex_lock(&pram_mutex); + list_for_each_entry_safe(page, tmp, &pram_nodes, lru) { + node = page_address(page); + if (!(node->flags & PRAM_ACCMODE_MASK)) + list_move(&page->lru, &dispose); + } + mutex_unlock(&pram_mutex); + + while (!list_empty(&dispose)) { + page = list_first_entry(&dispose, struct page, lru); + list_del(&page->lru); + node = page_address(page); + pram_truncate_node(node); + pram_free_page(node); + } +} + static void pram_stream_init(struct pram_stream *ps, struct pram_node *node, gfp_t gfp_mask) { @@ -1189,8 +1215,19 @@ static ssize_t show_pram_sb_pfn(struct kobject *kobj, return sprintf(buf, "%lx\n", pfn); } +static ssize_t store_pram_sb_pfn(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int val; + + if (kstrtoint(buf, 0, &val) || val) + return -EINVAL; + pram_truncate(); + return count; +} + static struct kobj_attribute pram_sb_pfn_attr = - __ATTR(pram, 0444, show_pram_sb_pfn, NULL); + __ATTR(pram, 0644, show_pram_sb_pfn, store_pram_sb_pfn); static struct attribute *pram_attrs[] = { &pram_sb_pfn_attr.attr, -- 1.7.10.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>