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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D0D8C433F5 for ; Sat, 23 Apr 2022 14:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230517AbiDWObJ (ORCPT ); Sat, 23 Apr 2022 10:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbiDWObG (ORCPT ); Sat, 23 Apr 2022 10:31:06 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2DB27FC4 for ; Sat, 23 Apr 2022 07:28:05 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f7d4addafdso1748857b3.6 for ; Sat, 23 Apr 2022 07:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DXAXkVZYPHcetFXE1oISHIeSMz1Xot5LLxB15W3LMjk=; b=tQibwGA8uz8Ue+E3pvs+c8ZLtax4gGb4dFOV3dy8bzYAyRQotxBRYtX3oExAAr/e5W lcJykMgKZDqXuCRcUTWrpgdKqNqa7SDK7R5LQ1iWkeMFOMj4/GvkIliYrru0Fcz3ot5h cvD+hIJBFRnHqnE3eBGsznogk3ef/KiPrus6ZbeRLGrGf+/GlLHeLPEohW773ai5NpM2 pXrvOgHb8VQuBDo7BbJ8vcpHd3CLD6msHLW5xjWZJUln3dl7h6R0dYjUMivzqyXucYGI E+67TMHQeiyQW5PXgSo8AKsLGTtBzdyQAAlPZ+C99mPyDJfjZvDTgswF9XlojwtZrxoc qXMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DXAXkVZYPHcetFXE1oISHIeSMz1Xot5LLxB15W3LMjk=; b=hGWOuiK2Efr9VbRW4h4232ncrDlerfDegl5hoCnJWuoJpyUxHJe11Vy9ZCVS3T0qHG X+ntpt7fKhkJyL+8695ihCQz0rplEGlg5PT3G1qPArSlreqOWmjwjSY2u8Rspdk6XTiL kATRefC8qHP9coNDD8Pkqms97gOBkLFuSUQPXZmDJYZtm4PFk3NUTIiMUQMYBn+NvJtj 2eRnrhtvn5G0lhJzfNA6SfpxKfMBJRphXybNhvHCm3pNCZvrId4UNGDXf1HbMCZXbXyI BpuiH/jpryQtXxPu2wvcLxMKZON3F9jiWYKFfgt1K42IFEiap84aROsKCOQvyhOAh3O2 BZjw== X-Gm-Message-State: AOAM531CJ1LmYsyw8qsbqWfOSteYvsjVfY0Q3jGGB1zEp66h38jqGo80 1pjDPoloFTSwDt9ngA86ZpBNhaSPBaRg8g== X-Google-Smtp-Source: ABdhPJymwLMUEIWwXLSUSEFl1hrUHDozuSw0iJLPBiMCTcvECf3BdD1JzQSLUMCkewcVDkKmZFBQ5OvW5vc+iw== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:28b]) (user=shakeelb job=sendgmr) by 2002:a05:6902:124b:b0:644:c3bf:fa2d with SMTP id t11-20020a056902124b00b00644c3bffa2dmr9159316ybu.462.1650724084357; Sat, 23 Apr 2022 07:28:04 -0700 (PDT) Date: Sat, 23 Apr 2022 14:28:01 +0000 In-Reply-To: <20220421234426.3494842-5-yosryahmed@google.com> Message-Id: <20220423142801.gnvd42cdcsz4hpon@google.com> Mime-Version: 1.0 References: <20220421234426.3494842-1-yosryahmed@google.com> <20220421234426.3494842-5-yosryahmed@google.com> Subject: Re: [PATCH v4 4/4] selftests: cgroup: add a selftest for memory.reclaim From: Shakeel Butt To: Yosry Ahmed Cc: Johannes Weiner , Michal Hocko , Andrew Morton , Roman Gushchin , David Rientjes , Tejun Heo , Zefan Li , Jonathan Corbet , Shuah Khan , Yu Zhao , Dave Hansen , Wei Xu , Greg Thelen , Chen Wandun , Vaibhav Jain , "Michal =?utf-8?Q?Koutn=C3=BD?=" , Tim Chen , Dan Schatzberg , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 21, 2022 at 11:44:26PM +0000, Yosry Ahmed wrote: > Add a new test for memory.reclaim that verifies that the interface > correctly reclaims memory as intended, from both anon and file pages. > > Signed-off-by: Yosry Ahmed > Acked-by: Roman Gushchin > --- > .../selftests/cgroup/test_memcontrol.c | 86 +++++++++++++++++++ > 1 file changed, 86 insertions(+) > > diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c > index f2ffb3a30194..5f7c20de2426 100644 > --- a/tools/testing/selftests/cgroup/test_memcontrol.c > +++ b/tools/testing/selftests/cgroup/test_memcontrol.c > @@ -760,6 +760,91 @@ static int test_memcg_max(const char *root) > return ret; > } > > +/* > + * This test checks that memory.reclaim reclaims the given > + * amount of memory (from both anon and file). > + */ > +static int test_memcg_reclaim(const char *root) > +{ > + int ret = KSFT_FAIL, fd, retries; > + char *memcg; > + long current, to_reclaim; > + char buf[64]; > + > + memcg = cg_name(root, "memcg_test"); > + if (!memcg) > + goto cleanup; > + > + if (cg_create(memcg)) > + goto cleanup; > + > + current = cg_read_long(memcg, "memory.current"); > + if (current != 0) > + goto cleanup; > + > + cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(50)); Don't you need is_swap_enabled() check before deciding to do the anon allocations? > + sleep(1); > + > + fd = get_temp_fd(); > + if (fd < 0) > + goto cleanup; > + > + cg_run_nowait(memcg, alloc_pagecache_50M_noexit, (void *)(long)fd); > + sleep(1); These sleep(1)s do not seem robust. Since kernel keeps the page cache around, you can convert anon to use tmpfs and use simple cg_run to trigger the allocations of anon (tmpfs) and file which will remain in memory even after return from cg_run.