From patchwork Thu Apr 21 23:44:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12822549 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 463AFC433F5 for ; Thu, 21 Apr 2022 23:44:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE5966B0075; Thu, 21 Apr 2022 19:44:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C94646B0078; Thu, 21 Apr 2022 19:44:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B31B16B007B; Thu, 21 Apr 2022 19:44:48 -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 A56376B0075 for ; Thu, 21 Apr 2022 19:44:48 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 763FE226CE for ; Thu, 21 Apr 2022 23:44:48 +0000 (UTC) X-FDA: 79382518656.06.994C604 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 96298C0002 for ; Thu, 21 Apr 2022 23:44:47 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id h14-20020a63530e000000b0039daafb0a84so3605530pgb.7 for ; Thu, 21 Apr 2022 16:44:47 -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=zrjgrKYnU6OpMbvPqxH4AMaOafcQPI/dEJCu4TPzq/A=; b=R5EgEEFiJLJPylJr1GpRvnGVqN1ompyECMnvFf7eJcNcIBFBfprXXAft0A/RmwaXeD sbaE02S2hM0MhJlnoYl4BZ6GwzLLyFeyoaeyfYlebGdZNk2FJqWy0CBTgUDnhS3IZByt vQWqicHWsomUI7gHz2Tvt1gFymu5ka/dsdDO3KlmWLi1mH5fKV33sBgHm0V9J9vTRadg 6MpPFs5NAnuJf5761TBNcYgccwJrkDqvgaOAsSc4lC0uYWWC70kYneQqFgmKZ/IoeuvU TVc1vZldKVcLP7xe8H7/pcshpA4uONKuKc7K/n5XrtPuudMkt4mzmX1nR+nSRuafWS5v ptTQ== 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=zrjgrKYnU6OpMbvPqxH4AMaOafcQPI/dEJCu4TPzq/A=; b=T/SppHjT3SdOrBmyDC0Sc2t/itXuyPDC7yfg3QlFBPC6lJzFKu5jkoVMnmlT7HCCW1 072q6dqMDjFJ/ANvhK1dtV5MXFGwPWwxM+eLtLvyerxUE93XtzkCfpBEpzEWXGaF6fZN EIcqiEVhdtdbZhZaKFXHmohjwwcWduUmShA5GidLJJ4/c+IlswhBi62YaFz/pLa/R8jI 4vgOCq0rSmJ/TUinmTVFlSEmS73eKuxbcdBgSk6/nHF0rCGdAG9yf45X9+a+2bKk8TS8 C7egca3LBhmMQ7PX6+1Ffsj5iEkm1e31j0bcPNMxIb5eK89NjaXDnbbGvX72AQ9JkY4H /J9g== X-Gm-Message-State: AOAM530ULsjatawqSvYKCPug1uaGdXzsFdKpYQ88kBLXyyIuPQfiYKK+ 88mdhTwNCH6PYn08kjzkFO8hhNM3rl7OgmPA X-Google-Smtp-Source: ABdhPJxkyS9552eyRbp5WO6d5madi5NDuaVaOduz7euoUqf8KeXnSqt/NpxhsWB/Uh+lm1g3ddmKZu3hnmlshvfN X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:f391:b0:158:f1e6:7233 with SMTP id f17-20020a170902f39100b00158f1e67233mr1863993ple.133.1650584687052; Thu, 21 Apr 2022 16:44:47 -0700 (PDT) Date: Thu, 21 Apr 2022 23:44:25 +0000 In-Reply-To: <20220421234426.3494842-1-yosryahmed@google.com> Message-Id: <20220421234426.3494842-4-yosryahmed@google.com> Mime-Version: 1.0 References: <20220421234426.3494842-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v4 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 , 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, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 96298C0002 X-Stat-Signature: rn3j5tdn4d3jdxw4p16s79m1xau756iz Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=R5EgEEFi; spf=pass (imf22.hostedemail.com: domain of 3b-xhYgoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3b-xhYgoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1650584687-119418 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 Acked-by: Shakeel Butt --- 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; }