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 8FACCC4321E for ; Wed, 30 Nov 2022 17:20:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC2BF6B0072; Wed, 30 Nov 2022 12:20:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4C026B0073; Wed, 30 Nov 2022 12:20:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC1D6B0074; Wed, 30 Nov 2022 12:20:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AAA676B0072 for ; Wed, 30 Nov 2022 12:20:20 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3AB64161169 for ; Wed, 30 Nov 2022 17:20:20 +0000 (UTC) X-FDA: 80190772200.22.70F4814 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf08.hostedemail.com (Postfix) with ESMTP id 4F583160008 for ; Wed, 30 Nov 2022 17:20:19 +0000 (UTC) Date: Wed, 30 Nov 2022 09:19:54 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1669828817; 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=8d2qoJJbs/jImeDoRLTIKxjLWSiPwn5R2MjW8APBuqA=; b=berm4eT1yBkMFTFF2yGumqkY2Zu85I2EMDxahix7VUsjZxFPeH6ndwzlcwCNi7vmqb8kH0 sz7Q+YG+JcN0UGmknR9gbYBf6IZ103Mqxm1fp8eGLjDKgPX2BC7ExtqxiJEpExOkSqxB5l nWrnSYw1m6yDWWFnmEMppCh9lv5Pnlc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Yosry Ahmed Cc: Shakeel Butt , Johannes Weiner , Michal Hocko , Yu Zhao , Muchun Song , "Matthew Wilcox (Oracle)" , Vasily Averin , Vlastimil Babka , Chris Down , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 2/3] selftests: cgroup: refactor proactive reclaim code to reclaim_until() Message-ID: References: <20221123092132.2521764-1-yosryahmed@google.com> <20221123092132.2521764-3-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669828819; a=rsa-sha256; cv=none; b=M9aEKBIMVrBmtBinrXgdTzxq2xm5uy4L0NIeft4eqRk6qBgJuYdlAo3mwfwU1OQn8Wu20g tw1k55Ve4R0wnfAIcmCHGztpemvKyi3E+YFcSfclg/vHNSjYhEkePQNhvjLo9D+ENCsU0n fpcTSyX5dj0wLczsIyq0ZJ7IWIe+jac= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=berm4eT1; spf=pass (imf08.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669828819; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8d2qoJJbs/jImeDoRLTIKxjLWSiPwn5R2MjW8APBuqA=; b=OWo7PY/AcZJaBwYZtV0WoqFjucPpvhe3kOxck5DnqBOQV/aUDj5tzoXWMmnvYaChmD3buH iHIg7UFoZOqRd4AJYHFzkvtp0rlLClRFjrQvgLFQUhLv8TLoD8oiBCQ5aXZYv8V7PeFxQY FpQwUXaYReby9aijHOb+wdIS1g/tzjA= X-Stat-Signature: yny5yuacmsc8zqmg8bgbtqtjs98beajj Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=berm4eT1; spf=pass (imf08.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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4F583160008 X-Rspam-User: X-HE-Tag: 1669828819-624812 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Nov 29, 2022 at 11:42:31AM -0800, Yosry Ahmed wrote: > On Wed, Nov 23, 2022 at 7:16 PM Yosry Ahmed wrote: > > > > On Wed, Nov 23, 2022 at 5:03 PM Roman Gushchin wrote: > > > > > > On Wed, Nov 23, 2022 at 09:21:31AM +0000, Yosry Ahmed wrote: > > > > Refactor the code that drives writing to memory.reclaim (retrying, error > > > > handling, etc) from test_memcg_reclaim() to a helper called > > > > reclaim_until(), which proactively reclaims from a memcg until its > > > > usage reaches a certain value. > > > > > > > > This will be used in a following patch in another test. > > > > > > > > Signed-off-by: Yosry Ahmed > > > > --- > > > > .../selftests/cgroup/test_memcontrol.c | 85 +++++++++++-------- > > > > 1 file changed, 49 insertions(+), 36 deletions(-) > > > > > > > > diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c > > > > index 8833359556f3..d4182e94945e 100644 > > > > --- a/tools/testing/selftests/cgroup/test_memcontrol.c > > > > +++ b/tools/testing/selftests/cgroup/test_memcontrol.c > > > > @@ -645,6 +645,53 @@ static int test_memcg_max(const char *root) > > > > return ret; > > > > > > > > > The code below looks correct, but can be simplified a bit. > > > And btw thank you for adding a test! > > > > > > Reviewed-by: Roman Gushchin > > > (idk if you want invest your time in further simplication of this code, > > > it was this way before this patch, so up to you). > > > > I don't "want" to, but the voices in my head won't shut up until I do so.. > > > > Here's a patch that simplifies the code, I inlined it here to avoid > > sending a new version. If it looks good to you, it can be squashed > > into this patch or merged separately (whatever you and Andrew prefer). > > I can also send it in a separate thread if preferred. > > Roman, any thoughts on this? > > > > > > > From 18c40d61dac05b33cfc9233b17979b54422ed7c5 Mon Sep 17 00:00:00 2001 > > From: Yosry Ahmed > > Date: Thu, 24 Nov 2022 02:21:12 +0000 > > Subject: [PATCH] selftests: cgroup: simplify memcg reclaim code > > > > Simplify the code for the reclaim_until() helper used for memcg reclaim > > through memory.reclaim. > > > > Signed-off-by: Yosry Ahmed > > --- > > .../selftests/cgroup/test_memcontrol.c | 65 ++++++++++--------- > > 1 file changed, 33 insertions(+), 32 deletions(-) > > > > diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c > > b/tools/testing/selftests/cgroup/test_memcontrol.c > > index bac3b91f1579..2e2bde44a6f7 100644 > > --- a/tools/testing/selftests/cgroup/test_memcontrol.c > > +++ b/tools/testing/selftests/cgroup/test_memcontrol.c > > @@ -17,6 +17,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "../kselftest.h" > > #include "cgroup_util.h" > > @@ -656,51 +657,51 @@ static int test_memcg_max(const char *root) > > return ret; > > } > > > > -/* Reclaim from @memcg until usage reaches @goal_usage */ > > +/* > > + * Reclaim from @memcg until usage reaches @goal_usage by writing to > > + * memory.reclaim. > > + * > > + * This function will return false if the usage is already below the > > + * goal. > > + * > > + * This function assumes that writing to memory.reclaim is the only > > + * source of change in memory.current (no concurrent allocations or > > + * reclaim). > > + * > > + * This function makes sure memory.reclaim is sane. It will return > > + * false if memory.reclaim's error codes do not make sense, even if > > + * the usage goal was satisfied. > > + */ > > static bool reclaim_until(const char *memcg, long goal_usage) > > { > > char buf[64]; > > int retries = 5; > > - int err; > > + int err = INT_MAX; > > long current, to_reclaim; > > > > - /* Nothing to do here */ > > - if (cg_read_long(memcg, "memory.current") <= goal_usage) > > - return true; > > - Hi Yosry! Thank you for working on this! I feel like it's still way more complex than it can be. How about something like this? (completely untested, treat is as a pseudo-code). { ... bool ret = false; for (retries = 5; retries > 0; retries--) { current = cg_read_long(memcg, "memory.current"); if (current <= goal) // replace with values_close? break; to_reclaim = current - goal_usage; snprintf(buf, sizeof(buf), "%ld", to_reclaim); err = cg_write(memcg, "memory.reclaim", buf); if (!err) ret = true; else if (err != -AGAIN) break; } return ret; }