From patchwork Fri Mar 24 22:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 74776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp70888vqo; Fri, 24 Mar 2023 15:47:48 -0700 (PDT) X-Google-Smtp-Source: AKy350ZxYVA71VQLpg63fqHiqIfC7S0rbE3LLTZEd4oLvY6wadDgW1+21g7u51FqRZ7/zwpav9M0 X-Received: by 2002:a17:903:2015:b0:1a2:2091:ee8b with SMTP id s21-20020a170903201500b001a22091ee8bmr1889144pla.10.1679698068393; Fri, 24 Mar 2023 15:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679698068; cv=none; d=google.com; s=arc-20160816; b=uC5hLlnP4T3qMgD+1/Kw0A3+8P75p1nRENDXxSYhfOhmU2FR0rjSqhlYQc77ZiI2MR 0Ur/dzyUUjCTp5kPHAfzz5y8DHwD/KyAjSy6JpUfwz4sUxdbGZP20O4AK7116BP8DVta jzmSDTaH4axGfQNRifoaepw2mux4+HL23o1Xhr0SYEsr3ovessX10Zp0cXKHpBB5Nqaa 6B66XTJG5pamxJWkZDTJej4lhrR4p6rWQnfjUyllazIfE5H/5UMqmQ+OEgffTAscLRiy 1wS6iV9/hdE+5xHEy5eGNLVcjxWTB6CZTu01h07iOA7pbCyjppYodbyfsYvg8qpJ8/nX mDGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=IeyP4hszPxXQh3EfDrorhwGAyqHtWNJ8d/cCBZiRrsA=; b=uZKBz7dgB0xE2xYgGNLwViEd59Etiwizd51N5JFqVR9UDlNJR5QDOih+UjDblJ+jDD c8pDKsWeCtMYr4YO6Z6D3xwCbs8tLmjy+blXN3dwW5ihC9bw8rhSosXFyMQtG4h4S2zY NwHeOh4Qk+sGiHLS2miZMLE3lBk2uqcOZc3PYGlrnOPbeuv3xuFxhX6g5WvvZqeoOZKZ ABEM/2KtctXyEiOJzA99xthgKvsIhT9yzW+fI7F4BO01TumfFvrTelaO74M6MypKGdMG 4eFCHYB2o3ecxSpSUbHGWUwdqa1jYC43wH1XG0V6Mjq7fefFLm7NrM5fvDhsuHto5FdJ XLAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=sI8mD6Xb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o19-20020a170903211300b0019ca19614c7si20909994ple.69.2023.03.24.15.47.29; Fri, 24 Mar 2023 15:47:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=sI8mD6Xb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbjCXWbH (ORCPT + 99 others); Fri, 24 Mar 2023 18:31:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232081AbjCXWan (ORCPT ); Fri, 24 Mar 2023 18:30:43 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6A6E17CD2; Fri, 24 Mar 2023 15:30:41 -0700 (PDT) Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 5E8C520FC4F6; Fri, 24 Mar 2023 15:30:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5E8C520FC4F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679697041; bh=IeyP4hszPxXQh3EfDrorhwGAyqHtWNJ8d/cCBZiRrsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sI8mD6XbffTrTe6OV9fXtMnS45eeEG7fqfdRdFdd2DhDmRcMeiKnuvsF8EsWN9Xm/ QrVESBXRc5aGxq8fimVJdnf+vapiCdTa/vFnANgrNRXFWxFrY2PMTJyZSakgWmcS9Q 6X5aYMJwRcGgw9nQlU98ZqSA7dUO3AAwTqx0Zbyg= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dcook@linux.microsoft.com, alanau@linux.microsoft.com, brauner@kernel.org, akpm@linux-foundation.org, ebiederm@xmission.com, keescook@chromium.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v9 10/11] tracing/user_events: Charge event allocs to cgroups Date: Fri, 24 Mar 2023 15:30:27 -0700 Message-Id: <20230324223028.172-11-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324223028.172-1-beaub@linux.microsoft.com> References: <20230324223028.172-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-17.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761291081380841275?= X-GMAIL-MSGID: =?utf-8?q?1761291081380841275?= Operators need a way to limit how much memory cgroups use. User events need to be included into that accounting. Fix this by using GFP_KERNEL_ACCOUNT for allocations generated by user programs for user_event tracing. Signed-off-by: Beau Belgrave --- kernel/trace/trace_events_user.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c index e4ee25d16f3b..222f2eb59c7c 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -442,7 +442,7 @@ static bool user_event_enabler_dup(struct user_event_enabler *orig, if (unlikely(test_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(orig)))) return true; - enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT); + enabler = kzalloc(sizeof(*enabler), GFP_NOWAIT | __GFP_ACCOUNT); if (!enabler) return false; @@ -502,7 +502,7 @@ static struct user_event_mm *user_event_mm_create(struct task_struct *t) struct user_event_mm *user_mm; unsigned long flags; - user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL); + user_mm = kzalloc(sizeof(*user_mm), GFP_KERNEL_ACCOUNT); if (!user_mm) return NULL; @@ -662,7 +662,7 @@ static struct user_event_enabler if (!user_mm) return NULL; - enabler = kzalloc(sizeof(*enabler), GFP_KERNEL); + enabler = kzalloc(sizeof(*enabler), GFP_KERNEL_ACCOUNT); if (!enabler) goto out; @@ -870,7 +870,7 @@ static int user_event_add_field(struct user_event *user, const char *type, struct ftrace_event_field *field; int validator_flags = 0; - field = kmalloc(sizeof(*field), GFP_KERNEL); + field = kmalloc(sizeof(*field), GFP_KERNEL_ACCOUNT); if (!field) return -ENOMEM; @@ -889,7 +889,7 @@ static int user_event_add_field(struct user_event *user, const char *type, if (strstr(type, "char") != NULL) validator_flags |= VALIDATOR_ENSURE_NULL; - validator = kmalloc(sizeof(*validator), GFP_KERNEL); + validator = kmalloc(sizeof(*validator), GFP_KERNEL_ACCOUNT); if (!validator) { kfree(field); @@ -1175,7 +1175,7 @@ static int user_event_create_print_fmt(struct user_event *user) len = user_event_set_print_fmt(user, NULL, 0); - print_fmt = kmalloc(len, GFP_KERNEL); + print_fmt = kmalloc(len, GFP_KERNEL_ACCOUNT); if (!print_fmt) return -ENOMEM; @@ -1508,7 +1508,7 @@ static int user_event_create(const char *raw_command) raw_command += USER_EVENTS_PREFIX_LEN; raw_command = skip_spaces(raw_command); - name = kstrdup(raw_command, GFP_KERNEL); + name = kstrdup(raw_command, GFP_KERNEL_ACCOUNT); if (!name) return -ENOMEM; @@ -1704,7 +1704,7 @@ static int user_event_parse(struct user_event_group *group, char *name, return 0; } - user = kzalloc(sizeof(*user), GFP_KERNEL); + user = kzalloc(sizeof(*user), GFP_KERNEL_ACCOUNT); if (!user) return -ENOMEM; @@ -1874,7 +1874,7 @@ static int user_events_open(struct inode *node, struct file *file) if (!group) return -ENOENT; - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = kzalloc(sizeof(*info), GFP_KERNEL_ACCOUNT); if (!info) return -ENOMEM; @@ -1927,7 +1927,7 @@ static int user_events_ref_add(struct user_event_file_info *info, size = struct_size(refs, events, count + 1); - new_refs = kzalloc(size, GFP_KERNEL); + new_refs = kzalloc(size, GFP_KERNEL_ACCOUNT); if (!new_refs) return -ENOMEM;