From patchwork Fri Sep 29 18:00:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13404694 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 A7973E728CF for ; Fri, 29 Sep 2023 18:01:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 377FF8D00FC; Fri, 29 Sep 2023 14:01:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F86E8D002B; Fri, 29 Sep 2023 14:01:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 197D18D00FC; Fri, 29 Sep 2023 14:01:35 -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 04CD08D002B for ; Fri, 29 Sep 2023 14:01:35 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BA3DC1A0C6A for ; Fri, 29 Sep 2023 18:01:34 +0000 (UTC) X-FDA: 81290402508.19.372D015 Received: from out-209.mta0.migadu.com (out-209.mta0.migadu.com [91.218.175.209]) by imf07.hostedemail.com (Postfix) with ESMTP id 0A2D94002D for ; Fri, 29 Sep 2023 18:01:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=odkLZGFv; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.209 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696010491; 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=bqAmBYeSm88vV592hWQme0xomIuCkHPF6mqJGonRv8FRCJZyZx9EGDEph2plCd5zJwAXvM 9dAJ2O1Yteimwml54Pp5CfOQ5xGSf6yNoz0ecUPiLGYVnK2D6N+T0vPEs05/Ns5OAmHqFC dx9XRqF4SDC2QzSLxGK/AV8+oUVcEBI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=odkLZGFv; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.209 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696010491; a=rsa-sha256; cv=none; b=QNjo9QZPQ0keJkdZAOCcfJmNA46cdmm7lSUIQn8WkjO+uyjx8ufaE9P6Ey+Ofd7KwFR8bu IbhpfnKzXxZ6fjXx5tJithuL0ZiQ7Bvj8HWnk1ftWDGtZIZh8QMrCR6ICAOvXQRZKzlm4P WMWglvet2pUR/EpwYT3+QK3pX3xwOyY= 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=1696010488; 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=odkLZGFvcc5TTuJvilLKehHXRk/B6mY4ABoJ1wkhqpX6hgrcQG2DXR/Xkyfy/HGnDasNt6 5JRdpKxIA1lbfyIu/AkdURXUJc8ZL7aiQApQLkXhhdoWIzk+PAht+vVeY3dVj+R1otYNom anh+3HHhyLLzhbFfFWBmw6+6M0/vXGg= 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 , Roman Gushchin Subject: [PATCH v1 5/5] percpu: scoped objcg protection Date: Fri, 29 Sep 2023 11:00:55 -0700 Message-ID: <20230929180056.1122002-6-roman.gushchin@linux.dev> In-Reply-To: <20230929180056.1122002-1-roman.gushchin@linux.dev> References: <20230929180056.1122002-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 0A2D94002D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xk1htk1sesu1cwtdj4p7kj9q3bbn3jhb X-HE-Tag: 1696010490-817409 X-HE-Meta: U2FsdGVkX18TFCmK0c1FOOPl1D7Ln+YzH+W1b3fL2vG5c3Diivkm8EsxYG0onJn3rl4BmClBqlSe/HTa+Mi4WL4WPtjKQ1GFww8ElYm7iAy/zpJ684/LecCBnKN2uUZm41OT1TYPswM5osIxblPIPfcH5wrloJCjWFic4O2wzCh9Kj7w/GXjaY86OUX6k9pOa2iwbyV8Hy1Pot8r3yrJ0Gfa2ZWkDYpiktAQqehDzPHqNPUHAL7O5KkWvUaClXHV0wKQrgrkpWcnWRiVIO0MwNjm448saQTiXNStJuLJpZTo1yByJMq23BqClzjDVL0MbmSKFjfASsVKk9ZEIupRZNWwmnoFrlGwAojpSss5Wvch2HU8LZqs+Sx7iU9J9BT3MR8RNgrA8/xnFbzKY6pZxBYRsodr2AxetDQ5axRgJKnfB+ZAZJbn+GpMbGxLmurvsCtqCLsOjFceYYYRUtxBr+7Xc79/mg9MS/1cNGaKV394hwzmmGvxj2PSOgkuDVUc9t5vx/qrHTAW0+Ye1wM2M9trxLCXMQHqk3BQOq76ptHPzblR/t+UVg501as94pWj/b4X3EJZxgjTDJlK2mB3iHjEpylDV/WoNRZTopsW24lSKMCJlZAgw7Go9+c0NMoVrhuWk1bN9WNA4G78tlk72IA6ovgmR56oRdT/mR3od5sGYjbZX+sbEMRWN1f9zt7BYBW7tO9qravhQrNd5IYZUlp+T1MOZJlb+xUICGNLEpcSJzVlq3Hp/+PDpsUzAIzeFFQE7WdxtSPM0thujJdabPfA0NzhIEK7ttnGkAIKREA9/W8duxhjwXdpEN4EPriDHCW0wVgN+ZjsuP5oynCU560hcq58LJN0zdbu1qYI/DDsQ9NjeirqGwlncD/rcN22oNnwGyeBwQ0U0nyi0XdPfPtDgOFtsPKkXtwX5BkueZq7X9vy5YTm9MGx1IzADc6DUWLQqWdR57MaQsQLUIm 0+58AiRO uOeuZiN9Tf4f0Apt3Y4J0ZVodIIV68KauPK4Gm1jZVybhuuqGJaczlaCEDbwr/JERDrJk++kM0UiQh5o= 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) --- 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); } }