From patchwork Fri Feb 12 17:01:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12085693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16AC4C433E0 for ; Fri, 12 Feb 2021 17:02:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A110764E39 for ; Fri, 12 Feb 2021 17:02:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A110764E39 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DCBFD8D0070; Fri, 12 Feb 2021 12:02:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D31F18D0060; Fri, 12 Feb 2021 12:02:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5F7F8D0070; Fri, 12 Feb 2021 12:02:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 909B78D0060 for ; Fri, 12 Feb 2021 12:02:26 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4135818039797 for ; Fri, 12 Feb 2021 17:02:26 +0000 (UTC) X-FDA: 77810234292.19.vase58_0416a7d27622 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id E67AA1ACC35 for ; Fri, 12 Feb 2021 17:02:25 +0000 (UTC) X-HE-Tag: vase58_0416a7d27622 X-Filterd-Recvd-Size: 3826 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 12 Feb 2021 17:02:25 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id gx20so765845pjb.1 for ; Fri, 12 Feb 2021 09:02:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uMiCMlqqsGt4v3DIDBbc5Tzpa+oMrTR3N8I/PD9p2nk=; b=NmStyGwgQEnVNrqN5Ubtgd25sYfpL8IXtOClOXbtc4s/sjMIQFqvb31t0DYjJZidM1 gCU3y8v0DWb3bByea+46x2tO/zxaZI0DLjF8Y1CVsBZu6wD68sRHZXdAlzW5+0pqOwTT TM3Jb8qnl9xOL4mWSIZj8Q1QL2ERlMxEY4F9uzUa1wjlotEQZKxZVjviz3OXd8WsF/Rg jFVabi1XtYlsOwbqnSNgovnWpCfmsOpZKBCmrxZU1f8vkqYrTp2sVvrX738HsEIw8MFn blBu6Yfthn9vxzvgemOvsKgO0ZWZHZw99ZIC5oXvfM3NPLKZaY4jXeVvJfxkeLuu24Wy 6/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uMiCMlqqsGt4v3DIDBbc5Tzpa+oMrTR3N8I/PD9p2nk=; b=oIfIxWwNyVtuqc8JTqEVyq+ei+0911WTHeA8oU7zQidLpQ9SyW0bSf7s1MX+R7nWCq VQirhyPfITa3Pn6i/CjtGkak4GDm/jaXoHr7l1z3bIplnhiQptRP3omr/P0VVv55wBvB H66IheBoi273mQd0hXMyVMwZxXVnMkviI+XET9yHYbXva/4w6sgxcqP8Nh+/wWU1r356 JOpNOLqxIZkqK57azWBC5fAnkPsO+2NKClO/jiFKXWFcGkTQpy6tYgOCcB3m5/KsyM58 aSuVEJmb+QWySPW2j4rgqxsaGjbKH0bZb48w2WqVB3CrwbyDgMgVyUo1HjjqXcsdEhI4 9bGQ== X-Gm-Message-State: AOAM5321gOSyy7xdCxZo0sFPokuoXegI/T/kzxb1wyUfvXWLvghyGpDB 2mvQoAD82waGsXP1JlnLFQIB7w== X-Google-Smtp-Source: ABdhPJzNZ8r1f8u/Wzepj9mLIFlxDAW2JOdq6rVUNEpN5TjGRjw0rdpCvkeGjJveQHXo8f+etJVqEw== X-Received: by 2002:a17:902:d886:b029:e1:7784:4db5 with SMTP id b6-20020a170902d886b02900e177844db5mr3677168plz.72.1613149344235; Fri, 12 Feb 2021 09:02:24 -0800 (PST) Received: from localhost.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id e21sm9317815pgv.74.2021.02.12.09.02.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2021 09:02:23 -0800 (PST) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 3/4] mm: memcontrol: bail out early when id is zero Date: Sat, 13 Feb 2021 01:01:58 +0800 Message-Id: <20210212170159.32153-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210212170159.32153-1-songmuchun@bytedance.com> References: <20210212170159.32153-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: The memcg ID cannot be zero, but we can pass zero to mem_cgroup_from_id, so idr_find() is pointless and wastes CPU cycles. Signed-off-by: Muchun Song --- mm/memcontrol.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a3f26522765a..68ed4b297c13 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5173,6 +5173,9 @@ static inline void mem_cgroup_id_put(struct mem_cgroup *memcg) struct mem_cgroup *mem_cgroup_from_id(unsigned short id) { WARN_ON_ONCE(!rcu_read_lock_held()); + /* The memcg ID cannot be zero. */ + if (id == 0) + return NULL; return idr_find(&mem_cgroup_idr, id); }