From patchwork Tue Oct 10 00:09:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13414699 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 32F84CD68E3 for ; Tue, 10 Oct 2023 00:10:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAB4D8D00A2; Mon, 9 Oct 2023 20:10:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5A9E8D0089; Mon, 9 Oct 2023 20:10:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFD338D00A2; Mon, 9 Oct 2023 20:10:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B8A808D0089 for ; Mon, 9 Oct 2023 20:10:13 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9894EA0419 for ; Tue, 10 Oct 2023 00:10:13 +0000 (UTC) X-FDA: 81327619506.29.810500D Received: from out-209.mta0.migadu.com (out-209.mta0.migadu.com [91.218.175.209]) by imf17.hostedemail.com (Postfix) with ESMTP id DD3E84000B for ; Tue, 10 Oct 2023 00:10:11 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ZGPVwiM2; spf=pass (imf17.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.209 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696896612; a=rsa-sha256; cv=none; b=lmDhRrOh40Wcc+VFdpupleiJftHCI2ls7MI5UA277lixZxubj2ERWtGeJruzeSPuDjdctx INL/+PdEGwUNHz2mKjkOaYbC/ms+72JDuPshz20vGePa6VzFufxPUMVALF6StU7BsUpKGN 1m9AxpxztdtZsw6T9+vbdhcfP2yaoC4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ZGPVwiM2; spf=pass (imf17.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.209 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696896612; 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=j6TjL0tOzMm9uw8Y9niPXJ1ezOtPxfS6WilpL+cESRE=; b=IpKy8a/umieFGQl7DwUixB2uz7DQYTw5Bm44VxJeOz3a5QegMzRocrlsEDmCINpDIPc/I4 +MCdOpSABh826dRsQLxFvS6Vq6iMjmAnLQIX1v99i8Rp2xhh0q5NCLJA8T8f3VaoVF4XHr 9qyUKhVo67kQtqb/HnyDdawie/TOCN8= 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=1696896610; 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=j6TjL0tOzMm9uw8Y9niPXJ1ezOtPxfS6WilpL+cESRE=; b=ZGPVwiM2h+XunCiZLqM4FyYGsiSKjC0phq0S+wyUEtVkyO+vvaGmE0lOyAzfhgRkZqIQVI z+aLmjDpmuOiL6ag53Op+5oV0AIkM4FSmAvmbCqi/H5wKmFVEnAUYzw7h9+t++JC6EK5WG wCu/Uex1P/e7AHO9YRFh11WGzRmaLv8= From: Roman Gushchin To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Dennis Zhou , Andrew Morton , David Rientjes , Vlastimil Babka , Naresh Kamboju , Roman Gushchin Subject: [PATCH v2 5/5] percpu: scoped objcg protection Date: Mon, 9 Oct 2023 17:09:29 -0700 Message-ID: <20231010000929.450702-6-roman.gushchin@linux.dev> In-Reply-To: <20231010000929.450702-1-roman.gushchin@linux.dev> References: <20231010000929.450702-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: DD3E84000B X-Stat-Signature: banmq63wrodjqtxfkd9scftkuqxukg34 X-Rspam-User: X-HE-Tag: 1696896611-690962 X-HE-Meta: U2FsdGVkX1+3eHeR4HXqwwWWZzpWRnBgh7VNJUvdCm/Lt7zw1m/s1SEkPjzmdnbi5wWmHEt8bo/Fq922RNiNd2GA/EzO3+u4TLmEWowoihQ/m1FW95zRZP0V6yWQoVNBsyY405nIu6Ke2zIVtpNBgIdsvrr/umTYSyukJdxb9WmRlxCZmsnsYfxiWl+meEniCJZbKR4DThu91megWuX+nF3cN65q5SX4+E1amEMhWiB12rrIm6Hz3ETolBzYD+Tlf4M7ZCWcI19bPr6QjO4omh21cvOpseeDuMK8OT3JYiUAhyRjXLV+os02PrGMkPhtLP97qKGG13eeO/yzyZhHcSg9w+vVG2UUlI+lo7Yu9En4rB25S4vPSH9BJTbds5M8PRRQEogaWbiNbs2LeTPhmLfezuxgQKzX2ALV2tI3wKbx1AeQ9jVMzlN0swUd9UFnoEG6wOMevIHTi3auq/raTtVgDcd2ppAgz+WGikIND00p9dScIemqaEcG0nLc5AFhN7WafsVjWUMYCB0GUE5FGZCl4GWlUP3bajvgYZDjH4CszJlNDJYAuo/8a2rsr1GczlKkU4tTtY6Wy+ztK8a1v3UHD7kxPbRaC18dnQFuWyvLogIv4Kvmo0M4ei+ojeZ2zdumfNR8qUyC65J20oOKCe14rY0D+dhYRux0UlJDAQsNRttAkeUv1t9wECFIKp2DEuF4dxpuf6pVvFkABglDuRRoSHrK54hVpJLUZL/ZbIERKv6hedMBiX3Qe3Ea+MxL7unbj8aQ870Yej065P8ISrHxgO90ENoU0oeYMzOeYYcPFQVi1TFtWfrc7jD0WnvpvtZ/2fwEVkDUIAROjBlBBmmucFYnedBfP0Z9r6uM8wjjwqXFESPlvCzZ7joslpOMBuMqgzdDFr47ZgpkdEaFpwMi1WknUj99jcXwvkBHOzGY78gSnlLH0pj6kCHGnqLz4x4l5jEsUC3rmowp2lQ ADDfIBv1 VM20BySNeXncDzSgFOE6RYCrBIelD7Rl28yBkmrWvjlvOo+ZBfZrPMcY3RHTu9AhpncLc 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: Similar to slab and kmem, switch to a scope-based protection of the objcg pointer to avoid. Signed-off-by: Roman Gushchin (Cruise) Acked-by: Shakeel Butt --- mm/percpu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index a7665de8485f..f53ba692d67a 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1628,14 +1628,12 @@ static bool pcpu_memcg_pre_alloc_hook(size_t size, gfp_t gfp, if (!memcg_kmem_online() || !(gfp & __GFP_ACCOUNT)) return true; - objcg = get_obj_cgroup_from_current(); + objcg = current_obj_cgroup(); if (!objcg) return true; - if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size))) { - obj_cgroup_put(objcg); + if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size))) return false; - } *objcgp = objcg; return true; @@ -1649,6 +1647,7 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, return; if (likely(chunk && chunk->obj_cgroups)) { + obj_cgroup_get(objcg); chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg; rcu_read_lock(); @@ -1657,7 +1656,6 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, rcu_read_unlock(); } else { obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size)); - obj_cgroup_put(objcg); } }