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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7186DC433EF for ; Fri, 13 May 2022 18:53:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89C106B0073; Fri, 13 May 2022 14:53:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 824596B0075; Fri, 13 May 2022 14:53:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69ECB6B0078; Fri, 13 May 2022 14:53:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 54E7D6B0073 for ; Fri, 13 May 2022 14:53:02 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 21E7820327 for ; Fri, 13 May 2022 18:53:02 +0000 (UTC) X-FDA: 79461617004.28.4EF15AB Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf03.hostedemail.com (Postfix) with ESMTP id C1FF6200AB for ; Fri, 13 May 2022 18:52:52 +0000 (UTC) Date: Fri, 13 May 2022 11:52:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1652467979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c9TRybVbhOQgUFxoQemhb4nS3icLR/En8Zxu0EkRFzs=; b=UKCdjVRdCBUCF0VJzs6bgU0WyPR3VyI60/PJnQpwECHSSCbZD9gieB07JA0/lDp7vEtGX3 tbsyD/Nsy4xjtX15B1/yCq3rz1O6uKYdhfoaXVv9QiXwEeGX2ny9G0ZntrBO0/ppJPLtN/ YA0km8jz4BreLxE7GMpTSF1HMy7iv/Y= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Michal =?iso-8859-1?Q?Koutn=FD?= Cc: void@manifault.com, 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, shakeelb@google.com, tj@kernel.org, Richard Palethorpe Subject: Re: [PATCH 3/4] selftests: memcg: Adjust expected reclaim values of protected cgroups Message-ID: References: <20220512174452.tr34tuh4k5jm6qjs@dev0025.ash9.facebook.com> <20220513171811.730-1-mkoutny@suse.com> <20220513171811.730-4-mkoutny@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220513171811.730-4-mkoutny@suse.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: C1FF6200AB X-Stat-Signature: xn1xjy31obhjbpeyq74zisycopywymob Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UKCdjVRd; spf=pass (imf03.hostedemail.com: domain of roman.gushchin@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-HE-Tag: 1652467972-377730 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000144, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, May 13, 2022 at 07:18:10PM +0200, Michal Koutny wrote: > 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 This is a cool stuff! How about to place it into a separate file and add a comment into the code with a reference? Thanks!