Sysfs Interface for balloon driver
PATCH 1/1 Sysfs Interface for balloon driver
Hi.
This patch provides a sysfs interface for the balloon driver (Take 2).
Currently, the interface for the balloon driver is provided by procfs. However, I was suggested by Kier and Anthony that procfs should handle
only process information and other information should be located in sysfs,
when I made the interface for virtual block devices.
The information for the balloon driver also should be moved to sysfs. So, I have made a sysfs interface for the balloon driver.
The information for balloon driver is placed in /sys/devices/system/memory/.
Example outputs of the sysfs interface of the balloon driver are as follows:
Example 1. Show each information
[root@Dom0 ~]# ls /sys/devices/system/memory/memory0/
balloon_high current_pages hard_limit
balloon_low driver_pages target_pages
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/current_pages
262144
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/target_pages
262144
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/balloon_high
0
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/balloon_low
509952
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/hard_limit
???
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/driver_pages
1024Example 2. Set memory size of a domain
[root@Dom0 ~]# echo 1024M > /sys/devices/system/memory/memory0/target_pages [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/target_pages
1048576
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/current_pages
758192
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/hard_limit
758192
[root@Dom0 ~]# cat /sys/devices/system/memory/memory0/driver_pages
1024Regards
Satoshi UCHIDA
NEC Corporation, Japan
# HG changeset patch
# User [email protected]
# Node ID 381fa5366f71bd2762290f5506d1d67be25519aa # Parent c4f3f719d997522ae82e065d4f93d5af6494a750 [Balloon]Add sysfs interface.
This patch provides sysfs interface for balloon driver. Information is located under /sys/devices/system/memory.
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +112 -0
@@ -53,6 +53,7 @@#include <asm/uaccess.h> #include <asm/tlb.h> #include <linux/list.h> +#include <linux/sysdev.h> #include <xen/xenbus.h>
@@ -456,6 +457,116 @@ static int balloon_read(char *page, char }#endif +/***************************************************** +* sysfs interface for balloon driver. +*/ + +#define BALLOON_CLASS_NAME "memory" + +struct balloon { +struct sys_device sysdev; +}; + +#define to_balloon (sys_device) container_of(sys_device, struct balloon, sysdev) + +#define BALLOON_SHOW(name, format, args...) \ + static ssize_t show_##name(struct sys_device *dev, \ + char *buf) \ + { \ + return sprintf(buf, format, ##args); \ + } \ + static SYSDEV_ATTR(name, S_IRUGO, show_##name, NULL) + +BALLOON_SHOW (current_pages,"%8lu\n" ,PAGES2KB (current_pages)); +BALLOON_SHOW (balloon_low,"%8lu\n" ,PAGES2KB (balloon_low)); +BALLOON_SHOW (balloon_high,"%8lu\n" ,PAGES2KB (balloon_high)); +BALLOON_SHOW (hard_limit, + (hard_limit!=~0UL )?"%8lu\n" :"???\n" , + (hard_limit!=~0UL )?PAGES2KB (hard_limit):0 ); +BALLOON_SHOW (driver_pages,"%8lu\n" ,PAGES2KB (driver_pages)); + +static ssize_t show_target_pages (struct sys_device *dev, +char *buf) +{ +return sprintf (buf,"%8lu\n" ,PAGES2KB (target_pages)); +} + +static ssize_t store_target_pages (struct sys_device *dev, +const char *buf, +size_t count) +{ +char memstring[64 ], *endchar; +unsigned long long target_bytes; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (count <=1 ) +return -EBADMSG ;/* runt */ +if (count >sizeof (memstring)) +return -EFBIG ;/* too long */ +strcpy (memstring, buf); + + target_bytes =memparse (memstring, &endchar); +set_new_target (target_bytes >>PAGE_SHIFT ); + +return count; +} + +static SYSDEV_ATTR(target_pages, S_IRUGO | S_IWUSR, + show_target_pages, store_target_pages); + +static struct sysdev_attribute *balloon_attrs[] = { + &attr_current_pages, + &attr_target_pages, + &attr_balloon_low, + &attr_balloon_high, + &attr_hard_limit, + &attr_driver_pages +}; + +static struct sysdev_class balloon_sysdev_class = { +set_kset_name (BALLOON_CLASS_NAME ), +}; + + +static int register_balloon (struct balloon *bln) +{ +int error; +int i; + + bln->sysdev.id =0 ; + bln->sysdev.cls = &balloon_sysdev_class; + error =sysdev_register (&bln->sysdev); + +if (!error) { +for (i=0 ; i <ARRAY_SIZE (balloon_attrs) ; i++) +sysdev_create_file (&bln->sysdev, balloon_attrs[i]); + } +return error; +} + +static void unregister_balloon (struct balloon *bln) +{ +int i; + +for (i=0 ; i <ARRAY_SIZE (balloon_attrs) ; i++) +sysdev_remove_file (&bln->sysdev, balloon_attrs[i]); +sysdev_unregister (&bln->sysdev); +} + +static int balloon_sysfs_init (void ) +{ +int ret =0 ; +struct balloon *bln =kzalloc (sizeof (*bln),GFP_KERNEL ); + + ret =sysdev_class_register (&balloon_sysdev_class); + +register_balloon (bln); + +return ret; +} +static struct notifier_block xenstore_notifier;static int __init balloon_init (void )
@@ -489,6 +600,7 @@ static int __init balloon_init(void) balloon_pde->read_proc = balloon_read; balloon_pde->write_proc = balloon_write;#endif +balloon_sysfs_init ();/* Initialise the balloon with excess memory space. */ for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 9 lines
This patch provides a sysfs interface for the balloon driver (Take 2). Example outputs of the sysfs interface of the balloon driver are as follows:
Example 1. Show each information
[root@Dom0 ~]# ls
/sys/devices/system/memory/memory0/balloon_high current_pages hard_limit balloon_low driver_pages target_pages
These names are a bit misleading, confusing pages and KB.
Perhaps go for everything in KB, and have a '_KB' post fix to all the names e.g. 'current_KB'.
Does anyone actually use balloon_low and _high? At the very least they should be renamed, possibly put under an info sub directory.
Something that would be good to export via sysfs is the maximum amount of memory the guest could have (for guests that can't expand their page array i.e. all current guests).
Since linux currently doesn't know the hard limit, perhaps best to remove this node.
Thanks,
Ian
Quoted 30 lines
[root@Dom0 ~]# cat
/sys/devices/system/memory/memory0/current_pages262144 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/target_pages 262144 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/balloon_high 0 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/balloon_low 509952 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/hard_limit ??? [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/driver_pages 1024Example 2. Set memory size of a domain
[root@Dom0 ~]# echo 1024M >
/sys/devices/system/memory/memory0/target_pages
[root@Dom0 ~]# cat/sys/devices/system/memory/memory0/target_pages
1048576
[root@Dom0 ~]# cat/sys/devices/system/memory/memory0/current_pages758192 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/hard_limit 758192 [root@Dom0 ~]# cat /sys/devices/system/memory/memory0/driver_pages 1024Regards
Satoshi UCHIDA
NEC Corporation, Japan
Ti, Ian
Quoted 4 lines
These names are a bit misleading, confusing pages and KB.
Perhaps go for everything in KB, and have a '
_KB' post fix to all the names e.g. 'current_KB'.
OK.
Quoted 4 lines
Does anyone actually use
balloon_lowand_high? At the very least they should be renamed, possibly put under an info sub directory.
Works the renaming.
However, Does it needs to put under an info sub directory?
Because both of current pages and high/low memory are information and show states of memory. Perhaps, The parameter is only target pages.
Quoted 3 lines
Since linux currently doesn't know the hard limit, perhaps best to remove this node.
The hard limit show limitation after ballooning process.
The hard limit currently is initialized before ballooning process, so no have its significance.
But, at least, anyone know the limitaion by it when ballooning process. Maybe may it be left?
Quoted 3 lines
Something that would be good to export via sysfs is the maximum amount of memory the guest could have (for guests that can't expand their page array i.e. all current guests).
What is this means?
Should information export the limitaion handled within linux? (i.e by mem option) or the limitation controlled at hypervisor (mem-max)?
Regard,
Satoshi UCHIDA