From patchwork Fri Apr 8 04:57:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12806064 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 1C050C433EF for ; Fri, 8 Apr 2022 04:57:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E9C36B0075; Fri, 8 Apr 2022 00:57:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 471128D0002; Fri, 8 Apr 2022 00:57:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2764D8D0001; Fri, 8 Apr 2022 00:57:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 168486B0075 for ; Fri, 8 Apr 2022 00:57:52 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D9C82353 for ; Fri, 8 Apr 2022 04:57:51 +0000 (UTC) X-FDA: 79332504342.04.E5FB87C Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf03.hostedemail.com (Postfix) with ESMTP id 6B99020003 for ; Fri, 8 Apr 2022 04:57:51 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id q1-20020a17090a750100b001cb1d8cb9e9so1643843pjk.1 for ; Thu, 07 Apr 2022 21:57:51 -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=gA8fl4VBLSIuPoY/kPZyFR8DNphzGSE/geYX3/dgg00=; b=Pcpd2Rbrapa7M7Za73CnE1bEFC5wI7dwEloVVr2sNZaIVqKCy5cB4naL+d9PVU9Kq9 o27VPMESu81Lm/IKCtpsqDvuaOrAbNZ4Z3JlkNVWBzI0rgkIQUh8AgXWl+jQU788ZJmX l6A6jyeZdEjndJ2j2ErDuXmLudkDIPIY2lKK43CSnl2C6npVfgu2m4i619MVJM7BRrwk AY/5jLUI62lflwZYHGLXDAiENTVnD5dnA32uP1ue3g0CVNMJg6oMYm2jAGzmng8hs1ih 0Riamlr+TJ4j2W4TmwXqsgJmdKZCloPwc1OqNvr5som55EVUiCPihm0xB908z/cfbhad eBpQ== 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=gA8fl4VBLSIuPoY/kPZyFR8DNphzGSE/geYX3/dgg00=; b=In3sUMzEAYH7ir8/f315zoieGaR/fO8I/MXc/RegrxKz1fLYSKkY+RAualjdBy4y0z BkdRQyqLUw0b/IuGzVrnH25NtNCfI95tpqqfMh8k9xXNcaHWCdvXoY+1uHkGm2fcJDvG l00iLtX3P7Nd7zPyDcWnZsLzJTXTRG65d4nv7YG6/lqUUvwwKZR0j9mzdZGK1gYfbWRm n78s2f2O+xYW/YLcJoCQYya+zulZJNB6+0m5pnWO8gBGFPIbCmNYgL5A5Rcdcgj5nGuI DO2eLExLig+6cHuHLgYyKUSfHgfl6M2OJRm46mX6lMzGrgdRa+3r1+xgcxjtlyT3cLYb PbRQ== X-Gm-Message-State: AOAM531tGe5YGtQOE1R5Z/OnBu0RuEagFLjyZP1iq2ODdsqfNoMZWSVu mf1ovWFp9oYr250H+aaY9gbEV8qkYH8fclRi X-Google-Smtp-Source: ABdhPJwveDjBEYrVRy38w4adlQ9PbmM5YsL9jL+O+3mQ7Gci02SY9egKz08a0oG2xCNWEbJ8Q67ORfFnzPtKwKxT X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:6bc4:b0:154:6b3d:a720 with SMTP id m4-20020a1709026bc400b001546b3da720mr17230778plt.104.1649393870424; Thu, 07 Apr 2022 21:57:50 -0700 (PDT) Date: Fri, 8 Apr 2022 04:57:42 +0000 In-Reply-To: <20220408045743.1432968-1-yosryahmed@google.com> Message-Id: <20220408045743.1432968-4-yosryahmed@google.com> Mime-Version: 1.0 References: <20220408045743.1432968-1-yosryahmed@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v3 3/4] selftests: cgroup: fix alloc_anon_noexit() instantly freeing memory From: Yosry Ahmed To: Johannes Weiner , Michal Hocko , Shakeel Butt , Andrew Morton , Roman Gushchin Cc: David Rientjes , Tejun Heo , Zefan Li , Jonathan Corbet , Shuah Khan , Yu Zhao , Dave Hansen , Wei Xu , Greg Thelen , Chen Wandun , Vaibhav Jain , " =?utf-8?q?Michal_Koutn=C3=BD?= " , Tim Chen , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Yosry Ahmed Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Pcpd2Rbr; spf=pass (imf03.hostedemail.com: domain of 3zsBPYgoKCKcfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3zsBPYgoKCKcfVZYfHOTLKNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: pgyn7s6e78xfqdq51jyxqpqosh4taqx6 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6B99020003 X-HE-Tag: 1649393871-926191 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: Currently, alloc_anon_noexit() calls alloc_anon() which instantly frees the allocated memory. alloc_anon_noexit() is usually used with cg_run_nowait() to run a process in the background that allocates memory. It makes sense for the background process to keep the memory allocated and not instantly free it (otherwise there is no point of running it in the background). Signed-off-by: Yosry Ahmed Acked-by: Roman Gushchin --- tools/testing/selftests/cgroup/test_memcontrol.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 36ccf2322e21..f2ffb3a30194 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -211,13 +211,17 @@ static int alloc_pagecache_50M_noexit(const char *cgroup, void *arg) static int alloc_anon_noexit(const char *cgroup, void *arg) { int ppid = getppid(); + size_t size = (unsigned long)arg; + char *buf, *ptr; - if (alloc_anon(cgroup, arg)) - return -1; + buf = malloc(size); + for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) + *ptr = 0; while (getppid() == ppid) sleep(1); + free(buf); return 0; }