Commit 8a105678 authored by SeongJae Park's avatar SeongJae Park Committed by Boris Ostrovsky

xenbus/backend: Add memory pressure handler callback

Granting pages consumes backend system memory.  In systems configured
with insufficient spare memory for those pages, it can cause a memory
pressure situation.  However, finding the optimal amount of the spare
memory is challenging for large systems having dynamic resource
utilization patterns.  Also, such a static configuration might lack
flexibility.

To mitigate such problems, this commit adds a memory reclaim callback to
'xenbus_driver'.  If a memory pressure is detected, 'xenbus' requests
every backend driver to volunarily release its memory.

Note that it would be able to improve the callback facility for more
sophisticated handlings of general pressures.  For example, it would be
possible to monitor the memory consumption of each device and issue the
release requests to only devices which causing the pressure.  Also, the
callback could be extended to handle not only memory, but general
resources.  Nevertheless, this version of the implementation defers such
sophisticated goals as a future work.
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarRoger Pau Monné <roger.pau@citrix.com>
Signed-off-by: default avatarSeongJae Park <sjpark@amazon.de>
Signed-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent 92937241
...@@ -247,6 +247,35 @@ static int backend_probe_and_watch(struct notifier_block *notifier, ...@@ -247,6 +247,35 @@ static int backend_probe_and_watch(struct notifier_block *notifier,
return NOTIFY_DONE; return NOTIFY_DONE;
} }
static int backend_reclaim_memory(struct device *dev, void *data)
{
const struct xenbus_driver *drv;
if (!dev->driver)
return 0;
drv = to_xenbus_driver(dev->driver);
if (drv && drv->reclaim_memory)
drv->reclaim_memory(to_xenbus_device(dev));
return 0;
}
/*
* Returns 0 always because we are using shrinker to only detect memory
* pressure.
*/
static unsigned long backend_shrink_memory_count(struct shrinker *shrinker,
struct shrink_control *sc)
{
bus_for_each_dev(&xenbus_backend.bus, NULL, NULL,
backend_reclaim_memory);
return 0;
}
static struct shrinker backend_memory_shrinker = {
.count_objects = backend_shrink_memory_count,
.seeks = DEFAULT_SEEKS,
};
static int __init xenbus_probe_backend_init(void) static int __init xenbus_probe_backend_init(void)
{ {
static struct notifier_block xenstore_notifier = { static struct notifier_block xenstore_notifier = {
...@@ -263,6 +292,9 @@ static int __init xenbus_probe_backend_init(void) ...@@ -263,6 +292,9 @@ static int __init xenbus_probe_backend_init(void)
register_xenstore_notifier(&xenstore_notifier); register_xenstore_notifier(&xenstore_notifier);
if (register_shrinker(&backend_memory_shrinker))
pr_warn("shrinker registration failed\n");
return 0; return 0;
} }
subsys_initcall(xenbus_probe_backend_init); subsys_initcall(xenbus_probe_backend_init);
...@@ -105,6 +105,7 @@ struct xenbus_driver { ...@@ -105,6 +105,7 @@ struct xenbus_driver {
struct device_driver driver; struct device_driver driver;
int (*read_otherend_details)(struct xenbus_device *dev); int (*read_otherend_details)(struct xenbus_device *dev);
int (*is_ready)(struct xenbus_device *dev); int (*is_ready)(struct xenbus_device *dev);
void (*reclaim_memory)(struct xenbus_device *dev);
}; };
static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv) static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment