From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1FB0C433EF for ; Tue, 21 Sep 2021 10:48:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A0AEF60FE8 for ; Tue, 21 Sep 2021 10:48:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A0AEF60FE8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 42211900004; Tue, 21 Sep 2021 06:48:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D223900002; Tue, 21 Sep 2021 06:48:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C169900004; Tue, 21 Sep 2021 06:48:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 1F8EE900002 for ; Tue, 21 Sep 2021 06:48:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BD8B927DF5 for ; Tue, 21 Sep 2021 10:48:45 +0000 (UTC) X-FDA: 78611257410.02.1957698 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf20.hostedemail.com (Postfix) with ESMTP id 7B8A1D0000B4 for ; Tue, 21 Sep 2021 10:48:45 +0000 (UTC) Received: by mail-oi1-f176.google.com with SMTP id r26so29109901oij.2 for ; Tue, 21 Sep 2021 03:48:45 -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; bh=uQD0VoNg7df5hqKOKWbdHthbGkqzCUgLIjjPJbYxGXM=; b=nuqlgHgSMTyLv6y4qN8SY2nIPYd8eecIjOrHYK1ewfaO7W1MrHPEkP6cJLV60AAA5u QQ41nhZIf7zu2rg1UmSkqyJGAOUxxrZromPHfUU9B/8RAe51h2lw/ymbCUHm6HOE/sgC L1PXUnTaJo6qfL9sHX1yEkO/Ch8xcVMXJI2Pz9mEvVLBVa7q2kg1Jq8ManhkOheqMXg8 6wj5H3B9uF52UM/sVrcR3ffqTc5Zk6tAGJW4sMfO46oBSzysTp4dyW7DfAvF3Xb+h4Nc 4Ag3uC/baYuuuOIro+VOfgY9NqK+P+DZhT4CKimpvnQMmlluCrP6Nubn2NL2+RVm/lYW F7ng== 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; bh=uQD0VoNg7df5hqKOKWbdHthbGkqzCUgLIjjPJbYxGXM=; b=soR8r5b5Lg6mqvP60284aZueCtz2T7Qz3uzXV7hPtGxcHz4K8xL7Nsd+nP81lS1rbi QC2q+vQDw42x0Kx+DJD9Jh/6K6Gg0ClSapBibzM/Idur1M7adsU1GhkbLyoJ6SVpx7gN UASJI2d1H9uZ/oWfkHdesLx35f/llTOi1VMRZSMMaH7TkgO83tIbnIoDzTB1DjFdNRYZ gEkIJhMNsXVhDBPX77/1eNjQTbBZDPkh20fGTwspQyqIg/dr+AOpXKlTg29amwpdMegj fzNbw85TRW+cfLmJIhLPqp6sp947gPc/MG03Q3EcR80r/OJJ6fTm7Wc+DZ952pc0gf90 sLlw== X-Gm-Message-State: AOAM531TgvKLebLpqks7wd9PAAe47rPSBFsKnyf0u7tVULkSxrEN1HZk gMKya44lDI8nQhtZnpLSlpaCy8ihoyuRE/Dxz5rnyg== X-Google-Smtp-Source: ABdhPJwg7XAXBq5dllDW/UAm8CdazqwHn56tKUi/wY3c0Ee1vloEjtXJVU8X3FAfRDN4PzqakoW+PrD8utwFQZpnIFk= X-Received: by 2002:a54:4005:: with SMTP id x5mr3064072oie.160.1632221324643; Tue, 21 Sep 2021 03:48:44 -0700 (PDT) MIME-Version: 1.0 References: <20210921101014.1938382-1-elver@google.com> <20210921101014.1938382-2-elver@google.com> In-Reply-To: <20210921101014.1938382-2-elver@google.com> From: Dmitry Vyukov Date: Tue, 21 Sep 2021 12:48:33 +0200 Message-ID: Subject: Re: [PATCH v2 2/5] kfence: count unexpectedly skipped allocations To: Marco Elver Cc: Andrew Morton , Alexander Potapenko , Jann Horn , Aleksandr Nogikh , Taras Madan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7B8A1D0000B4 X-Stat-Signature: ne3qcjybxf6hpgxgyx4zto69uxrdm141 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nuqlgHgS; spf=pass (imf20.hostedemail.com: domain of dvyukov@google.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=dvyukov@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1632221325-870811 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: On Tue, 21 Sept 2021 at 12:10, 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 > --- > 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[] = { > [KFENCE_COUNTER_FREES] = "total frees", > [KFENCE_COUNTER_ZOMBIES] = "zombie allocations", > [KFENCE_COUNTER_BUGS] = "total bugs", > + [KFENCE_COUNTER_SKIP_INCOMPAT] = "skipped allocations (incompatible)", > + [KFENCE_COUNTER_SKIP_CAPACITY] = "skipped allocations (capacity)", > }; > static_assert(ARRAY_SIZE(counter_names) == 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 size, 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 cannot > @@ -749,8 +757,10 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, 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 make > -- > 2.33.0.464.g1972c5931b-goog >