Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp471350pxb; Thu, 23 Sep 2021 04:19:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJEed3qDxwQzBvSF1Z3uG2/2Kl/1aRuC3XR0Od6T2XlKP4R99i2G/bAIgG+HQLm4jR2KQK X-Received: by 2002:a50:cd06:: with SMTP id z6mr4851926edi.12.1632395992986; Thu, 23 Sep 2021 04:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632395992; cv=none; d=google.com; s=arc-20160816; b=KGw8ezYFbvIifdB3epfhYhhAqsmqcjvR4xWelisUojII7kRan87kGjIIPgDFlVqDxn ksyisfCRBdusjJl3kuB3Si5PN/NN8wwUo+CbKf5aJ2oHg6nqd1hht4ntL/hp6248Kbsi J0nduPAghB5Bq/xyaAd3epabhPF0Axt3ogY/bm9lEqWxRAR8FcS7ZNtiO38m8l4tNfti k9moxs48xAi/LuLKfh9/YYsRK4ylnfN+oUl8nDD3IyqU4kkBj/u4zNrFj0amp/TIm/Ur NBWAr++ZH8GXyUb4rctbIKdV+PBWpefBA3TEVYShGaUG4GnR4EwFdy0d++XI1UWTLZo9 xwUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WxWyZjqzKABxFGtDm2TtL1V2QPdgvK9G3mFsSj6IZsc=; b=y2eyjuwnqWyysQPdjJoy2ZaQgHVt77uwihpo98ff7Px6NQjN/J4uIiaG6NQjBMXqG1 oB1sNhyW2BeY3znzwFw0PcRxbC8inzsvqjEX+jhFVx+LFo2QGiqmowp7a9kLO7pJqfHp 5Qprc72nJzfQQCEw/AuHMsExwa5dn4P4dOzMlws00lJNiONCxHDVNLgT9OKdnEG9DNmd AWoiBBI8k+0njl4iCrh8vDWhZ/rap4EBYrcfMyiiri/W1LuvjsAys+kVny9Q5Ncn4Aqv 6eHF2jRVMXGkV2hQTw8/5SrmZI5PMN7QAFZN7cXM8L57ayyVHd+VrtHupHSLYWp0Cbyu NCGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=piWpDsjg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si6693006edu.115.2021.09.23.04.19.28; Thu, 23 Sep 2021 04:19:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=piWpDsjg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240542AbhIWLRc (ORCPT + 99 others); Thu, 23 Sep 2021 07:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240521AbhIWLRc (ORCPT ); Thu, 23 Sep 2021 07:17:32 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9B02C061574 for ; Thu, 23 Sep 2021 04:16:00 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id c7so20926563qka.2 for ; Thu, 23 Sep 2021 04:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WxWyZjqzKABxFGtDm2TtL1V2QPdgvK9G3mFsSj6IZsc=; b=piWpDsjgwmWQA7xP9ZDB/Ul8WwCD5xFDxPy//6xIQXw7lceBSflH3FaboHK2447F25 NUKJq+YksT+uzaJp+nxMyG0edltdwjR+nSzPj+G9hEXnvcoYWaxeRP+jcCJz6S096xx8 uAH1uinFxJ21t7EljSUxRYVq0G22dTH/RMDTJf7Ml69H+B/Ryge+wk+0FbKdCMSTCNSp u5P8ykRg6BfjLlNnSRwgu1CKx2KdkGbuKP2Mf6WFtokWG5Aav7zNBoQ8RE4Xh24GFeZf vN6GGxaq6MAcgOE+SNM56oRm+Tx5iKDUm4Qhvb7MZLtDUnWaFi3Bet38/GGXdIk+zYB4 NwGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=WxWyZjqzKABxFGtDm2TtL1V2QPdgvK9G3mFsSj6IZsc=; b=fCl4EP+aea8udCfZMlRzpBYeNqTuwVo70rvWcP/mGsPZUXMUP7hZJSa70J39ZGgMdK KOyWvROT8lwA94OH/Y7+k8nHvHtYLhEMvkyQqDfB7dAU2tqOE7cL6ceF2WBIuv/pGZ8B jHvyUQHx6qZDscNbZjsLFA2xpvg8Z0xFiQb10l2ECch7OMyUT/30TXyFvxD0+0hV6CiN ffeGSVtxPe3Bgc+Sm941lI7BZHZWJHy1g1samh43X7ULF5nQ+7W633FFZ9mXNxnfMd8T 1+vaNSml8tcOb6BhK6C6TeXo9n/GUu8WSXZe140jK4rkk7Ekup/06Nes4Zwq2ScmkQR9 XzlQ== X-Gm-Message-State: AOAM530vIdJqNlfQHz2kFLcKBdVN1ADRzHSoDlIpSCsQ+ampvok+Wmfa 2sjvizGBb9pQV7wNL/YxTTq5CsMngMs1B77whlsgmA== X-Received: by 2002:a37:b483:: with SMTP id d125mr4023411qkf.362.1632395759497; Thu, 23 Sep 2021 04:15:59 -0700 (PDT) MIME-Version: 1.0 References: <20210923104803.2620285-1-elver@google.com> <20210923104803.2620285-2-elver@google.com> In-Reply-To: <20210923104803.2620285-2-elver@google.com> From: Alexander Potapenko Date: Thu, 23 Sep 2021 13:15:23 +0200 Message-ID: Subject: Re: [PATCH v3 2/5] kfence: count unexpectedly skipped allocations To: Marco Elver Cc: Andrew Morton , Dmitry Vyukov , Jann Horn , Aleksandr Nogikh , Taras Madan , LKML , Linux Memory Management List , kasan-dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 23, 2021 at 12:48 PM Marco Elver wrote: > > Maintain a counter to count allocations that are skipped due to being > incompatible (oversized, incompatible gfp flags) or no capacity. > > This is to compute the fraction of allocations that could not be > serviced by KFENCE, which we expect to be rare. > > Signed-off-by: Marco Elver > Reviewed-by: Dmitry Vyukov Acked-by: Alexander Potapenko > --- > v2: > * Do not count deadlock-avoidance skips. > --- > mm/kfence/core.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index 7a97db8bc8e7..249d75b7e5ee 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -112,6 +112,8 @@ enum kfence_counter_id { > KFENCE_COUNTER_FREES, > KFENCE_COUNTER_ZOMBIES, > KFENCE_COUNTER_BUGS, > + KFENCE_COUNTER_SKIP_INCOMPAT, > + KFENCE_COUNTER_SKIP_CAPACITY, > KFENCE_COUNTER_COUNT, > }; > static atomic_long_t counters[KFENCE_COUNTER_COUNT]; > @@ -121,6 +123,8 @@ static const char *const counter_names[] =3D { > [KFENCE_COUNTER_FREES] =3D "total frees", > [KFENCE_COUNTER_ZOMBIES] =3D "zombie allocations", > [KFENCE_COUNTER_BUGS] =3D "total bugs", > + [KFENCE_COUNTER_SKIP_INCOMPAT] =3D "skipped allocations (incompa= tible)", > + [KFENCE_COUNTER_SKIP_CAPACITY] =3D "skipped allocations (capacit= y)", > }; > static_assert(ARRAY_SIZE(counter_names) =3D=3D KFENCE_COUNTER_COUNT); > > @@ -271,8 +275,10 @@ static void *kfence_guarded_alloc(struct kmem_cache = *cache, size_t size, gfp_t g > list_del_init(&meta->list); > } > raw_spin_unlock_irqrestore(&kfence_freelist_lock, flags); > - if (!meta) > + if (!meta) { > + atomic_long_inc(&counters[KFENCE_COUNTER_SKIP_CAPACITY]); > return NULL; > + } > > if (unlikely(!raw_spin_trylock_irqsave(&meta->lock, flags))) { > /* > @@ -740,8 +746,10 @@ void *__kfence_alloc(struct kmem_cache *s, size_t si= ze, gfp_t flags) > * Perform size check before switching kfence_allocation_gate, so= that > * we don't disable KFENCE without making an allocation. > */ > - if (size > PAGE_SIZE) > + if (size > PAGE_SIZE) { > + atomic_long_inc(&counters[KFENCE_COUNTER_SKIP_INCOMPAT]); > return NULL; > + } > > /* > * Skip allocations from non-default zones, including DMA. We can= not > @@ -749,8 +757,10 @@ void *__kfence_alloc(struct kmem_cache *s, size_t si= ze, gfp_t flags) > * properties (e.g. reside in DMAable memory). > */ > if ((flags & GFP_ZONEMASK) || > - (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) > + (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) { > + atomic_long_inc(&counters[KFENCE_COUNTER_SKIP_INCOMPAT]); > return NULL; > + } > > /* > * allocation_gate only needs to become non-zero, so it doesn't m= ake > -- > 2.33.0.464.g1972c5931b-goog > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg