From patchwork Wed Sep 27 15:08:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13400991 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 CE5ABE82CA5 for ; Wed, 27 Sep 2023 15:09:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEE956B0170; Wed, 27 Sep 2023 11:09:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9E3B6B0171; Wed, 27 Sep 2023 11:09:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A23D6B0173; Wed, 27 Sep 2023 11:09:07 -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 792766B0170 for ; Wed, 27 Sep 2023 11:09:07 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 589EA1CA295 for ; Wed, 27 Sep 2023 15:09:07 +0000 (UTC) X-FDA: 81282710334.30.DF7DDD2 Received: from out-193.mta1.migadu.com (out-193.mta1.migadu.com [95.215.58.193]) by imf20.hostedemail.com (Postfix) with ESMTP id 8E7C01C0037 for ; Wed, 27 Sep 2023 15:09:05 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="V//ihQR3"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.193 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=1695827345; 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=u3h/o7QMIzE34e2/fc8FZtY4cwSdIrXuMT4WUD6NJ44kEiGnteAXkDwJ89OB0UzdnhfkNV Ns9m3RWpSKKzfGjmIWUwEa8r6aWl+E+OY3FSsx6Mfj8NCUxWVPcB+OlirWIQjNfqLYkR76 XP3pFGHRRqyrMMmeXxJNs+CInDHOS3U= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="V//ihQR3"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.193 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695827345; a=rsa-sha256; cv=none; b=n99dq8lyPdfUbuJR3Ooe5eRbT0JsK6V+e5HaY5pqc7Bh4qWOT3ibTtfax5OQWDHwxbM+D6 WBhbmpOrL26jR5CCtz/P1I2Bl3br6sGHv718CtvV/F7M7tqIh+1M5li6Ad32TECXs0j6qN SxN3jNAW2uL1T7hT4dR5ahLoJ0zHhLA= 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=1695827344; 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=V//ihQR3BNX8mCaIN2RHbsj24ybf5tsZR80ZurjIq/P4zdNE6/CNiqXGaUHELfnQzFCvFu ald/Rulhzhr/xKdfWTbsCyE4U6wbBWcnVys7yuOgrgVNmXQqA6dKbwvtqUzJLSfKLVSbkz VEv/GP4pB24vCqh16SVt3PIzQgO5+VI= 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 , Roman Gushchin Subject: [PATCH rfc 5/5] percpu: scoped objcg protection Date: Wed, 27 Sep 2023 08:08:32 -0700 Message-ID: <20230927150832.335132-6-roman.gushchin@linux.dev> In-Reply-To: <20230927150832.335132-1-roman.gushchin@linux.dev> References: <20230927150832.335132-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8E7C01C0037 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: k7ncptu5tsh1mi98zkpuuwu36b1g4zzm X-HE-Tag: 1695827345-936086 X-HE-Meta: U2FsdGVkX1/YylXs6eJ5ZxZwozrCjlhcXuu/5k7R0jnFU59s+IwDQRuiXNUjfyO4FU1ylBxO9zy6GEKS+vknB2biaqfzk1UsulksaLCpXFLEaiI6F8HbX2vKK7Q4vgW2hw976AvyvUYR/bW11QX/1C4pKQK6QFURiWeZDEN+aPkCmbwCwXqbhQsiZ8D77yPlP8fx8Nv1nWFvm0ZSIT4DYwJChWl35lBRhnuZIJ40MYT2D/Q3ZF6edZuF6DKss0g3fCgD7KBrAygrXl17POaubGy6BnUgW24qQoVemFuckDp99sMRZ8Kifp0zM+Lk17etoIRUH5I0cyNijiVumsGOInIiyWsbAj6DKQ3HJxHs0rV+TVX3sw7GJQLTVloawKJuX7O4ITLYfWUj8m2rMHp6vi6SNEUih/jjr0Mrc2DeI9IzBN6LMqO23oNcxkTY9BK9gewGZSwntla8M7sNz28MJKKpul8c5CnQtODDuxTvfhjWpzACq22elgx7OtgIWGDw7sHyVY3h7akmMkwU8d6A11dgdt/cvdz3f9e1dClOx3WLfPaINNYDErLUmeQiFUU8EC9BaGXjsAJd4XdPzqEJheQ0dNHpyw/Agd6AVbNmx8ia+9S8jhJ4Xy+AujM0lVt1ggORlvyuBaFAJFnoZ8mRpSdJ3m6haPJSdjoSlzB2GCntmUhlwGvo+oQqNZQBI1+450yF/xYAmxCDIhJZ17VedNpSLZXMu6L9lbm675GuBl6HVYiqRcgUK33O2tuVbQdx9kCSQJGaQb14nhIbX9kVFl3ovgbq6ChufxFbwpFrNvqYH5D9ydMO1ho+rFSwEOFwicYXC0ql3p4S2IHMQ8JTmhHTkSODhSVETm2SamwCFVnArE+gsV0IIx6Fg1MegLhkMmGpjMDH856yv3lJOWtsxVdi87QvKoxiyS1A0I5CADZsgs1TjJB2XNU7CHY6I0Ygzv+u8DpShdXRe8QlnOk 8IEW0f5b 6kz+KSTYJkzyzFLZpkIFlmvyckBEmnYLC/Z+CfgF7qKFl42yqz87gg53ZMSWWNJlQ+7W3QRh5s39WycM= 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); } }