Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp613995lqh; Fri, 31 May 2024 10:46:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWS8TOGw4u1JYfXvBJLePULgQ6u+8DvbXm67CRMTxUDqzoIwpUp1OxsRBpuQ4KSJwMgN046alD84LE5i1uv1OXyBy7W79wGbq1bInsO2A== X-Google-Smtp-Source: AGHT+IHgVIcuTnFtyIhHa4+zgJ5+ZLiiKfpny0oQqbKNa8OzOskNW6GEhHIpkI3riznhUHtLdFBA X-Received: by 2002:a17:902:740c:b0:1f6:324e:4df7 with SMTP id d9443c01a7336-1f6370ce37emr22259705ad.46.1717177591491; Fri, 31 May 2024 10:46:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717177591; cv=pass; d=google.com; s=arc-20160816; b=umdyRwzdDA+9BQamPP7pbmw7LMyBQ/6ckAzU2RqoykkXU4bYkzHpPURf07RZQ26geb WOojvTyDTfHtKTZkb183EozKP5ODIA9aXeTTE9pJBBWdwxxy8lhxiBjqR+zVMGoUTGPV Wv7vfJscChxJtrGEc58lvrdkHNrtdOMidYWJQISKmYVpI8Kob+7dBd0no3uTT9yCeHQA lab7jCDU1Y7h8n1OcYWa4wFj8U/rOH0FR3FYIIkXUBrdtcq+eA0WPdfoL9V4NsIJ5mga grtCjyw2bf6jq3cDwVnIdGIbTghbrFH6+o2ZOKB26yOCeDt4mLRyyDKKmO3/8QaCFmd3 j8gQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=knmodrcY3ruf2qGktj4YBIa4Hu+EWJ5K27FOck3RpeQ=; fh=+zb9mK9TG+LYMBgLf4tHkQmhdRdZWYD430YkLG9YER8=; b=e41+mYsj1tjmEp2F/VAjvQrwkoh+x/pRjvDKoygn3LVujG+YBTm/iY9y9yddzmdILs kVbmf3VZPYBpPkaVi7VkoG9VfXHIDKxtnRTB09ISR66myJGDzrO+tWeFrY1Se9NPXN+V iD77ySmzb6Zc0aBsRgmLMzJvdEDi80bi+5MJSPxhQLDZlZlJf0zsLrNVCXEHWa3fx6ET N8YBg+NjnU+J6BlQphFim4kIY7No48fbxy/DuzADfQL6fyiNaFzlp8yrRO4+cXkMpFoF VgZfVmWKOjnXz1xfzsT5mJF9YEBkoM7bh0cE7UbW60oBS43EcDKG6pA7CnSLnA0YFBDg 2Ygw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1w8vZTdk; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-197244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35c73b829si1934756a12.730.2024.05.31.10.46.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 10:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1w8vZTdk; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-197244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 162CCB26DBC for ; Fri, 31 May 2024 17:18:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F045A17C233; Fri, 31 May 2024 17:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1w8vZTdk" Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F0B755E4C for ; Fri, 31 May 2024 17:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717175919; cv=none; b=HQaQ+tPePpPrjJzEp+obqwlA9eINqRQrN1k5bg3hTVT2BbT9aiJrU10092cuku2vYZtUr5YbQ6Ihqx/R7Dl1IZj4fB+buav1zBWKuA0CrjEIdfVY405Gnem7854lYQ+/HvXUwxDniiaFBySn0LFyOFQnW2Pnyv2ABBHVCyFJTvY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717175919; c=relaxed/simple; bh=DS0hDZfNJZkkzFy8Yct62SEoWnrdxNIojjUrc12e2eA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UZduVcogQYE/3StwGy6tX97tB11IBfgdAchgRo68xS+t+C93T7rqyvjzxcKEECQsR1XB1SDBhU9dDOyFMT6YDfXJTcZwkgbWeXWbj29LpSk6dxLmEYZp05H7hFiM5xty1vt6lWZYNtMjanGrXBJ19oUq3jfWfq2palri9PO7Fq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1w8vZTdk; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a63359aaaa6so289252266b.2 for ; Fri, 31 May 2024 10:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717175916; x=1717780716; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=knmodrcY3ruf2qGktj4YBIa4Hu+EWJ5K27FOck3RpeQ=; b=1w8vZTdkn+mPNnfeaWCWFNEU2c0f10pXctds/U0m7HG321kIqRwKj7ZzOISd/4CFbo 0Qbb0C43thFfBQ/XGsE/onPkA/f7t8pi9JWwq1JN8Ngl7X+ruw3hQmfOFiWhqsLnNzS5 OBCvVAbg9a+tQoCO/5ggZt+VwHVs9xnzRtUXiMEaLuNMklAk7CBhnWORDhd/Q9S6vygi GD6Qyz6ucJSPj0Y50j1WL+MF4Wnki2JP35aph5oXkc6X8OzyQawOa5tNM/6FBQ3wGLb7 t3918HXF74NBmQ07gKJ+4DcgFiL3pjccK6f0wXtM7U3pLLAuYavoR900EBrtbxehHdtq P58g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717175916; x=1717780716; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=knmodrcY3ruf2qGktj4YBIa4Hu+EWJ5K27FOck3RpeQ=; b=VtSVTLV7BdY3Hu/xLOwyrQCnqYS+NeIkVjwDpSmydCenPwEJcM8kSZxtAG10qwiZ5C EuV1PRuzcEAalJ2reTMTXd0ZDSPnG4DHIUekICYjpUYdynh06+76FRy3yr9OhTv/Pbf3 gz3PyHRT7jYsHZEhtiG2EoYsYDHIK9sG2ER3+G/oo7LqvC6In4b32NTsgHKeKx1vn0e1 zyggT5cS/sblgkumoEDcWpogeWvQXVrH20Npc9Cf1RGDTe9wuQVyhTsp/zrp94QcqLV0 S4ex2fwdB9+vaRsdj2UCz/kvEdTPkgVRLNE4V605ilwKZVznOVm+fEEiP8WERbsnNnXH EZUQ== X-Forwarded-Encrypted: i=1; AJvYcCUneiFP2BafVh5wnyQNJqkzU6jJQtYBT/qmFi9ztm9tyuNE6xuknJJ0G8qjUFgeJsRdM/Oa2SzJv1QMIkhFuzeoLZ7jrlKpGFhoqPTJ X-Gm-Message-State: AOJu0YxeaLvdBdXk9pAZv1f05MrKoP+XEBa0CKg2lSHzYYgKIgEh8Bhd ZXAkpIU2Brg/tD6FxonmmbSv469RIpefF2HKLgyVvXDzQsvj3KpOr+7GYW+2O1vHN2JFd85GaR6 ZNMUrmywm+5HrK0FF1CVA49oLz8dQls3dMC3G X-Received: by 2002:a17:906:a1c5:b0:a67:b440:e50f with SMTP id a640c23a62f3a-a68224472c9mr177860866b.63.1717175915378; Fri, 31 May 2024 10:18:35 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240531-fault-injection-statickeys-v1-0-a513fd0a9614@suse.cz> <20240531-fault-injection-statickeys-v1-3-a513fd0a9614@suse.cz> In-Reply-To: From: Yosry Ahmed Date: Fri, 31 May 2024 10:17:57 -0700 Message-ID: Subject: Re: [PATCH RFC 3/4] mm, slab: add static key for should_failslab() To: Alexei Starovoitov Cc: Vlastimil Babka , Akinobu Mita , Christoph Lameter , David Rientjes , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Steven Rostedt , Mark Rutland , Jiri Olsa , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, LKML , linux-mm , bpf , linux-trace-kernel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 31, 2024 at 9:44=E2=80=AFAM Alexei Starovoitov wrote: > > On Fri, May 31, 2024 at 2:33=E2=80=AFAM Vlastimil Babka = wrote: > > > > Since commit 4f6923fbb352 ("mm: make should_failslab always available f= or > > fault injection") should_failslab() is unconditionally a noinline > > function. This adds visible overhead to the slab allocation hotpath, > > even if the function is empty. With CONFIG_FAILSLAB=3Dy there's additio= nal > > overhead when the functionality is not enabled by a boot parameter or > > debugfs. > > > > The overhead can be eliminated with a static key around the callsite. > > Fault injection and error injection frameworks can now be told that the > > this function has a static key associated, and are able to enable and > > disable it accordingly. > > > > Signed-off-by: Vlastimil Babka > > --- > > mm/failslab.c | 2 +- > > mm/slab.h | 3 +++ > > mm/slub.c | 10 +++++++--- > > 3 files changed, 11 insertions(+), 4 deletions(-) > > > > diff --git a/mm/failslab.c b/mm/failslab.c > > index ffc420c0e767..878fd08e5dac 100644 > > --- a/mm/failslab.c > > +++ b/mm/failslab.c > > @@ -9,7 +9,7 @@ static struct { > > bool ignore_gfp_reclaim; > > bool cache_filter; > > } failslab =3D { > > - .attr =3D FAULT_ATTR_INITIALIZER, > > + .attr =3D FAULT_ATTR_INITIALIZER_KEY(&should_failslab_active.ke= y), > > .ignore_gfp_reclaim =3D true, > > .cache_filter =3D false, > > }; > > diff --git a/mm/slab.h b/mm/slab.h > > index 5f8f47c5bee0..792e19cb37b8 100644 > > --- a/mm/slab.h > > +++ b/mm/slab.h > > @@ -11,6 +11,7 @@ > > #include > > #include > > #include > > +#include > > > > /* > > * Internal slab definitions > > @@ -160,6 +161,8 @@ static_assert(IS_ALIGNED(offsetof(struct slab, free= list), sizeof(freelist_aba_t) > > */ > > #define slab_page(s) folio_page(slab_folio(s), 0) > > > > +DECLARE_STATIC_KEY_FALSE(should_failslab_active); > > + > > /* > > * If network-based swap is enabled, sl*b must keep track of whether p= ages > > * were allocated from pfmemalloc reserves. > > diff --git a/mm/slub.c b/mm/slub.c > > index 0809760cf789..3bb579760a37 100644 > > --- a/mm/slub.c > > +++ b/mm/slub.c > > @@ -3874,13 +3874,15 @@ static __always_inline void maybe_wipe_obj_free= ptr(struct kmem_cache *s, > > 0, sizeof(void *)); > > } > > > > +DEFINE_STATIC_KEY_FALSE(should_failslab_active); > > + > > noinline int should_failslab(struct kmem_cache *s, gfp_t gfpflags) > > { > > if (__should_failslab(s, gfpflags)) > > return -ENOMEM; > > return 0; > > } > > -ALLOW_ERROR_INJECTION(should_failslab, ERRNO); > > +ALLOW_ERROR_INJECTION_KEY(should_failslab, ERRNO, &should_failslab_act= ive); > > > > static __fastpath_inline > > struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, gfp_t fla= gs) > > @@ -3889,8 +3891,10 @@ struct kmem_cache *slab_pre_alloc_hook(struct km= em_cache *s, gfp_t flags) > > > > might_alloc(flags); > > > > - if (unlikely(should_failslab(s, flags))) > > - return NULL; > > + if (static_branch_unlikely(&should_failslab_active)) { > > + if (should_failslab(s, flags)) > > + return NULL; > > + } > > makes sense. > Acked-by: Alexei Starovoitov > > Do you have any microbenchmark numbers before/after this optimization? There are numbers in the cover letter for the entire series: https://lore.kernel.org/lkml/20240531-fault-injection-statickeys-v1-0-a513f= d0a9614@suse.cz/