Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp808133pxb; Fri, 22 Apr 2022 11:35:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz923qrLP5K53HPJvIuMQlr9v8QeqJWEyJRz7rmBI815e60HgJRpwhwDZBwpkzBoOuOoRUG X-Received: by 2002:a17:90a:e7c3:b0:1d7:4c75:3a58 with SMTP id kb3-20020a17090ae7c300b001d74c753a58mr6768990pjb.185.1650652505148; Fri, 22 Apr 2022 11:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650652505; cv=none; d=google.com; s=arc-20160816; b=As16roYdWhR4k2kbbuPGhbY161rN1xNCM8WfHlIpnPbUqfUj4lfclvApQ+aFfLMUFh qvsk4hsydsROSXbbJgcBbYSqyZhPHpZ55uEfuwSYbdASY12qUFRG9fIFsCuhCDsXqBc6 zmxhD8RfB1bHl0FLJe6cMB8qBbuPOvTxFI9IbsSVwmhQdkQfFJMsxE9TAoOps9ynWm0f sViAHXUYQZED2ae8BCoRIrRNNK6xzxQ6Dl9jVz5R2rV8leqfDTg/8gEbyBIOz4Ija0DY oOx5DEJ8/2n/nzdialYquHO9mY8e6h4LSbz33kmBCL0GGXZakmmaxcHwaSctVTgFQHAB aFyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=zrjgrKYnU6OpMbvPqxH4AMaOafcQPI/dEJCu4TPzq/A=; b=B47YGdzb9k6R9j58PeQ+7LvBQxggMoCbbP4M1mn6Uo8DcfFywDrih4/Rkeo/2JHIfp Ff+NMscwl11TBzL1AcUZz2d4ECyxJ6Nu+JLt3B64qnLa8lVqTjW9vnjQkWd5KRD6RUCi BkdrCGedkqSR2WYX7ZEmNdY2Mcz1tO0yzn9bliM+b/xTT42q29PHod3E2OOjhkyyAIB/ vng4BR9X3HQAGxn6CpqQ395Q/XGhtAmjHCgb1kn3xpX+8XlOFeUpG9RFnjVr8/VjHNu3 nk+YVdNw+Bn/ekydxEgDB78tBuGi40k15ytbtXtnJyo3qxgUKGvvTx19k6lvF4+teJzg WpGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=R5EgEEFi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 137-20020a63048f000000b003aa7a7e7743si7855765pge.495.2022.04.22.11.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:35:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=R5EgEEFi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C28CF1186FF; Fri, 22 Apr 2022 11:04:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442745AbiDUXr5 (ORCPT + 99 others); Thu, 21 Apr 2022 19:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442744AbiDUXrk (ORCPT ); Thu, 21 Apr 2022 19:47:40 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9095247AE9 for ; Thu, 21 Apr 2022 16:44:47 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id b20-20020a62a114000000b0050a6280e374so3858529pff.13 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=E/Ks5YcX2COrVXL2UcKMFyoknKPWGytr6hEAy8jVfZa6RBSpGJinE+fw+rY8Wl2ric fklavbwTJB18Wz00EjeW8wdooYGmeAQUSD3UGjs5qSx3Smihk+7sX0ZMQtZBxW26l1Mj A6XMs7zn7nkMXnmVKWUrd8B9ibeBIHew4tRrM73T4wxMCWaYgUeqUhIrGcvSdDUp1aMs pZjDu0+28BY9iUaYiLj9RUF5OGMghDrMWyTj/TM91AgJm9h7koohXQ27Ivg0F1BhapbG ntZPg8CVcmx7mDl6WzBib/GqZkhWPbWyRupUAwGm6i5Y79LJKP0xcE+IMUPu9d6oaWxy 19+w== X-Gm-Message-State: AOAM533X4E6PS+G1mRhi0H+zhR0q8hO8dh4aC2UkDwnauNm4ruIJldZB 7z4m4b8uzA+4nXHoh2ldwOXJ+zS/xJdH1x84 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=20Koutn=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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.36.0.rc2.479.g8af0fa9b8e-goog