From patchwork Thu Apr 7 22:42:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12805880 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 2C36CC433EF for ; Thu, 7 Apr 2022 22:44:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2CD98D0003; Thu, 7 Apr 2022 18:43:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB5566B0074; Thu, 7 Apr 2022 18:43:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A55D18D0003; Thu, 7 Apr 2022 18:43:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 973C56B0073 for ; Thu, 7 Apr 2022 18:43:26 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 63BF1A7AE0 for ; Thu, 7 Apr 2022 22:43:15 +0000 (UTC) X-FDA: 79331560350.25.8C91806 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf02.hostedemail.com (Postfix) with ESMTP id DDF7C80006 for ; Thu, 7 Apr 2022 22:43:14 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id nm20-20020a17090b19d400b001ca8fa98274so6573958pjb.5 for ; Thu, 07 Apr 2022 15:43:14 -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=Jvjn52nSnpi6AIEmLCqBtZ2YPBYOJR0f93U1cJFGil4=; b=BlJpoAori7PwrN2hsipxJJDSi4wgn/as3nxmzLr88juJGOy2S6rEG7V00aGQgCSTHY ZNeLpQ7dvj8Hd8f2uKY3PM4t8YzG4U7hjFvVUweBLVzRLDlBEhe8BsgIzBcall+ZQJjb RPmHI1AgA0xcAWsHBU6nUBXP4j/Qs5Rx/E8Wr0LgywADaOrox9cPikVY7Zk5LHs9aJsI uYO5+DRm85pOBgmDgSagFEONAmNKfXh6jeWKiyIC0PTeAqnmLYDiGdO0cUmn3uUb8FMn RB6QH+QGMmuZ8QdxXV2+7mFdNZ7MiJOGD77KzHGBxmCz+qSG7OpNtheats4G2DMt9zSR UG6A== 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=Jvjn52nSnpi6AIEmLCqBtZ2YPBYOJR0f93U1cJFGil4=; b=sMQZx4oV/94Yge+Ej3acUF0GQPGzMzlAK6Rx8LaJyw2tAiyoOoAMbG8UxHblWQT7lx YN4fvFc0DqJ/A3iy531+JLb7PiXFXyMyQ+wCMEeh4pv0jo3pjuPRNHIK763TR4cNy5mZ cPM9YBalq5XT8KyqhhbvJtyqRs5HVtWZ5RQ5O74H+iNMsfCpqY7srXWcp4/4noEmlnSO XggWdAEG0znralNNeZB4JD44fKtl9qANQyxhNC27woUT7MNA1Ec4QcePDk3zWKaw9fAh Au350hFGgTRNm0RZkCQ+IA1iX3It6qkdYJFYeFdjkSbxmbd1K2mEpabVtdsjtfE4Ft88 /qPg== X-Gm-Message-State: AOAM532Wk133uBBUHWjy3TdSH0/ghx6DLRmXnGAhZ1EGwUrE9Fac7ys/ 1nyMSQvfg0ldHcsoy5wwzLWZ+hwvXNhIJS/f X-Google-Smtp-Source: ABdhPJxq3x91eslfBly031zKmT65Bar91Cou176VtwrbXWL0BEPkbqFWiipTf++fpGD5xI4wRGD+8HhGkx8dHxFP X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90b:3d0:b0:1cb:1659:c910 with SMTP id go16-20020a17090b03d000b001cb1659c910mr5182457pjb.71.1649371393981; Thu, 07 Apr 2022 15:43:13 -0700 (PDT) Date: Thu, 7 Apr 2022 22:42:43 +0000 In-Reply-To: <20220407224244.1374102-1-yosryahmed@google.com> Message-Id: <20220407224244.1374102-4-yosryahmed@google.com> Mime-Version: 1.0 References: <20220407224244.1374102-1-yosryahmed@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v2 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 , Huang@google.com, Ying , " =?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 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=BlJpoAor; spf=pass (imf02.hostedemail.com: domain of 3AWlPYgoKCCoeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3AWlPYgoKCCoeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: DDF7C80006 X-Stat-Signature: qnftxre3owimgsgubax1zuau8ri7ps6m X-HE-Tag: 1649371394-203980 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 --- tools/testing/selftests/cgroup/test_memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 36ccf2322e21..c1ec71d83af7 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -211,13 +211,18 @@ 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); + printf("Freeing buffer"); + free(buf); return 0; }