From patchwork Tue Jun 29 12:10:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 1498323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDjxW3Xxxz9sWK for ; Tue, 29 Jun 2021 22:11:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 20F093C8D79 for ; Tue, 29 Jun 2021 14:11:08 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 0E34C3C0F90 for ; Tue, 29 Jun 2021 14:10:57 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 4567D600B7C for ; Tue, 29 Jun 2021 14:10:56 +0200 (CEST) Received: from mail-ed1-f70.google.com ([209.85.208.70]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyCZr-0006l3-Pd for ltp@lists.linux.it; Tue, 29 Jun 2021 12:10:55 +0000 Received: by mail-ed1-f70.google.com with SMTP id m4-20020a0564024304b0290394d27742e4so11340011edc.10 for ; Tue, 29 Jun 2021 05:10:55 -0700 (PDT) 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=BClslnzLnEg8dAVMHksnVev1L7d4K9fIt7j4rb2433c=; b=iO/MxhHlUOheMc6TgGqqcub2TLVMCyrWcu10GGILfyeRFG5A0tsTdhbpicWOiuBUal y3PA2TocuEi+awu2YKut7wgOynz0MbIfyfYxbOo6Zw/DMS5mOy/TmPTSxthZAHYgYojV /409ijQ8sjh2AAHm2mJaQb8E2GL/P2LGMJIPuOT0vfbTkbVRMNn8meRBJsbu1rwUhBnj YHQIrB+oZ/gkfFFEQ0UfWghj1AWU4V2Omx2nl8Arh6pse+nzuVlZxf7khhnvy0C9EtTI kfP72xYxTRM4Msj4R70T/CpWZ/9iQwlNiXrlyBMlJnnQekJhjTxASG0u9cJU1keiSbUK Q+QA== X-Gm-Message-State: AOAM530CHPEzdohbxG6zS88EJ7rAIKbqDAelkwpBDgr2DaK9QOLxu0Ce LCAMS8ld2OmXKXbMHnbre/fDi1J678UwbqCfDUrKyBYb99sFexP0saycszGqAE16/qpKMaBf6Pn ukLMnQJu7yNLmC36uT4BqyB8uVk3B X-Received: by 2002:aa7:cb9a:: with SMTP id r26mr40815493edt.78.1624968655270; Tue, 29 Jun 2021 05:10:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO2IbI24MEangFFIWvYu28PEZeEn4i90k+gKZqTCRf7HHzJAlLQFQon9mxv1mHa6ELquOJCA== X-Received: by 2002:aa7:cb9a:: with SMTP id r26mr40815478edt.78.1624968655181; Tue, 29 Jun 2021 05:10:55 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-177-222.adslplus.ch. [188.155.177.222]) by smtp.gmail.com with ESMTPSA id n4sm8084256eja.121.2021.06.29.05.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 05:10:54 -0700 (PDT) From: Krzysztof Kozlowski To: ltp@lists.linux.it Date: Tue, 29 Jun 2021 14:10:44 +0200 Message-Id: <20210629121047.100391-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> References: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_NONE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v4 1/4] include/tst_pid.h: fix language typo (subtraction) X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Krzysztof Kozlowski --- include/tst_pid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tst_pid.h b/include/tst_pid.h index 9ba1abb27b7c..6c42f73a57e7 100644 --- a/include/tst_pid.h +++ b/include/tst_pid.h @@ -13,7 +13,7 @@ pid_t tst_get_unused_pid_(void (*cleanup_fn)(void)); /* - * Returns number of free pids by substarction of the number of pids + * Returns number of free pids by subtraction of the number of pids * currently used ('ps -eT') from max_pids */ int tst_get_free_pids_(void (*cleanup_fn)(void)); From patchwork Tue Jun 29 12:10:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 1498324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDjxh02Cvz9sVb for ; Tue, 29 Jun 2021 22:11:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 622933C6CFA for ; Tue, 29 Jun 2021 14:11:17 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id EE8CD3C0F90 for ; Tue, 29 Jun 2021 14:10:57 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 8A6B21A00E7F for ; Tue, 29 Jun 2021 14:10:57 +0200 (CEST) Received: from mail-ej1-f70.google.com ([209.85.218.70]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyCZt-0006lH-0B for ltp@lists.linux.it; Tue, 29 Jun 2021 12:10:57 +0000 Received: by mail-ej1-f70.google.com with SMTP id ho42-20020a1709070eaab02904a77ea3380eso5629157ejc.4 for ; Tue, 29 Jun 2021 05:10:56 -0700 (PDT) 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=d9qhKPd8OKON9S7Pt7H7PbGx5dpQ/BTd41TQLNh9iSA=; b=Y+ofzynFrZtoEiWQPvQENuYCT8jOs0hwWl0RLqpFaxjhquuNQ+xYqtB1ZInJPernp1 yQmtzlxcEW08Zkdu0kHWTMML9tCHvgHHM1KDUYH56ltl+04M+xm3T5LpnK6Qc/3vgrki yUImr8uvI9zjw+8+E4xRmM+h3IYP1b4RCSYzQty3HE40wEDSwa2Fz7PaOQOaUZlc5Udf 69mxA+XfwoM6Hxo2yKwnFSAxfDKXGT15OoBTQDWyOyKiqbAi3AqC0iwUFqgccRT6yW18 2vQAVsHnjqkSJEVh9J3Q2bb5B7YAb4vWfNL2hprmgEUAPeWILVSt9bXb5suza7ZtxzJb xOFA== X-Gm-Message-State: AOAM5328ktyG3qPHMeRDy/eAYRtYH4r/WvjIzzkSidP0OFcn8WbI7/45 XVw+8sWvbIxsNUlwHriKH/9J3+K/LduA/HE/G5G2OsmUoBwOCRCOz+K83BGVgQx8lxN0FoARl86 3nAz+2EedwQrc9SqV3oZ9S9LH0gt3 X-Received: by 2002:a05:6402:1d55:: with SMTP id dz21mr38885152edb.338.1624968656288; Tue, 29 Jun 2021 05:10:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGiPIHEehM3vLiXcWHmVK5xtFMyIKzD5Q8SeWmMl+OKBl6E7+HcQ2V8AMT9OYUI53aUIJG0A== X-Received: by 2002:a05:6402:1d55:: with SMTP id dz21mr38885130edb.338.1624968656082; Tue, 29 Jun 2021 05:10:56 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-177-222.adslplus.ch. [188.155.177.222]) by smtp.gmail.com with ESMTPSA id n4sm8084256eja.121.2021.06.29.05.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 05:10:55 -0700 (PDT) From: Krzysztof Kozlowski To: ltp@lists.linux.it Date: Tue, 29 Jun 2021 14:10:45 +0200 Message-Id: <20210629121047.100391-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> References: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_NONE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v4 2/4] tst_pid.c: fix fork failure on small memory systems X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Running syscalls/msgstress04 on a system with less than ~4 GB of RAM fails: Fork failure in the first child of child group 4396 Fork failure in the second child of child group 4413 msgstress04 1 TFAIL : msgstress04.c:222: Child exit status = 1 The reason is cgroups pid limit set by systemd user.slice. The limit is set for login session, also for root user. For example on 2 GB RAM machine it is set as: /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207 Read the maximum number of pids and adjust the test limit. Signed-off-by: Krzysztof Kozlowski --- include/tst_pid.h | 4 ++- lib/tst_pid.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/include/tst_pid.h b/include/tst_pid.h index 6c42f73a57e7..8d999a655f1a 100644 --- a/include/tst_pid.h +++ b/include/tst_pid.h @@ -14,7 +14,9 @@ pid_t tst_get_unused_pid_(void (*cleanup_fn)(void)); /* * Returns number of free pids by subtraction of the number of pids - * currently used ('ps -eT') from max_pids + * currently used ('ps -eT') from maximum number of processes. + * The limit of processes come from kernel pid_max and cgroup session limits + * (e.g. configured by systemd user.slice). */ int tst_get_free_pids_(void (*cleanup_fn)(void)); diff --git a/lib/tst_pid.c b/lib/tst_pid.c index 9568cc9e91d2..c408172675a7 100644 --- a/lib/tst_pid.c +++ b/lib/tst_pid.c @@ -18,14 +18,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include +#include +#include #include +#include #include "test.h" #include "tst_pid.h" #include "old_safe_file_ops.h" #define PID_MAX_PATH "/proc/sys/kernel/pid_max" +#define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max" +#define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max" pid_t tst_get_unused_pid_(void (*cleanup_fn) (void)) { @@ -36,10 +42,68 @@ pid_t tst_get_unused_pid_(void (*cleanup_fn) (void)) return pid; } +/* + * Get the effective session UID - either one invoking current test via sudo + * or the real UID. + */ +static unsigned int get_session_uid(void) +{ + const char *sudo_uid; + + sudo_uid = getenv("SUDO_UID"); + if (sudo_uid) { + unsigned int real_uid; + int ret; + + ret = sscanf(sudo_uid, "%u", &real_uid); + if (ret == 1) + return real_uid; + } + + return getuid(); +} + +static int read_session_pids_limit(const char *path_fmt, int uid, + void (*cleanup_fn) (void)) +{ + int max_pids, ret; + char path[PATH_MAX]; + + ret = snprintf(path, sizeof(path), path_fmt, uid); + if (ret < 0 || (size_t)ret >= sizeof(path)) + return -1; + + if (access(path, R_OK) != 0) { + tst_resm(TINFO, "Cannot read session user limits from '%s'", path); + return -1; + } + + SAFE_FILE_SCANF(cleanup_fn, path, "%d", &max_pids); + tst_resm(TINFO, "Found limit of processes %d (from %s)", max_pids, path); + + return max_pids; +} + +static int get_session_pids_limit(void (*cleanup_fn) (void)) +{ + int max_pids, uid; + + uid = get_session_uid(); + max_pids = read_session_pids_limit(CGROUPS_V2_SLICE_FMT, uid, cleanup_fn); + if (max_pids < 0) + max_pids = read_session_pids_limit(CGROUPS_V1_SLICE_FMT, uid, + cleanup_fn); + + if (max_pids < 0) + return -1; + + return max_pids; +} + int tst_get_free_pids_(void (*cleanup_fn) (void)) { FILE *f; - int rc, used_pids, max_pids; + int rc, used_pids, max_pids, max_session_pids; f = popen("ps -eT | wc -l", "r"); if (!f) { @@ -57,6 +121,10 @@ int tst_get_free_pids_(void (*cleanup_fn) (void)) SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids); + max_session_pids = get_session_pids_limit(cleanup_fn); + if ((max_session_pids > 0) && (max_session_pids < max_pids)) + max_pids = max_session_pids; + /* max_pids contains the maximum PID + 1, * used_pids contains used PIDs + 1, * so this additional '1' is eliminated by the substraction */ From patchwork Tue Jun 29 12:10:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 1498325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDjxy2byRz9sVb for ; Tue, 29 Jun 2021 22:11:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A33803C8D91 for ; Tue, 29 Jun 2021 14:11:31 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E182D3C86AC for ; Tue, 29 Jun 2021 14:10:58 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 8C1C9200B6B for ; Tue, 29 Jun 2021 14:10:58 +0200 (CEST) Received: from mail-ed1-f70.google.com ([209.85.208.70]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyCZu-0006lb-24 for ltp@lists.linux.it; Tue, 29 Jun 2021 12:10:58 +0000 Received: by mail-ed1-f70.google.com with SMTP id g14-20020a056402424eb02903954930851bso5040836edb.0 for ; Tue, 29 Jun 2021 05:10:58 -0700 (PDT) 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=rz7GisD4gD8ZJuoI0XHtZVVDCHrVkJYv0AACuvLkJL0=; b=YLi0uUZQldX1Ya0KJWTj20J0zDerGs3XKyRakg4zA2kqj6SkrkVUwCYqwWGCejnV5E 7Cy7kl6WdXQt9eBymbbQCyDwBEoAMXlirCURWEloDe7uqJ3CqLzH/VBG15dO6rn8Varb ol+UaMaKbvsW6vJ7kwyal1kxwM4nXj4WAoXNPAhOpUnBWeNonNQWm4do9mZJT5YTonkI IMCvmAfgGBzFtsk5kL+LC0pLRr3XABufaPs7QrOqJJo9aRXBVoTmBaziZQnAYEvx03RF 6MZ7Rt8sNxWcoHNEhf1sMxEYNL2IBq4nr8U5b8uyolEBKeFRMYT1yiQseKjnCWUNWNnx q3uQ== X-Gm-Message-State: AOAM531UVl++0BYAAQo9cJ51oF+1ayl0ZMnMKv/3gjKRE4Qxjj03KFls baXfMfnkKCTm3AZqesVRvH+XA/NlU/jASTSd2tQnidleMGlAcvdTDn4JxwNL0wItOIgJhHOaVQg eSctIllBV4gq/YouvdOBz4KYt2m+l X-Received: by 2002:a17:906:dbdc:: with SMTP id yc28mr29675873ejb.444.1624968657354; Tue, 29 Jun 2021 05:10:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvwLl0BSZrjQMDzc+DbV9GQ6bxyF1ux3A4zLCXfXRlesWGYfF7WSnBAjrroI7xtW9xSyqx9Q== X-Received: by 2002:a17:906:dbdc:: with SMTP id yc28mr29675854ejb.444.1624968657192; Tue, 29 Jun 2021 05:10:57 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-177-222.adslplus.ch. [188.155.177.222]) by smtp.gmail.com with ESMTPSA id n4sm8084256eja.121.2021.06.29.05.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 05:10:56 -0700 (PDT) From: Krzysztof Kozlowski To: ltp@lists.linux.it Date: Tue, 29 Jun 2021 14:10:46 +0200 Message-Id: <20210629121047.100391-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> References: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_NONE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v4 3/4] syscalls/msgstress03: fix fork failure on small memory systems X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Running syscalls/msgstress03 on a system with less than ~4 GB of RAM fails: msgstress03 1 TFAIL : msgstress03.c:155: Fork failed (may be OK if under stress) In dmesg: LTP: starting msgstress03 cgroup: fork rejected by pids controller in /user.slice/user-1000.slice/session-1.scope The reason is cgroups pid limit set by systemd user.slice. The limit is set for login session, also for root user. For example on 2 GB RAM machine it is set as: /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207 Read the maximum number of pids and adjust the test limit. For 2 GB RAM machine with systemd this will result in: msgstress03 0 TINFO : Found limit of processes 5056 (from /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.max) msgstress03 0 TINFO : Requested number of processes higher than user session limit (10000 > 4556), setting to 4556 Signed-off-by: Krzysztof Kozlowski --- .../kernel/syscalls/ipc/msgstress/msgstress03.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c index 294b401b1b38..18e50e35ee07 100644 --- a/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c +++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c @@ -78,7 +78,7 @@ static void usage(void) int main(int argc, char **argv) { - int i, j, ok, pid; + int i, j, ok, pid, free_pids; int count, status; struct sigaction act; @@ -109,6 +109,19 @@ int main(int argc, char **argv) } } + free_pids = tst_get_free_pids(cleanup); + if (free_pids < 0) { + tst_brkm(TBROK, cleanup, "Can't obtain free_pid count"); + } else if (!free_pids) { + tst_brkm(TBROK, cleanup, "No free pids"); + } + if (nprocs >= free_pids) { + tst_resm(TINFO, + "Requested number of processes higher than limit (%d > %d), " + "setting to %d", nprocs, free_pids, free_pids); + nprocs = free_pids; + } + srand(getpid()); tid = -1; From patchwork Tue Jun 29 12:10:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 1498326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDjy73dLZz9sW6 for ; Tue, 29 Jun 2021 22:11:43 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AA8223C8D82 for ; Tue, 29 Jun 2021 14:11:40 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 342A63C8D7C for ; Tue, 29 Jun 2021 14:10:59 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id E09DA60078E for ; Tue, 29 Jun 2021 14:10:58 +0200 (CEST) Received: from mail-ej1-f71.google.com ([209.85.218.71]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyCZu-0006lk-BE for ltp@lists.linux.it; Tue, 29 Jun 2021 12:10:58 +0000 Received: by mail-ej1-f71.google.com with SMTP id lu1-20020a170906fac1b02904aa7372ec41so5527886ejb.23 for ; Tue, 29 Jun 2021 05:10:58 -0700 (PDT) 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=YDY+vNYcMIWyWGKlk63PcGfc4ciJyoIKWgoQ9zkvFRg=; b=blfy3HLBqS/Y6fxNrfjTg0xZv5ab/nhISHF0ybLiEAdld1o4qSyeRGHGLRhNu35ZyP 79o5kTXfpJeBVOfH6S+TLGpDGhqcBBHUfmlUpT2qMngBFtboTLhfCI4P+0TJWDThO9Sm LvxNT4xvELQg8jsd9xpkH128qH5viqjefIIQIq0YVMBHKhh8c05R0Z+f8VEaANhaHqkM ybhvRIqTEl+9N78ymmnFJIpzTZibuy9oM9evRO+X9VBoGHYEOnN7sGoZyPaU8cElrfrT rcLAPvxbdM88A3JjoQ9+e2xYZv0nviel6XwcsRa058h+RsqOil6tvkB4akUExgGKhDo9 bg0w== X-Gm-Message-State: AOAM533KKqEczG5StWB07XpHnNVG/0BsQdinzrqweOiNJP/8xrcfyeEC VDDfHGv1nZm1K/ZFTmkToqbq8UhIBQ/KUATw5UWdi+XWxUgxJ0pbbH3ARx1/94RDIRS8KxlCuVp /MXVnqCiqPZxbPGNsUfh8mtRqkNQ4 X-Received: by 2002:a05:6402:2805:: with SMTP id h5mr39068672ede.255.1624968657833; Tue, 29 Jun 2021 05:10:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIwReS1UAFV9s8nXjaD8p+j8hvmYZIY7TNumQLbu/j1yCz+2cyMsr+ZyLEleR18Q6K/tgYpQ== X-Received: by 2002:a05:6402:2805:: with SMTP id h5mr39068661ede.255.1624968657740; Tue, 29 Jun 2021 05:10:57 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-177-222.adslplus.ch. [188.155.177.222]) by smtp.gmail.com with ESMTPSA id n4sm8084256eja.121.2021.06.29.05.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 05:10:57 -0700 (PDT) From: Krzysztof Kozlowski To: ltp@lists.linux.it Date: Tue, 29 Jun 2021 14:10:47 +0200 Message-Id: <20210629121047.100391-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> References: <20210629121047.100391-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_NONE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v4 4/4] syscalls/msgstress: tune limit of processes for small machines X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Forking the exactly amount of processes as the limit (either from max_pids or from cgroups) is risky - OS might be doing some work and interfere with the test. Instead leave some reserve (hard-coded to 500) for the OS so the test won't fail on fork failure. Signed-off-by: Krzysztof Kozlowski --- lib/tst_pid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tst_pid.c b/lib/tst_pid.c index c408172675a7..338235f13a6a 100644 --- a/lib/tst_pid.c +++ b/lib/tst_pid.c @@ -32,6 +32,8 @@ #define PID_MAX_PATH "/proc/sys/kernel/pid_max" #define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max" #define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max" +/* Leave some available processes for the OS */ +#define PIDS_RESERVE 500 pid_t tst_get_unused_pid_(void (*cleanup_fn) (void)) { @@ -97,7 +99,7 @@ static int get_session_pids_limit(void (*cleanup_fn) (void)) if (max_pids < 0) return -1; - return max_pids; + return max_pids > PIDS_RESERVE ? max_pids - PIDS_RESERVE : 0; } int tst_get_free_pids_(void (*cleanup_fn) (void))