From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BBC3C4332F for ; Tue, 12 Oct 2021 13:42:07 +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 38EDF60555 for ; Tue, 12 Oct 2021 13:42:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 38EDF60555 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.207221.362999 (Exim 4.92) (envelope-from ) id 1maI2Y-0002HP-Vl; Tue, 12 Oct 2021 13:41:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 207221.362999; Tue, 12 Oct 2021 13:41:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1maI2Y-0002HG-SP; Tue, 12 Oct 2021 13:41:58 +0000 Received: by outflank-mailman (input) for mailman id 207221; Tue, 12 Oct 2021 13:41:57 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1maI2X-0001i7-N1 for xen-devel@lists.xenproject.org; Tue, 12 Oct 2021 13:41:57 +0000 Received: from smtp-out2.suse.de (unknown [195.135.220.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 27ae2b7f-2b62-11ec-8129-12813bfff9fa; Tue, 12 Oct 2021 13:41:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 51D2F200AD; Tue, 12 Oct 2021 13:41:51 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2774F13BC9; Tue, 12 Oct 2021 13:41:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aLQ6CJ+QZWGabgAAMHmgww (envelope-from ); Tue, 12 Oct 2021 13:41:51 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 27ae2b7f-2b62-11ec-8129-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1634046111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SEIm+LDplzdzplbZtDj1JKs78X3CX933Us/EMZK8kUQ=; b=DeH1SPQanWNTalBCfT28ybemBt/DXolwcq5aIAsmOeLi69vKGr6llMAujDPpxgEj7UaG9I WrgWUnDVeIJfO6pbffBCNn8fwYAE8OeO2Y9nhLhVzUQ8PWtUDKcCWq5uRcepdOi9FOyhbw YifqJlTD/O76cBP2JIhEzv4Zw8SllxI= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v6 2/2] tools/xenstore: set open file descriptor limit for xenstored Date: Tue, 12 Oct 2021 15:41:48 +0200 Message-Id: <20211012134148.6280-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211012134148.6280-1-jgross@suse.com> References: <20211012134148.6280-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a configuration item for the maximum number of open file descriptors xenstored should be allowed to have. The default should be "unlimited" in order not to restrict xenstored in the number of domains it can support, but unfortunately the kernel is normally limiting the maximum value via /proc/sys/fs/nr_open [1], [2]. So check that file to exist and if it does, limit the maximum value to the one specified by /proc/sys/fs/nr_open. As an aid for the admin configuring the value add a comment specifying the common needs of xenstored for the different domain types. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=60fd760fb9ff7034360bab7137c917c0330628c2 [2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0c2d64fb6cae9aae480f6a46cfe79f8d7d48b59f Signed-off-by: Juergen Gross --- V2: - set ulimit form launch script (Julien Grall) - split off from original patch (Julien Grall) V4: - switch to directly configuring the limit of file descriptors instead of domains (Ian Jackson) V5: - use /proc/sys/fs/nr_open (Ian Jackson) V6: - start daemon directly via prlimit --- .../Linux/init.d/sysconfig.xencommons.in | 13 ++++++++++++ tools/hotplug/Linux/launch-xenstore.in | 21 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons.in b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in index b83101ab7e..433e4849af 100644 --- a/tools/hotplug/Linux/init.d/sysconfig.xencommons.in +++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in @@ -32,6 +32,19 @@ # Changing this requires a reboot to take effect. #XENSTORED=@XENSTORED@ +## Type: string +## Default: unlimited +# +# Select maximum number of file descriptors xenstored is allowed to have +# opened at one time. +# For each HVM domain xenstored might need up to 5 open file descriptors, +# PVH and PV domains will require up to 3 open file descriptors. Additionally +# 20-30 file descriptors will be opened for internal uses. +# The specified value (including "unlimited") will be capped by the contents +# of /proc/sys/fs/nr_open if existing. +# Only evaluated if XENSTORETYPE is "daemon". +#XENSTORED_MAX_OPEN_FDS=unlimited + ## Type: string ## Default: "" # diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/launch-xenstore.in index 1747c96065..8438af9977 100644 --- a/tools/hotplug/Linux/launch-xenstore.in +++ b/tools/hotplug/Linux/launch-xenstore.in @@ -54,6 +54,7 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFIG_LEAF [ "$XENSTORETYPE" = "daemon" ] && { [ -z "$XENSTORED_TRACE" ] || XENSTORED_ARGS="$XENSTORED_ARGS -T @XEN_LOG_DIR@/xenstored-trace.log" + [ -z "$XENSTORED_MAX_OPEN_FDS" ] && XENSTORED_MAX_OPEN_FDS=unlimited [ -z "$XENSTORED" ] && XENSTORED=@XENSTORED@ [ -x "$XENSTORED" ] || { echo "No xenstored found" @@ -62,10 +63,28 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFIG_LEAF [ -z "$XENSTORED_OOM_MEM_THRESHOLD" ] || XENSTORED_OOM_MEM_THRESHOLD=50 XS_OOM_SCORE=-$(($XENSTORED_OOM_MEM_THRESHOLD * 10)) + [ "$XENSTORED_MAX_OPEN_FDS" = "unlimited" ] || { + [ -z "${XENSTORED_MAX_OPEN_FDS//[0-9]}" ] && + [ -n "$XENSTORED_MAX_OPEN_FDS" ] || { + echo "XENSTORED_MAX_OPEN_FDS=$XENSTORED_MAX_OPEN_FDS invalid" + echo "Setting to default \"unlimited\"." + XENSTORED_MAX_OPEN_FDS=unlimited + } + } + [ -r /proc/sys/fs/nr_open ] && { + MAX_FDS=`cat /proc/sys/fs/nr_open` + [ "$XENSTORED_MAX_OPEN_FDS" = "unlimited" ] && XENSTORED_MAX_OPEN_FDS=$MAX_FDS + [ $XENSTORED_MAX_OPEN_FDS -gt $MAX_FDS ] && { + echo "XENSTORED_MAX_OPEN_FDS exceeds system limit." + echo "Setting to \"$MAX_FDS\"." + XENSTORED_MAX_OPEN_FDS=$MAX_FDS + } + } + rm -f @XEN_RUN_DIR@/xenstored.pid echo -n Starting $XENSTORED... - $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS + prlimit --nofile=$XENSTORED_MAX_OPEN_FDS $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exit 1 XS_PID=`cat @XEN_RUN_DIR@/xenstored.pid` -- 2.26.2