Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp179757ybl; Tue, 10 Dec 2019 20:30:03 -0800 (PST) X-Google-Smtp-Source: APXvYqyFviNbmSvFSufjL+r62D22InVtxzfq2m8UVDcXAyHpJtOjFdaDgxdHHhnkHfzECGQQRNsZ X-Received: by 2002:aca:5490:: with SMTP id i138mr1326723oib.34.1576038603609; Tue, 10 Dec 2019 20:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576038603; cv=none; d=google.com; s=arc-20160816; b=MusiofWP7EYp3BPNCu+PFh/GkH1c06xxkSAZpPGjkJEVxOV4VpxJQiCnSx7en9dh+v i8OWzORLA7O5yZSv6+LM0+rDzMLBUCSCQQRqpObgjTxZyVIXdQR8UVVOClb8vt8h5nEi XrWiSO+XLcfb2b7tz+d+w2w73TLOkKSnBm/3ZsaO7dl/xuefV4fOySDOLQTbE4VrZsKK vtJY/OL/MgoNL5XkP0lIcdfb0LzxUTKevPN8ZUpHSkvkFtXu63+SDvhk0fdTd2bYUjKi 7vERKz073Ovmn4ABnHnpKsBEj+tdJ5G3BOOwba/6lLNrRgEfML4JsM1kLgn6eHs6EL6R HqCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=s7ypUOuVnqBd5be1hKp8bDLVVBRRPeaRQV9mQbkGU3s=; b=XUP7jCEmCnH+xfeZ3XX/b9DKOXcEpSC08/QL4xsbxci9BbwXtUND526U1EXv74Me24 6B5zXdgwj5x4nT/ihtHf/xurbkQ8jD/6qOZrMDvUJ0xJge17iLpiMjupztoWFBYRifzd IMlVNS7PDjQT0+AuSyaFIeLTx/YHvszRGSo/zE1hzex4JTNJh//Bj/hu5s7e/cW2aPS2 eYrqO4QQua1+of5aIHTdxZ5+xDS+9eEQdp1G/aeJn9ERd7cC1QQey8ExLEvND3FAAob8 IS8o6BnFYBE2pf4cdghko1UXwzqBkpvZhH23BiDFxt4ODLLZAQbkRKx+ts8dA9qEGNz0 tNvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gTENeTiC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s68si444259oih.275.2019.12.10.20.29.51; Tue, 10 Dec 2019 20:30:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gTENeTiC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbfLKE1L (ORCPT + 99 others); Tue, 10 Dec 2019 23:27:11 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:41037 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbfLKE1L (ORCPT ); Tue, 10 Dec 2019 23:27:11 -0500 Received: by mail-pj1-f66.google.com with SMTP id ca19so8395515pjb.8; Tue, 10 Dec 2019 20:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s7ypUOuVnqBd5be1hKp8bDLVVBRRPeaRQV9mQbkGU3s=; b=gTENeTiCkWr99yApgh/4VAIyoKDT3J7JznhYgYA4yoRd3lIV7Jm+5BL8ZWoTvA7zRp z9pynE4SbT7H+qeti2O+huH/QLAOHUl79cPlwnOC8jDVV7lx8IoXTxHIGs3rhJvAAMQa Yc6x1Rvg1pAjEwIvVGdP7984KVM3/BVxsgQNuP6LZ7fkAqAkavw1uX8LJtV2j+Zp6Lb5 1awdDwCJI3o1m3td6EweC4s2Bl/AsVBEc+qxdVSUDqSpEWAbA3tf9WnGg8pegcAPS9R4 5PjvVVq/2M5E9jWv0ThPdLHenPImUhlT90qLM1HLA+JaSUhSUgxpC8QDPSSX8C4XEFZT Jocg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s7ypUOuVnqBd5be1hKp8bDLVVBRRPeaRQV9mQbkGU3s=; b=mPi10sG4Z2nKcucE1v//XK+C/AaPOr2rjvYGNZ99xKs8r6gTYD1kmuvyKjcsN+bkoK G5JFoNafhr2puUkfl19yrliOCLPyfTZUiuvlEzKx9mbvQl/gv0BjYiih+qucnPAhvk9O 4TPOXMntQWYjRq+zVGTTUhWdaaMKgXpBbJfFKDbDq9BBfgdUJPAusYZGABjck1mcKa5f EgQ82OKMi9hDb/3C6kdTqwbWjeNO9Dff5QY8OTvIfVkmzy/CfjLzv97ItYsQcUbg2XaS xpzWgBGsY/a3YbR8n+7fnqZXTyuieOpIa8uyXbiTerG/okKdyIiuzlPgI9fl91hqEloI kHdA== X-Gm-Message-State: APjAAAUggu6AZpUTYUvdOzapGeWHQ3y52nCaEia+W8i+m6m9+wwm6Xqd nzQn8U5yTGT0XFFFPWob7N4= X-Received: by 2002:a17:90a:1955:: with SMTP id 21mr1200544pjh.105.1576038430640; Tue, 10 Dec 2019 20:27:10 -0800 (PST) Received: from localhost.localdomain ([12.176.148.120]) by smtp.gmail.com with ESMTPSA id r62sm692916pfc.89.2019.12.10.20.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 20:27:09 -0800 (PST) From: SeongJae Park X-Google-Original-From: SeongJae Park To: jgross@suse.com, axboe@kernel.dk, konrad.wilk@oracle.com, roger.pau@citrix.com Cc: SeongJae Park , pdurrant@amazon.com, sjpark@amazon.com, xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/3] xenbus/backend: Add memory pressure handler callback Date: Wed, 11 Dec 2019 04:26:57 +0000 Message-Id: <20191211042657.6037-1-sjpark@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191211042428.5961-1-sjpark@amazon.de> References: <20191211042428.5961-1-sjpark@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: SeongJae Park --- drivers/xen/xenbus/xenbus_probe_backend.c | 32 +++++++++++++++++++++++ include/xen/xenbus.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c index b0bed4faf44c..aedbe2198de5 100644 --- a/drivers/xen/xenbus/xenbus_probe_backend.c +++ b/drivers/xen/xenbus/xenbus_probe_backend.c @@ -248,6 +248,35 @@ static int backend_probe_and_watch(struct notifier_block *notifier, return NOTIFY_DONE; } +static int xenbus_backend_reclaim(struct device *dev, void *data) +{ + struct xenbus_driver *drv; + + if (!dev->driver) + return 0; + drv = to_xenbus_driver(dev->driver); + if (drv && drv->reclaim) + drv->reclaim(to_xenbus_device(dev)); + return 0; +} + +/* + * Returns 0 always because we are using shrinker to only detect memory + * pressure. + */ +static unsigned long xenbus_backend_shrink_count(struct shrinker *shrinker, + struct shrink_control *sc) +{ + bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, + xenbus_backend_reclaim); + return 0; +} + +static struct shrinker xenbus_backend_shrinker = { + .count_objects = xenbus_backend_shrink_count, + .seeks = DEFAULT_SEEKS, +}; + static int __init xenbus_probe_backend_init(void) { static struct notifier_block xenstore_notifier = { @@ -264,6 +293,9 @@ static int __init xenbus_probe_backend_init(void) register_xenstore_notifier(&xenstore_notifier); + if (register_shrinker(&xenbus_backend_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 869c816d5f8c..196260017666 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -104,6 +104,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)(struct xenbus_device *dev); }; static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv) -- 2.17.1