From patchwork Fri Sep 2 02:30:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12963571 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 20A43C6FA83 for ; Fri, 2 Sep 2022 02:30:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE33E800A2; Thu, 1 Sep 2022 22:30:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6B848008D; Thu, 1 Sep 2022 22:30:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86DF7800A2; Thu, 1 Sep 2022 22:30:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7506B8008D for ; Thu, 1 Sep 2022 22:30:35 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5880E1405D3 for ; Fri, 2 Sep 2022 02:30:35 +0000 (UTC) X-FDA: 79865566830.12.9D417B0 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf14.hostedemail.com (Postfix) with ESMTP id 2421B10002B for ; Fri, 2 Sep 2022 02:30:34 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id q3so722117pjg.3 for ; Thu, 01 Sep 2022 19:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=eAg0PZWl4zJUTIoBr/3Gv3urgLIcQ4VDCzv1IFZNeuY=; b=Gy+cv6XxxiYO3hr3Muw+hBZMy0efagnoQa+lkQO0z4mGYIW5CA1XBEpuraxfeAkfxK G8jIecWEoNFtvzfvGj7MUoaQaJt6vAiOKaeeaE0MPYK18/zDhN7V4FvEnghuG12f7i8k Wygblna21VTeaQ1/2AbJRacHSL9o97+r1sF9tnGeMEcckZfF2mRzApylow2eQjSffdB/ hmzgT9VOAVh2e1R9frgjc8IuTH7PdBnGqPgwVc5a7Y0hMwIth/hwYmEVonEu1nG6Pnij zqNPwiEXu0QWL90ZfnVnEaOkufmAIS5nPaMLhxm/P9a6FaAONxHMU+n2OSgyMVpdr9Sa 6ayQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=eAg0PZWl4zJUTIoBr/3Gv3urgLIcQ4VDCzv1IFZNeuY=; b=BqECOMosXRjpnSuqsURU/r6JYvLIhgrFrdyggzSkEjf3T5oW3PRtIrcn6Fvd1Z5kOm czZxGqOiujQgE0f0Mi4Q3T1ORZKiPV0DJX9iIYSc7L9dMXWEGbEoSUkQmZYhC7/BXoD2 m2QdNWF+L8h5i0xTkNemqJWlbSb8aaYpkaqs3zsMLFukbO9IIsjTQHgF5k7a85gyq+ov YVWJXhpv5dVmRAMnUNRbJxdYrplkBiCqZ/SKPRBDd57eCUiLEefiUX/8So/NoMCkpc9Q sEzQcGAKUGjwQSWextE9s8XH6HEkHS00K7eU4A7pkPUAVmKHKzjAxarxMxu66PQtOj0k GZdQ== X-Gm-Message-State: ACgBeo13YTKb5Vm+ptCvvUQRTyRD0E8+g6rRgUPv7Sx2CFQscpIa/3W0 puMPK/Z4O8roKWtQK5xyqpI= X-Google-Smtp-Source: AA6agR4DsBfz/UK1tZcnfi/DCBBeE+JJsSZfcGsqqa8xiOuQfkFBNrN6XShqRSgVYStdq2UPWrbWLQ== X-Received: by 2002:a17:903:2284:b0:174:8681:3f6e with SMTP id b4-20020a170903228400b0017486813f6emr25252605plh.5.1662085834206; Thu, 01 Sep 2022 19:30:34 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:50ea:5400:4ff:fe1f:fbe2]) by smtp.gmail.com with ESMTPSA id j4-20020a170902da8400b0017297a6b39dsm269719plx.265.2022.09.01.19.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 19:30:33 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, songmuchun@bytedance.com, akpm@linux-foundation.org, tj@kernel.org, lizefan.x@bytedance.com Cc: cgroups@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, Yafang Shao Subject: [PATCH bpf-next v3 11/13] mm, memcg: Add new helper task_under_memcg_hierarchy Date: Fri, 2 Sep 2022 02:30:01 +0000 Message-Id: <20220902023003.47124-12-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220902023003.47124-1-laoar.shao@gmail.com> References: <20220902023003.47124-1-laoar.shao@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662085835; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eAg0PZWl4zJUTIoBr/3Gv3urgLIcQ4VDCzv1IFZNeuY=; b=Ec7D0aqBEJMxAAPcynr+6N0/B35oNU0Hfdp+proLxnrA7M7p0r1VZwRZ15pFnAxCZG4+Qq 9IIQrq/zLAFJCzm5Vg+Zw5xTb+0tSLvRo0ASYN8vi+L9bw+wzDY9s3IR5oEWM8J0UH/ZVV UCWWSLBbl2VvOqqMq4Q3Y3LxO1bw27E= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Gy+cv6Xx; spf=pass (imf14.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662085835; a=rsa-sha256; cv=none; b=lUqXIRJOEyWIh5GPoLBvY1hc13ZCJdQm+9y0zbsa+CYc7D72doa0ib7bxi9chcBWTlZVg1 bQAws8e0GEQlfoerfj/Pvs0lGwJQuXq1mv9AhE7U7J+zHiB19yGTY+ZIm9KkYcwazHZs+E VFg5Ji4Y9bBoj8mUBnLzssECsAVuhZI= X-Stat-Signature: zprsfw61zcycfnx1hyphtro6b5fj6pj1 X-Rspamd-Queue-Id: 2421B10002B X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Gy+cv6Xx; spf=pass (imf14.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-HE-Tag: 1662085834-428051 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: Introduce a new helper to check if a task belongs to a specific memcg. It is similar to mm_match_cgroup() except that the new helper is checked against a task rather than a mm struct. So with this new helper we can check a task directly. Signed-off-by: Yafang Shao --- include/linux/memcontrol.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 7a7f252..3b8a8dd 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -887,6 +887,20 @@ static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg, return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup); } +static inline bool task_under_memcg_hierarchy(struct task_struct *p, + struct mem_cgroup *memcg) +{ + struct mem_cgroup *task_memcg; + bool match = false; + + rcu_read_lock(); + task_memcg = mem_cgroup_from_task(p); + if (task_memcg) + match = mem_cgroup_is_descendant(task_memcg, memcg); + rcu_read_unlock(); + return match; +} + static inline bool mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *memcg) {