Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp664543rdb; Thu, 19 Oct 2023 15:55:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGARmQVyST39qmjeOkuFfJwKMOkBrz1yYXF5lnbaOQs1MVvy6HmI0IUz8s3pgQ4Joz3KHMv X-Received: by 2002:a05:6a20:7d9d:b0:161:2607:d815 with SMTP id v29-20020a056a207d9d00b001612607d815mr247135pzj.24.1697756100515; Thu, 19 Oct 2023 15:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697756100; cv=none; d=google.com; s=arc-20160816; b=LS9AJ58jwfT6xWF/iydPn2xV7eU43nXHtl4gLCAEzzdxl/gnJv+0w62ovF4ZG1wG5L xVDDwSyt7FXv+6igfOrx+BLUJVUL6cX5qyrLl5Xk/W3JKjuWJ//mLGzrlaZJZkd2nHOm 4bJLxC/xsozPsc4JjaYW9rFakHZzEjk6zHVblXmSxUaMo8Vfq9PYtXv8wVd4Qkm7LoZw RfQRDuzftWCbxWU+c0hFZbyx701P/VAdUnW1RNvdVxxIUy8oCTw1M/37Ii9IdNychPsb JusRDcy6FcJ5/wrO1LQyvDay8hsZKrWVcDZ/8XaF1Soa2N6dXjSWqEau2TUkLdCFiQYv 56SA== 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; bh=dS7frJRdSMuPJ7DdWWAjQ+cQ8KaRwRE0njPFfiYUqhI=; fh=0sD7u+6ZeVLabXSJ0/ta2yf8mUfUXWwh1sJBhHvFyso=; b=xGYxdvomebr+sZBulrTu2ApRGLU0Folm0o3xP59QNQwYyjllW/8E+HOiagDeZSnnbA qd6mGXb9Qe20x9G376Aup5NQFy1XIYCI9KulPr8jyRXR/Y2kcK9T3q9BdMXTsOAN6IuY GZCPrlAjRjV/QYX0N4gApZyJigukT9gh+3m0q5DRF4IO8WcxEWrPU9apJAWgzk1bJAZH NsqjmalFcWe1NFSuvxUTrE0JJpnKsvsTOOGAW4xngQer53qOkF50S1Zhs+q75KBWmaY9 rfmUas36wn6rBGk6vHrIPbU2n0/UewY5tmx3dI7gZTYTJpEtqCsrTqo73jl3xO4s4maH 6CJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=swiyjDzb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id s21-20020a632c15000000b005acd5108042si576891pgs.521.2023.10.19.15.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 15:55:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=swiyjDzb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 485F1836CE7B; Thu, 19 Oct 2023 15:54:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346737AbjJSWyk (ORCPT + 99 others); Thu, 19 Oct 2023 18:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235553AbjJSWyb (ORCPT ); Thu, 19 Oct 2023 18:54:31 -0400 Received: from out-194.mta0.migadu.com (out-194.mta0.migadu.com [91.218.175.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826E2184 for ; Thu, 19 Oct 2023 15:54:28 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1697756066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dS7frJRdSMuPJ7DdWWAjQ+cQ8KaRwRE0njPFfiYUqhI=; b=swiyjDzbwvO1ryyH0LOxBsG3sRDrHo8MwhzTCH/GhQa+yLHgJt9YruoXPCzep7ToRdRcIe f2eQNq6gGnHGE7yLa7z373yvV6fk04/R4k49Aiuuzgl3U3AyV/OKYwgN/BLnwOmIAr+Hpk tNxwryf0vISlCXMm0JNVfO9Q0ZShvgY= From: Roman Gushchin To: Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Dennis Zhou , David Rientjes , Vlastimil Babka , Naresh Kamboju , Roman Gushchin Subject: [PATCH v5 6/6] mm: kmem: reimplement get_obj_cgroup_from_current() Date: Thu, 19 Oct 2023 15:53:46 -0700 Message-ID: <20231019225346.1822282-7-roman.gushchin@linux.dev> In-Reply-To: <20231019225346.1822282-1-roman.gushchin@linux.dev> References: <20231019225346.1822282-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 15:54:57 -0700 (PDT) Reimplement get_obj_cgroup_from_current() using current_obj_cgroup(). get_obj_cgroup_from_current() and current_obj_cgroup() share 80% of the code, so the new implementation is almost trivial. get_obj_cgroup_from_current() is a convenient function used by the bpf subsystem, so there is no reason to get rid of it completely. Signed-off-by: Roman Gushchin (Cruise) --- include/linux/memcontrol.h | 11 ++++++++++- mm/memcontrol.c | 32 -------------------------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index a89df289144d..ef26551a633f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1778,9 +1778,18 @@ void __memcg_kmem_uncharge_page(struct page *page, int order); * needs to be used outside of the local scope. */ struct obj_cgroup *current_obj_cgroup(void); -struct obj_cgroup *get_obj_cgroup_from_current(void); struct obj_cgroup *get_obj_cgroup_from_folio(struct folio *folio); +static inline struct obj_cgroup *get_obj_cgroup_from_current(void) +{ + struct obj_cgroup *objcg = current_obj_cgroup(); + + if (objcg) + obj_cgroup_get(objcg); + + return objcg; +} + int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size); void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e3d4b7fabb7d..e13c10912c16 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3056,38 +3056,6 @@ static struct obj_cgroup *current_objcg_update(void) return objcg; } -__always_inline struct obj_cgroup *get_obj_cgroup_from_current(void) -{ - struct mem_cgroup *memcg; - struct obj_cgroup *objcg; - - if (in_task()) { - memcg = current->active_memcg; - if (unlikely(memcg)) - goto from_memcg; - - objcg = READ_ONCE(current->objcg); - if (unlikely((unsigned long)objcg & CURRENT_OBJCG_UPDATE_FLAG)) - objcg = current_objcg_update(); - - if (objcg) { - obj_cgroup_get(objcg); - return objcg; - } - } else { - memcg = this_cpu_read(int_active_memcg); - if (unlikely(memcg)) - goto from_memcg; - } - return NULL; - -from_memcg: - rcu_read_lock(); - objcg = __get_obj_cgroup_from_memcg(memcg); - rcu_read_unlock(); - return objcg; -} - __always_inline struct obj_cgroup *current_obj_cgroup(void) { struct mem_cgroup *memcg; -- 2.42.0