From patchwork Wed Dec 11 04:26:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11284231 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA7D2188B for ; Wed, 11 Dec 2019 04:28:04 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85DE02073B for ; Wed, 11 Dec 2019 04:28:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gTENeTiC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85DE02073B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ietaj-0004w5-Ju; Wed, 11 Dec 2019 04:27:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ietai-0004vx-2I for xen-devel@lists.xenproject.org; Wed, 11 Dec 2019 04:27:12 +0000 X-Inumbo-ID: 7fe0f902-1bce-11ea-88e7-bc764e2007e4 Received: from mail-pj1-x1044.google.com (unknown [2607:f8b0:4864:20::1044]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7fe0f902-1bce-11ea-88e7-bc764e2007e4; Wed, 11 Dec 2019 04:27:11 +0000 (UTC) Received: by mail-pj1-x1044.google.com with SMTP id v93so8400821pjb.6 for ; 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=c/3ZEeDyqXO0ICD1dWe8be7IVNMHDdj7l7qyPnfEeXIWCcMHIqveGbQOOt9syDot1f sLJH/Ne6Shug8w7GOr/tqQhhat2P+2GyYzOpdpxfuqnu+RsEeGSykXI8tTiVFfmqnvfe EezsPopzFIMVNxrLD5rzmDReu5IbwUNBuAO71QotjGtT7cUm2F9n2HC5XDwvjGMKBBVC arziOCV4liAGMPOpClhlQ3waAuXeBDwfYnAOFPNnK0gNR4qaTwllZTEGNJVwqHxWWPmJ MH8Fx+3sNKz0Gk+TliSr1upRF0nhxRWN/e1c61tvC0ETwWiLLsZ0B1mtdasePnqqBp44 RHiQ== X-Gm-Message-State: APjAAAXnrXiQE+JdjSgsKgVu6ivuyWow7sOXnuoidrom54KCUzN3aVoh 4RVQMqR94O8bmOMPE2OJinY= X-Google-Smtp-Source: APXvYqxmdkRJdHXU4kf3uFrsdx5z19XOW4pKdUEplSPaVl+4BRm2wt+R0nQkpS14IKgOpvMW5oYY+g== 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 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> Subject: [Xen-devel] [PATCH v6 1/3] xenbus/backend: Add memory pressure handler callback X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: sjpark@amazon.com, pdurrant@amazon.com, SeongJae Park , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, xen-devel@lists.xenproject.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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)