From nobody Tue Feb 10 02:49:43 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1576242224; cv=none; d=zohomail.com; s=zohoarc; b=QG8dBQrQrpG4EcU/2WTj0s1RH7zwNPCYh9n41DMVs9+5CEsX5XGh8folVRhICxLPnTQLRD3tEpaMTV+W7PU8amL1BSYoF9JzcTNT5WBL7sNo9Hmk7l18N96GPJqMBqkH4FQ8EpLmLX17dCkiWYVZHCA5Qh2Y/JFYLiCnuEz5Fdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576242224; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JgkfmuqCAwYp88I/s9tyMfKd0JktrXXn1HvgpPv7Nfo=; b=AASL26uA4Fj0YSUjVPe4vYC0iDNBurUmiFFFf0cB5Hf4L2H2Y+l9R6cbd5uVMqYmuRH2EZ4m5WZNuh23s91IHespWlwv+7xCAI62IU3VXF6beFE44AcMyR6JRQvfjUSSJcaAJXRAZhTUjm4VsMsGVcnuPN75tQ76RpxLUWEoctQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576242224960864.9977526938895; Fri, 13 Dec 2019 05:03:44 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ifkai-0003VR-Q1; Fri, 13 Dec 2019 13:02:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ifkah-0003VB-EK for xen-devel@lists.xenproject.org; Fri, 13 Dec 2019 13:02:43 +0000 Received: from mail-pj1-x1042.google.com (unknown [2607:f8b0:4864:20::1042]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d9469836-1da8-11ea-b6f1-bc764e2007e4; Fri, 13 Dec 2019 13:02:42 +0000 (UTC) Received: by mail-pj1-x1042.google.com with SMTP id ca19so1177848pjb.8 for ; Fri, 13 Dec 2019 05:02:42 -0800 (PST) Received: from localhost.localdomain ([12.176.148.120]) by smtp.gmail.com with ESMTPSA id k3sm10872278pgc.3.2019.12.13.05.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2019 05:02:41 -0800 (PST) X-Inumbo-ID: d9469836-1da8-11ea-b6f1-bc764e2007e4 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 :mime-version:content-transfer-encoding; bh=pxUD+VmkH1xxeAkPK92Cf10G5edui36/X8Za7R/dfvU=; b=GPQHCu78Xrr1/A8JC4eIZflNvkPhPoIpyCbA1lUi7KEIi1tX/nXbPhKYzB1/tgT5dg hF7my/P3XQxI4B5TBnhiJeW5kYzjZlYY7dIHuGFzSFNT/IS6D0q51CCfCPROtMjzqoTw lHMCvZizgR+oxSHhMS0mu3DDiScOWpHwCevJ8qafgtsvOtf3+vACj5c7CCDNSWXjagSa bGJPMaGjJcjpupr9TXJEIJIReyOD6rY06JeczCa4RahX6gyimSg+H6+1fjLbhQJ2QQNd cRKEhUDEpDnW0ii97I+uPvLdgbvF74dwb6iQj83dofqtrbEfQ2IeiFzS9EwxANNEdNJa PsnQ== 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:mime-version:content-transfer-encoding; bh=pxUD+VmkH1xxeAkPK92Cf10G5edui36/X8Za7R/dfvU=; b=m89tiM4mqhC68VdrumkWgGkBfU/TSKSplc3/IZPFogZq4RpQ1NprfsdWqO8OI2IvUs BXEKg4ohw1Vkn3whDEIk0RBaMrQ9DV7Y+o0OYnI5ckb3bKR0B9CcFua/nrLdAjxYPOvV P0vJgXLNJCbeW/bGHePmwUw71pHmtH/XRA2JUn85hKj2EcFcugYmXewJUj75DB6cKxs6 bT7PKeynaY2GDtk36hUzpEIniLafCIYqlLmbpTz7w+JeZbJ57EpVXascpfWEdBmZKqeT X29W6H+QOzwEbxZ0N6cSeFgwfplU27d9UJ0tu0aFPy1wYq7m9BkurS7KAMxEoLXBN6RL 0Z5A== X-Gm-Message-State: APjAAAWQVqE8O2uFIuRqNOh3mB6hIldYy12d4IEHGqUS43wIn/qT8n/2 FTl9/uj2NI/CzVePH/VspZs= X-Google-Smtp-Source: APXvYqxE/Ac2824bFf20oZ8b1DfKFM1E4WD0jgI8CVJA/sd5exSlCoqpGrIsLq6AGBPaXEwcjeHpxw== X-Received: by 2002:a17:902:bd98:: with SMTP id q24mr13563102pls.78.1576242161936; Fri, 13 Dec 2019 05:02:41 -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: Fri, 13 Dec 2019 13:02:09 +0000 Message-Id: <20191213130211.24011-2-sjpark@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213130211.24011-1-sjpark@amazon.de> References: <20191213130211.24011-1-sjpark@amazon.de> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v8 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: linux-block@vger.kernel.org, sjpark@amazon.com, pdurrant@amazon.com, SeongJae Park , linux-kernel@vger.kernel.org, sj38.park@gmail.com, xen-devel@lists.xenproject.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Roger Pau Monn=C3=A9 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..7e78ebef7c54 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_blo= ck *notifier, return NOTIFY_DONE; } =20 +static int backend_reclaim_memory(struct device *dev, void *data) +{ + const struct xenbus_driver *drv; + + if (!dev->driver) + return 0; + drv =3D 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 =3D { + .count_objects =3D backend_shrink_memory_count, + .seeks =3D DEFAULT_SEEKS, +}; + static int __init xenbus_probe_backend_init(void) { static struct notifier_block xenstore_notifier =3D { @@ -264,6 +293,9 @@ static int __init xenbus_probe_backend_init(void) =20 register_xenstore_notifier(&xenstore_notifier); =20 + 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 869c816d5f8c..c861cfb6f720 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_memory)(struct xenbus_device *dev); }; =20 static inline struct xenbus_driver *to_xenbus_driver(struct device_driver = *drv) --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel