From patchwork Tue Sep 21 10:10:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12507483 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=-26.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_AGENT_GIT,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 3D3D0C433F5 for ; Tue, 21 Sep 2021 10:10:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D48FF61038 for ; Tue, 21 Sep 2021 10:10:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D48FF61038 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 5B1556B0074; Tue, 21 Sep 2021 06:10:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 538DE6B0073; Tue, 21 Sep 2021 06:10:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DA016B0074; Tue, 21 Sep 2021 06:10:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 2F03B6B0072 for ; Tue, 21 Sep 2021 06:10:26 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CFAF88249980 for ; Tue, 21 Sep 2021 10:10:25 +0000 (UTC) X-FDA: 78611160810.06.B1A38B2 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf27.hostedemail.com (Postfix) with ESMTP id 7CB477000081 for ; Tue, 21 Sep 2021 10:10:25 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id r15-20020adfce8f000000b0015df1098ccbso8398183wrn.4 for ; Tue, 21 Sep 2021 03:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xqqCxuPrLaI1bLHMtAoGnOmrTQGbiQ0pjESMOvziO8U=; b=qs17jDbteS5bWdNSKYisdGThfhw9mWQnXuLyDn6xh+msrxUA9pL4A27pn9TwTQrYnc moBRZ7rLgtd5xbvFGT+peg1BDWHZINSnPwjQsihQBR8kwVpvgwCLAVYdkYSefa0VxoS/ Q+5b+qWoU3fZeGcpCQwQmtHjSt8ti2Z1t/n+CM1PoatMoed+scoju5sduDhnyIsVzicw y9RoxUQCrJxc6gtXTq0Ql69uBegGYNtHgMHBV4DPPDb6LVMtSUyfjyE7hmLqnTyrMNOi FMEUELhmmZAbG7nPbkA/UWCwEf0cq04sik7J2SQR8/5c1fzbxlm2QsRI2ZeLxSQ9fN6t zT/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xqqCxuPrLaI1bLHMtAoGnOmrTQGbiQ0pjESMOvziO8U=; b=6JF1zuv4jVxnRJx8iYKOjZZ0rWBnqU0v+KQggeYVFMXrXS5nYA5aIJszGDtFHkQ4cR 3vRVx+zunb4jzdeaGVDOWynV1sWIB12WWk006BChHmLxyPAezyz0XQ7szmCaVESWibHt aWm9EWqpGDbL9ztbs8Yszo+X7QM5HtpTcaJtm1gOopTRngyH56zEWUol2wEdjS9+mE6B nnVT9IEAZRkrv9u2e7VyuknzEnumre5mNxpPGB4qakINGMwA1b/9KcI57E2mJOTkJFZ1 21UYXV/x/knLKc8n5BMNjQJCovazdslYcmPkHwW35jOodEnL2EeaIFsZVgbxGP5W7p8b uGXg== X-Gm-Message-State: AOAM532eCYrmeCCeWk8LfXvlUh2WL9YIsBESJAhi6m2PgZ/dRs2gUHKl 5f6DkxzLDsm9AVyeI7234niWYeyMFQ== X-Google-Smtp-Source: ABdhPJx3COIbhHiKgMNm57MtDHgPxrn6NCIlsrggderVlrIYqkuHZHIVgfoPpXY4sPnG4z78HjkMGPH1JQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:dd03:c280:4625:60db]) (user=elver job=sendgmr) by 2002:a1c:a713:: with SMTP id q19mr3631781wme.42.1632219023932; Tue, 21 Sep 2021 03:10:23 -0700 (PDT) Date: Tue, 21 Sep 2021 12:10:11 +0200 In-Reply-To: <20210921101014.1938382-1-elver@google.com> Message-Id: <20210921101014.1938382-2-elver@google.com> Mime-Version: 1.0 References: <20210921101014.1938382-1-elver@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH v2 2/5] kfence: count unexpectedly skipped allocations From: Marco Elver To: elver@google.com, Andrew Morton Cc: Alexander Potapenko , Dmitry Vyukov , Jann Horn , Aleksandr Nogikh , Taras Madan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7CB477000081 X-Stat-Signature: i9wc5o5pud75myksbe85s9ng1yt35rm4 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qs17jDbt; spf=pass (imf27.hostedemail.com: domain of 3j69JYQUKCCYGNXGTIQQING.EQONKPWZ-OOMXCEM.QTI@flex--elver.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3j69JYQUKCCYGNXGTIQQING.EQONKPWZ-OOMXCEM.QTI@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1632219025-227963 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: 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