From patchwork Thu Oct 21 08:35: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: 1544216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=nDP25AxI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HZgmc19W1z9sR4 for ; Thu, 21 Oct 2021 19:35:59 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DDDF83C5582 for ; Thu, 21 Oct 2021 10:35:56 +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 [217.194.8.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 6F4023C536F for ; Thu, 21 Oct 2021 10:35:55 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id C2F6660156D for ; Thu, 21 Oct 2021 10:35:54 +0200 (CEST) Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id F232040002 for ; Thu, 21 Oct 2021 08:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1634805353; bh=c8SWBkozG+9XivV0ECnXiAH6lP+cdFjvMnjOSpKgIGA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=nDP25AxIZg8rmVUDQQfMQ5f9KciB+HzBi4kU9nV8WKcwlXjJ+r3e8fl6nmk26wKMV w0jp0Db/yd2WE6yE13fsFPhvjGnhDEtxKyEL7NnvWygaIrZb+IP0iPmD46Jv7WhB9E /8B6KbxwCrcy2X5L0knldi5QUlEBkicxP4OTaRGnLqQ+nwCpp5CKkgTRE1OpEtYzti m58Tr2b0KsIjww+tM2LukXJaIPgzCawlXw/xgp4rUO5MN99yplnbuG7WNieQSRSSTX V5aoee0VoROtx/JrzKUbIQUgF4Zd3ND2WH/4JRXZk8v+Ex9vp8iIDKC4aA6veyJDM0 f2blLy0COkg+A== Received: by mail-lj1-f199.google.com with SMTP id w9-20020a2e9989000000b00210af61ebbdso2555749lji.2 for ; Thu, 21 Oct 2021 01:35:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=c8SWBkozG+9XivV0ECnXiAH6lP+cdFjvMnjOSpKgIGA=; b=sXnqzz1AF7Zm3kPOBDTK3GMQt/OZmtNSQuLkF36RESZ/HMYBkKg/ZOXk87cBXMouH6 er5MRufN7bWIFZMxKM2fzQxWX8V1VNBGSp4zeF3DaIiKtR54jeN7QRuyFaTRy6tHUBvK 9eD3YM3yivoJIVaUn7dEW5lWk4G4VewRg1d4eN8+En12yxmtroK2Is9okRyp+AbCPHqZ mEYbeJ6Yk6KhrZ49/FF04MkxJjrYzF0j8NYy7cfrxuGRpuUhvnuPqHblr+FKcqvGrPyD t/gk75PWKt+nG/e+ak1EwuUJZZoXbAW5oIN+RohwqwuoA7I/IutDLOihFDhzaeWEXNDB 86GA== X-Gm-Message-State: AOAM533UspyJgq+N6osMPqgHe+q9dT3Ul1rugPRo/8FtPbWSEKUR7UsK Ae71gsG1Zx8SEQ6rxXvJ5vZP4wQ8vTpPzoSa+hQoCI6/5oSsFunZfG5pFNW3f2Qbm4LjkHfP7dC xUEePCwmhT2UqQKyG7RzjUGW9d36A X-Received: by 2002:a05:6512:3699:: with SMTP id d25mr4300274lfs.380.1634805353037; Thu, 21 Oct 2021 01:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYE9Bm5GQIu/FO7vCrR5FNTs+CU74+cQPfEJRDgNydoi8lSHPDq1KNjdAw8bPjS3aYCQFlbg== X-Received: by 2002:a05:6512:3699:: with SMTP id d25mr4300256lfs.380.1634805352790; Thu, 21 Oct 2021 01:35:52 -0700 (PDT) Received: from kozik-lap.lan (89-77-68-124.dynamic.chello.pl. [89.77.68.124]) by smtp.gmail.com with ESMTPSA id h6sm462794ljc.107.2021.10.21.01.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 01:35:52 -0700 (PDT) From: Krzysztof Kozlowski To: ltp@lists.linux.it Date: Thu, 21 Oct 2021 10:35:46 +0200 Message-Id: <20211021083547.111590-1-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.30.2 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.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 1/2] lib: memutils: respect minimum memory watermark when polluting memory 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" Previous fix for an out-of-memory killer killing ioctl_sg01 process in commit 4d2e3d44fad5 ("lib: memutils: don't pollute entire system memory to avoid OoM") was not fully effective. While it covers most of the cases, an ARM64 machine with 128 GB of memory, 64 kB page size and v5.11 kernel hit it again. Polluting the memory fails with OoM: LTP: starting ioctl_sg01 ioctl_sg01 invoked oom-killer: gfp_mask=0x100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0, oom_score_adj=0 ... Mem-Info: active_anon:309 inactive_anon:1964781 isolated_anon:0 active_file:94 inactive_file:0 isolated_file:0 unevictable:305 dirty:0 writeback:0 slab_reclaimable:1510 slab_unreclaimable:5012 mapped:115 shmem:339 pagetables:463 bounce:0 free:112043 free_pcp:1 free_cma:3159 Node 0 active_anon:19776kB inactive_anon:125745984kB active_file:6016kB inactive_file:0kB unevictable:19520kB ... Node 0 DMA free:710656kB min:205120kB low:256384kB high:307648kB reserved_highatomic:0KB active_anon:0kB inactive_anon:3332032kB ... lowmem_reserve[]: 0 0 7908 7908 7908 Node 0 Normal free:6460096kB min:6463168kB low:8078912kB high:9694656kB reserved_highatomic:0KB active_anon:19776kB inactive_anon:122413952kB ... lowmem_reserve[]: 0 0 0 0 0 The important part are details of memory on Node 0 in Normal zone: 1. free memory: 6460096 kB 2. min (minimum watermark): 6463168 kB Parse the /proc/sys/vm/min_free_kbytes which contains the free memory level used as minimum watermark (triggering OoM killer). Signed-off-by: Krzysztof Kozlowski --- Changes since v3: 1. None Changes since v2: 1. Use /proc/sys/vm/min_free_kbytes instead of parsing zoneinfo, thanks tgo Liu Xinpeng. Changes since v1: 1. Add static and rename to count_min_pages(). --- lib/tst_memutils.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c index af132bcc6c24..df53c542d239 100644 --- a/lib/tst_memutils.c +++ b/lib/tst_memutils.c @@ -16,12 +16,18 @@ void tst_pollute_memory(size_t maxsize, int fillchar) { size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE; + unsigned long min_free; void **map_blocks; struct sysinfo info; + SAFE_FILE_SCANF("/proc/sys/vm/min_free_kbytes", "%lu", &min_free); + min_free *= 1024; + /* Apply a margin because we cannot get below "min" watermark */ + min_free += min_free / 10; + SAFE_SYSINFO(&info); safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024); - safety = MAX(safety, (info.freeram / 64)); + safety = MAX(safety, min_free); safety /= info.mem_unit; if (info.freeswap > safety) From patchwork Thu Oct 21 08:35: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: 1544217 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=hQuJxK1i; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HZgmm4m9tz9sR4 for ; Thu, 21 Oct 2021 19:36:08 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8858B3C55AC for ; Thu, 21 Oct 2021 10:36:06 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (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 8653F3C5543 for ; Thu, 21 Oct 2021 10:35:56 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id AA3621400F91 for ; Thu, 21 Oct 2021 10:35:55 +0200 (CEST) Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 300BA402E8 for ; Thu, 21 Oct 2021 08:35:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1634805355; bh=yciDB58AxTca60YtxfPO7qCtvE3HKpruHKmzYqv7n30=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hQuJxK1i+EKn5aPhieZgmmOy9TN6Rb5VCiJHaoMDMevdYQIswSIrBRoOtK9AIic9j xlYAeKP/jfkHVo378IQBNU1s0LewTT2/MrXvm13UCGfUaChdbanEBjlgAFWndLqV3e tjqhjODFBmiGt+euMzNmYDACGIrPYVKBRtLOjb+0McbPDSlhqVvpMdyBM8rTv0/ZhH n2ED4zOPFTqOShJBAHmUoc2I0IH46oZrxMtynL2b3KiSNWE9bFWtVuEN/MfGCbBGwb wLKyO5z6gQAIDRyhbE3bQvOxl7zVcAXaHGWmDv7wW6rxlIlqcdO3WqD0qgw1iOV6JW itq4qLbQ8D6Xg== Received: by mail-lj1-f197.google.com with SMTP id e26-20020a2e985a000000b00211109b97e6so2576279ljj.0 for ; Thu, 21 Oct 2021 01:35:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yciDB58AxTca60YtxfPO7qCtvE3HKpruHKmzYqv7n30=; b=mJfa31Iry0fJzuSsS/SWR/JItKvBN1UAEnrBzV3SxBk0U5SrnfhKpVH9LKYRXpvJiI BgnAKRdRVL1nbB86ydfu+3+JH9yEUqjsz5od32R15ODg905Bb1pdbX66aA+41ZQW8QaP MBAKe1sLxzWrEcv7F+d/LqKeND5I8rZMwyKksRvw6nJGJugb4EglkgaizBbNjjCMafup KNQvomzBFObNVJidXU3WxUjzlgTxq4Wiyq55mX2Zm7XnoU/AVXzfPbi1Lbx0FIYlI/Rx s5BrSyBpouKo8tebHw2T+PA0h7N0op9McUlmJEvBPxBJLiIu+AawkGDKitE9F1rDs9VS +GAQ== X-Gm-Message-State: AOAM5332xeyaEO9Cp43zwEpy6tsFRCWnL0fTYSm97w9DjFaB7KQ0Cemc /JagHnsTLeixxB8Gg0YbudG2XDYsEYJBj0SlsVQ1bkQoHI2dnZNquAHTKbT6smyTW6k4l2O9hKv /pCncBU4xctBluMz0XQEJ56/fyuH2 X-Received: by 2002:ac2:5a07:: with SMTP id q7mr4071078lfn.318.1634805354236; Thu, 21 Oct 2021 01:35:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlD2vwSLeUNoozYdjZfLOEb8q/cS6zRshfRgPxMHQlk2nojwaJ1dOkl+kQCNR3Dg1tYiNasg== X-Received: by 2002:ac2:5a07:: with SMTP id q7mr4071065lfn.318.1634805354024; Thu, 21 Oct 2021 01:35:54 -0700 (PDT) Received: from kozik-lap.lan (89-77-68-124.dynamic.chello.pl. [89.77.68.124]) by smtp.gmail.com with ESMTPSA id h6sm462794ljc.107.2021.10.21.01.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 01:35:53 -0700 (PDT) From: Krzysztof Kozlowski To: ltp@lists.linux.it Date: Thu, 21 Oct 2021 10:35:47 +0200 Message-Id: <20211021083547.111590-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211021083547.111590-1-krzysztof.kozlowski@canonical.com> References: <20211021083547.111590-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting 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" Usually available memory (MemAvailable from /proc/meminfo) is higher than free memory, although not always. On kernel v5.14 the formula is approximately: available = free - reserved + pagecache + reclaimable The reserved part comes from vm.min_free_kbytes (already included in previous patch: lib: memutils: respect minimum memory watermark when polluting memory) and vm.lowmem_reserve_ratio. If user set specific vm.lowmem_reserve_ratio (sysctl), the available memory could be actually lower than free. Use lower value of these (free/available), to avoid out-of-memory killer for such system configurations. Reported-by: Li Wang Reported-by: Liu Xinpeng Signed-off-by: Krzysztof Kozlowski Reviewed-by: Li Wang Reviewed-by: Liu Xinpeng --- Changes since v3: 1. New patch --- lib/tst_memutils.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c index df53c542d239..bd09cf6fad9b 100644 --- a/lib/tst_memutils.c +++ b/lib/tst_memutils.c @@ -16,6 +16,7 @@ void tst_pollute_memory(size_t maxsize, int fillchar) { size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE; + unsigned long long freeram; unsigned long min_free; void **map_blocks; struct sysinfo info; @@ -33,15 +34,24 @@ void tst_pollute_memory(size_t maxsize, int fillchar) if (info.freeswap > safety) safety = 0; + /* + * MemFree usually is lower than MemAvailable, although when setting + * sysctl vm.lowmem_reserve_ratio, this could reverse. + * + * Use the lower value of both for pollutable memory. Usually this + * means we will not evict any caches. + */ + freeram = MIN(info.freeram, (tst_available_mem() * 1024)); + /* Not enough free memory to avoid invoking OOM killer */ - if (info.freeram <= safety) + if (freeram <= safety) return; if (!maxsize) maxsize = SIZE_MAX; - if (info.freeram - safety < maxsize / info.mem_unit) - maxsize = (info.freeram - safety) * info.mem_unit; + if (freeram - safety < maxsize / info.mem_unit) + maxsize = (freeram - safety) * info.mem_unit; blocksize = MIN(maxsize, blocksize); map_count = maxsize / blocksize;