Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1043840iob; Fri, 13 May 2022 20:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUefUvEEOXudYQAg0xJGJ+GnwqjCAEMfF7zWg77vnTL/EnWL/MRAJldaCe+fnvHcgipVfy X-Received: by 2002:a1c:cc08:0:b0:393:e7d2:e580 with SMTP id h8-20020a1ccc08000000b00393e7d2e580mr7344672wmb.145.1652500279956; Fri, 13 May 2022 20:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652500279; cv=none; d=google.com; s=arc-20160816; b=KcFVGb00trhTtdgGSGAm3sAXw00ZaH2u7yFmKlf8O536moGP/vsGoR0Fu4vhtnuCAN ntTMj20n2h9aO5VzlwtNVd23FsuZ/K648mCK0Lv1CKSa16x/MQvtRvNK7WqaLuslBt95 ptq3ogmYF1hdOwcpUiKEmH8ddMkD/Hjg4yL54xYrTCrn+/koMEMPVgjI2G6MO02ogMvE IZRM9KneA060sYPPjmXvblshfBQOrDW5IYY3pFpjLzQgoIv0e6z6dBb40Lt1uYdiB1M6 h0aGzrFa22kodMP1Do6fc6o8IwQymaAT3D+Dj1+4hQ8Dsz2yj3HsxgG9R4eAcnUbMohz 1R+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p/VfT98eDaSoE5VMKiC0q6OouDpijrF5gH7LM1N1KeA=; b=w6IvTVfQhFIGw0bjC61FDvQH+3Q/oELmXDnpEqq0doy5GbkL9sfcyV2g06yAfUd5d9 qTzfvry7EFRW4Nf1jBpQq0wmVfFJzGW9coeTmizAo5CIa57lNxZxRPxClB/clUDaJIsV mDaspviOLZjqm03CBpc7YhsY/Ctq4rEP2lBwAMN5SjPAdBEXjllW/u3DkRr7azKb+cbG kpakFARVC+uDOFxus8/hDuKRXnxEJ3J/QzNcRIMwBJASD23z4haeYM8corG3Z/lNM20R PkEg2XBf+qcQF8ykRZNtyT5sa12L7+0iylKLgjrFRfEdCwPw01yj4ei6lfstgktQjxTS 8xxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="fVXpbRI/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u15-20020a5d6daf000000b0020c57df709csi4375098wrs.1056.2022.05.13.20.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="fVXpbRI/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8DBBB47B570; Fri, 13 May 2022 17:24:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382904AbiEMRTB (ORCPT + 99 others); Fri, 13 May 2022 13:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376387AbiEMRSn (ORCPT ); Fri, 13 May 2022 13:18:43 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 721BA3B3FD; Fri, 13 May 2022 10:18:42 -0700 (PDT) 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 0A3CB1F971; Fri, 13 May 2022 17:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1652462321; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p/VfT98eDaSoE5VMKiC0q6OouDpijrF5gH7LM1N1KeA=; b=fVXpbRI/iGLP8RPo840xZVGfonklr2K3QS8qE+DN+oazLFZTP2hlyqjJgLqukjjH2CqpWh PZYP9/xzMNqDE8Jl8jAtu7j1VFr7iFze/ij6U4OD3rGdE9N/B4jOlDbAApp7VMrRWiOGV5 eFIJLzK2Gmv1z5Jcy15l4Yo9/D+vQGs= 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 B820513B3D; Fri, 13 May 2022 17:18:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MEX6K/CSfmIeUgAAMHmgww (envelope-from ); Fri, 13 May 2022 17:18:40 +0000 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: void@manifault.com Cc: akpm@linux-foundation.org, cgroups@vger.kernel.org, hannes@cmpxchg.org, kernel-team@fb.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, mkoutny@suse.com, roman.gushchin@linux.dev, shakeelb@google.com, tj@kernel.org, Richard Palethorpe Subject: [PATCH 3/4] selftests: memcg: Adjust expected reclaim values of protected cgroups Date: Fri, 13 May 2022 19:18:10 +0200 Message-Id: <20220513171811.730-4-mkoutny@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220513171811.730-1-mkoutny@suse.com> References: <20220512174452.tr34tuh4k5jm6qjs@dev0025.ash9.facebook.com> <20220513171811.730-1-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The numbers are not easy to derive in a closed form (certainly mere protections ratios do not apply), therefore use a simulation to obtain expected numbers. The new values make the protection tests succeed more precisely. % run as: octave-cli script % % Input configurations % ------------------- % E parent effective protection % n nominal protection of siblings set at the givel level % c current consumption -,,- % example from testcase (values in GB) E = 50 / 1024; n = [75 25 0 500 ] / 1024; c = [50 50 50 0] / 1024; % Reclaim parameters % ------------------ % Minimal reclaim amount (GB) cluster = 32*4 / 2**20; % Reclaim coefficient (think as 0.5^sc->priority) alpha = .1 % Simulation parameters % --------------------- epsilon = 1e-7; timeout = 1000; % Simulation loop % --------------------- % Simulation assumes siblings consumed the initial amount of memory (w/out % reclaim) and then the reclaim starts, all memory is reclaimable, i.e. treated % same. It simulates only non-low reclaim and assumes all memory.min = 0. ch = []; eh = []; rh = []; for t = 1:timeout % low_usage u = min(c, n); siblings = sum(u); % effective_protection() protected = min(n, c); % start with nominal e = protected * min(1, E / siblings); % normalize overcommit % recursive protection unclaimed = max(0, E - siblings); parent_overuse = sum(c) - siblings; if (unclaimed > 0 && parent_overuse > 0) overuse = max(0, c - protected); e += unclaimed * (overuse / parent_overuse); endif % get_scan_count() r = alpha * c; % assume all memory is in a single LRU list % commit 1bc63fb1272b ("mm, memcg: make scan aggression always exclude protection") sz = max(e, c); r .*= (1 - (e+epsilon) ./ (sz+epsilon)); % uncomment to debug prints % e, c, r % nothing to reclaim, reached equilibrium if max(r) < epsilon break; endif % SWAP_CLUSTER_MAX r = max(r, (r > epsilon) .* cluster); % XXX here I do parallel reclaim of all siblings % in reality reclaim is serialized and each sibling recalculates own residual c = max(c - r, 0); ch = [ch ; c]; eh = [eh ; e]; rh = [rh ; r]; endfor t c, e Signed-off-by: Michal Koutný --- .../selftests/cgroup/test_memcontrol.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index eba252fa64ac..9ffacf024bbd 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -260,9 +260,9 @@ static int cg_test_proc_killed(const char *cgroup) * memory pressure in it. * * A/B memory.current ~= 50M - * A/B/C memory.current ~= 33M - * A/B/D memory.current ~= 17M - * A/B/F memory.current ~= 0 + * A/B/C memory.current ~= 29M + * A/B/D memory.current ~= 21M + * A/B/E memory.current ~= 0 * * After that it tries to allocate more than there is * unprotected memory in A available, and checks @@ -365,10 +365,10 @@ static int test_memcg_min(const char *root) for (i = 0; i < ARRAY_SIZE(children); i++) c[i] = cg_read_long(children[i], "memory.current"); - if (!values_close(c[0], MB(33), 10)) + if (!values_close(c[0], MB(29), 10)) goto cleanup; - if (!values_close(c[1], MB(17), 10)) + if (!values_close(c[1], MB(21), 10)) goto cleanup; if (c[3] != 0) @@ -417,9 +417,9 @@ static int test_memcg_min(const char *root) * * Then it checks actual memory usages and expects that: * A/B memory.current ~= 50M - * A/B/ memory.current ~= 33M - * A/B/D memory.current ~= 17M - * A/B/F memory.current ~= 0 + * A/B/ memory.current ~= 29M + * A/B/D memory.current ~= 21M + * A/B/E memory.current ~= 0 * * After that it tries to allocate more than there is * unprotected memory in A available, @@ -512,10 +512,10 @@ static int test_memcg_low(const char *root) for (i = 0; i < ARRAY_SIZE(children); i++) c[i] = cg_read_long(children[i], "memory.current"); - if (!values_close(c[0], MB(33), 10)) + if (!values_close(c[0], MB(29), 10)) goto cleanup; - if (!values_close(c[1], MB(17), 10)) + if (!values_close(c[1], MB(21), 10)) goto cleanup; if (c[3] != 0) -- 2.35.3