Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp390273pxk; Fri, 11 Sep 2020 09:37:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkoput10tnDscm4rGmE/r/L6qWXX1Ry/iK6TjeKO1xyaXIttCzPQeoWCwPR4XJShQdrrb+ X-Received: by 2002:a17:906:715b:: with SMTP id z27mr3045792ejj.166.1599842234597; Fri, 11 Sep 2020 09:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599842234; cv=none; d=google.com; s=arc-20160816; b=sTelFiyhnPgAIFcxvQ7PuoJM21P7ZP28zbXj/53o3O7bJOyLERbSquYt5p4ecxBX8i 9Lf+ZKwKLcqXlaqZp3d5QDg2R7Enu/SBjuDbnZAFYquDEztlslJdBSgZEeT8kODXripl WkmeGPSmshBNsUpc9DaYkKBUYeSmRO/j0vY5hTX1G7mzgt/jw97fzzwwAz+Jifl14rJJ BZqPltnSw/iEwm6O2YJH74IeZxmSoUb88gV+yQwvax0WXEXgkQ7Y3WccHxBDIbmYsP4+ sJTCUORU0oBkS9ZFKo7jc45EtNSuyMwIYKWF+26VYT5QuMhUiP/FGsuxSy1yHga6pogn y6jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LXuI1+2niHV1f/itEDtLBlt+egT8GEGRmfKrWMZ85Ng=; b=jnTF44yyxCWmQvTZk7HQVGiL/am7c5hZVzvA5kFQzVshUCcIp2to1Elql5XJ29Vzeb HqcxrhnzxdmSwvkjozgDJdJLf8r4QAgn9sUOaioBpGCQsCtsBk2sCHhE0VMVEZ0o7t5C kVbWbFs5jr7A25yHyVxXkExQm1+wy1Qz0YAcPpbs1i4ILPnynTk9RmM/9C6Du+rLwWq4 PM71nYJMe9/IEgA90g2QVYUERZ/iEHTjAzCJUT6+YUo5y7HYzWRJUTDMKptqJOo0jRkB xiOlHvIC92GT8hCJWF4oQbgTTuBbPIS06L9RdIKKBvFcHOH8s91PEnCe29+RgNjkIHIJ cSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gPyGKwnG; 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 bl4si1808379ejb.579.2020.09.11.09.36.51; Fri, 11 Sep 2020 09:37:14 -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=20161025 header.b=gPyGKwnG; 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 S1726417AbgIKQgP (ORCPT + 99 others); Fri, 11 Sep 2020 12:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726484AbgIKQeE (ORCPT ); Fri, 11 Sep 2020 12:34:04 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EEC3C061573 for ; Fri, 11 Sep 2020 09:34:04 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id m7so8579519oie.0 for ; Fri, 11 Sep 2020 09:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LXuI1+2niHV1f/itEDtLBlt+egT8GEGRmfKrWMZ85Ng=; b=gPyGKwnGM1G4h49Vz2S2gxB+Iub1XTLvkXVUxUDWA9zqi3G6XLGlEH+NbXH92MinNL bPp+fmjiAji2QO8/gVFHtFwnXp4Q3BFZnDYqgI/m4dGxmyY68jLER1kQu9rST+AFag/n RHpNL2CDn1B8ZlJBMMrHj7PUnc4xIWd4L6iMoYbfjWv71mVlAjxn7Tkg63j79tBeqkhr vTgN6cNA5c/XhSanFsKnUKeWF3Gt2JEByZzJ/qxTGfe4SwmqY/JHUoiLaGklx83GFHuT 7N//ZByW/IvZjob5vVqze7DrtCfZiSDfQK/5UwatBjtWOV99ErfEL6NSWqD9nwo0H5jh sy1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LXuI1+2niHV1f/itEDtLBlt+egT8GEGRmfKrWMZ85Ng=; b=raUiCcsW7FK6BObzayUMWE1WyUX8D8dG5YSY9A66ku/fiWY3hT5gXUK6Y89ZKFwWt6 2LPOYwEj637EPW+tpjgZx12j+j5+bAIJ+m/NvNHefm21qtUWLfTtq4Qt567ttjMJQFBT vruJCyIn+2ZSIVUMZbtgQ9nePYwpHqIYhrc7qwstNV/100Z8tA3NzbauduvxmcYNI3gG ABpshlBFWtJicrZ83zClqSxRjfZ5n61c//px8Gl7uBO8pSBM+ryN/CqLBoY1cQYDrtTY YZLdLL+fLcA94t6/1mbIqZErChwzbgbS8oAPURCUAcBQtbjsYit/2ETrH4mNGk0JvMR+ cPVQ== X-Gm-Message-State: AOAM530WYE9u/G2HhIebgXXj+FBn0Bzrtfe1B4HJ769de5mqfb6yxurV LCC5YElbqdJur8G6jbi4zg01eLEeysWKiq2M1/2CBw== X-Received: by 2002:aca:54d1:: with SMTP id i200mr1720432oib.172.1599842043737; Fri, 11 Sep 2020 09:34:03 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200908153102.GB61807@elver.google.com> <20200908155631.GC61807@elver.google.com> In-Reply-To: From: Marco Elver Date: Fri, 11 Sep 2020 18:33:52 +0200 Message-ID: Subject: Re: [PATCH RFC 00/10] KFENCE: A low-overhead sampling-based memory safety error detector To: Dmitry Vyukov Cc: Vlastimil Babka , Dave Hansen , Alexander Potapenko , Andrew Morton , Catalin Marinas , Christoph Lameter , David Rientjes , Joonsoo Kim , Mark Rutland , Pekka Enberg , "H. Peter Anvin" , "Paul E. McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Dave Hansen , Eric Dumazet , Greg Kroah-Hartman , Ingo Molnar , Jann Horn , Jonathan Corbet , Kees Cook , Peter Zijlstra , Qian Cai , Thomas Gleixner , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux-MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Sep 2020 at 15:33, Marco Elver wrote: > On Fri, 11 Sep 2020 at 15:10, Dmitry Vyukov wrote: > > On Fri, Sep 11, 2020 at 2:03 PM Marco Elver wrote: > > > On Fri, 11 Sep 2020 at 09:36, Dmitry Vyukov wrote: > [...] > > > > By "reasonable" I mean if the pool will last long enough to still > > > > sample something after hours/days? Have you tried any experiments with > > > > some workload (both short-lived processes and long-lived > > > > processes/namespaces) capturing state of the pool? It can make sense > > > > to do to better understand dynamics. I suspect that the rate may need > > > > to be orders of magnitude lower. > > > > > > Yes, the current default sample interval is a lower bound, and is also > > > a reasonable default for testing. I expect real deployments to use > > > much higher sample intervals (lower rate). > > > > > > So here's some data (with CONFIG_KFENCE_NUM_OBJECTS=1000, so that > > > allocated KFENCE objects isn't artificially capped): > > > > > > -- With a mostly vanilla config + KFENCE (sample interval 100 ms), > > > after ~40 min uptime (only boot, then idle) I see ~60 KFENCE objects > > > (total allocations >600). Those aren't always the same objects, with > > > roughly ~2 allocations/frees per second. > > > > > > -- Then running sysbench I/O benchmark, KFENCE objects allocated peak > > > at 82. During the benchmark, allocations/frees per second are closer > > > to 10-15. After the benchmark, the KFENCE objects allocated remain at > > > 82, and allocations/frees per second fall back to ~2. > > > > > > -- For the same system, changing the sample interval to 1 ms (echo 1 > > > > /sys/module/kfence/parameters/sample_interval), and re-running the > > > benchmark gives me: KFENCE objects allocated peak at exactly 500, with > > > ~500 allocations/frees per second. After that, allocated KFENCE > > > objects dropped a little to 496, and allocations/frees per second fell > > > back to ~2. > > > > > > -- The long-lived objects are due to caches, and just running 'echo 1 > > > > /proc/sys/vm/drop_caches' reduced allocated KFENCE objects back to > > > 45. > > > > Interesting. What type of caches is this? If there is some type of > > cache that caches particularly lots of sampled objects, we could > > potentially change the cache to release sampled objects eagerly. > > The 2 major users of KFENCE objects for that workload are > 'buffer_head' and 'bio-0'. > > If we want to deal with those, I guess there are 2 options: > > 1. More complex, but more precise: make the users of them check > is_kfence_address() and release their buffers earlier. > > 2. Simpler, generic solution: make KFENCE stop return allocations for > non-kmalloc_caches memcaches after more than ~90% of the pool is > exhausted. This assumes that creators of long-lived objects usually > set up their own memcaches. > > I'm currently inclined to go for (2). Ok, after some offline chat, we determined that (2) would be premature and we can't really say if kmalloc should have precedence if we reach some usage threshold. So for now, let's just leave as-is and start with the recommendation to monitor and adjust based on usage, fleet size, etc. Thanks, -- Marco