Skip to content

Commit 8a10567

Browse files
sj-awsbostrovs
authored andcommitted
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: Juergen Gross <[email protected]> Reviewed-by: Roger Pau Monné <[email protected]> Signed-off-by: SeongJae Park <[email protected]> Signed-off-by: Boris Ostrovsky <[email protected]>
1 parent 9293724 commit 8a10567

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

drivers/xen/xenbus/xenbus_probe_backend.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,35 @@ static int backend_probe_and_watch(struct notifier_block *notifier,
247247
return NOTIFY_DONE;
248248
}
249249

250+
static int backend_reclaim_memory(struct device *dev, void *data)
251+
{
252+
const struct xenbus_driver *drv;
253+
254+
if (!dev->driver)
255+
return 0;
256+
drv = to_xenbus_driver(dev->driver);
257+
if (drv && drv->reclaim_memory)
258+
drv->reclaim_memory(to_xenbus_device(dev));
259+
return 0;
260+
}
261+
262+
/*
263+
* Returns 0 always because we are using shrinker to only detect memory
264+
* pressure.
265+
*/
266+
static unsigned long backend_shrink_memory_count(struct shrinker *shrinker,
267+
struct shrink_control *sc)
268+
{
269+
bus_for_each_dev(&xenbus_backend.bus, NULL, NULL,
270+
backend_reclaim_memory);
271+
return 0;
272+
}
273+
274+
static struct shrinker backend_memory_shrinker = {
275+
.count_objects = backend_shrink_memory_count,
276+
.seeks = DEFAULT_SEEKS,
277+
};
278+
250279
static int __init xenbus_probe_backend_init(void)
251280
{
252281
static struct notifier_block xenstore_notifier = {
@@ -263,6 +292,9 @@ static int __init xenbus_probe_backend_init(void)
263292

264293
register_xenstore_notifier(&xenstore_notifier);
265294

295+
if (register_shrinker(&backend_memory_shrinker))
296+
pr_warn("shrinker registration failed\n");
297+
266298
return 0;
267299
}
268300
subsys_initcall(xenbus_probe_backend_init);

include/xen/xenbus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct xenbus_driver {
105105
struct device_driver driver;
106106
int (*read_otherend_details)(struct xenbus_device *dev);
107107
int (*is_ready)(struct xenbus_device *dev);
108+
void (*reclaim_memory)(struct xenbus_device *dev);
108109
};
109110

110111
static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)

0 commit comments

Comments
 (0)