Patch "xenbus/backend: Add memory pressure handler callback" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    xenbus/backend: Add memory pressure handler callback

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     xenbus-backend-add-memory-pressure-handler-callback.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 235178db56f95bc80686936a50f1b0ae99cd9e55
Author: SeongJae Park <sjpark@xxxxxxxxx>
Date:   Mon Jan 27 09:18:08 2020 +0100

    xenbus/backend: Add memory pressure handler callback
    
    [ Upstream commit 8a105678fb3ec4763352db84745968bf2cb4aa65 ]
    
    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 <jgross@xxxxxxxx>
    Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Signed-off-by: SeongJae Park <sjpark@xxxxxxxxx>
    Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
    Stable-dep-of: afc545da381b ("xen: Fix the issue of resource not being properly released in xenbus_dev_probe()")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c
index 4bb603051d5b6..386a1348694a7 100644
--- a/drivers/xen/xenbus/xenbus_probe_backend.c
+++ b/drivers/xen/xenbus/xenbus_probe_backend.c
@@ -255,6 +255,35 @@ static int backend_probe_and_watch(struct notifier_block *notifier,
 	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 struct notifier_block xenstore_notifier = {
@@ -271,6 +300,9 @@ static int __init xenbus_probe_backend_init(void)
 
 	register_xenstore_notifier(&xenstore_notifier);
 
+	if (register_shrinker(&backend_memory_shrinker))
+		pr_warn("shrinker registration failed\n");
+
 	return 0;
 }
 subsys_initcall(xenbus_probe_backend_init);
diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
index 14d47ed4114fd..cf37b2d93560f 100644
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -113,6 +113,7 @@ struct xenbus_driver {
 	struct device_driver driver;
 	int (*read_otherend_details)(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)




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux