Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4040829pxk; Tue, 8 Sep 2020 09:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYA6lcOUwBbf/ERy5XumD4sbAGB+N0Vmn2Bprr5+bjPu/elZdyMN3TYVyvD/BwNpitrQWi X-Received: by 2002:aa7:cc8d:: with SMTP id p13mr8302598edt.136.1599581401916; Tue, 08 Sep 2020 09:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599581401; cv=none; d=google.com; s=arc-20160816; b=pkzV2QNq7fz3A3/aWJ3Q3OsLGVFhU9BZSOMdxruEAw5fzoavc1JNtABLQ0akB70ZdP k1V3eTTrXvVzo+pUQGPAFx+gkikNALAvxWW4YOpIICZAnnzs/n/jz4Qd02tu8vp5l9vH FCLTbYP/7OyxiKDedeFDXVa1D11DCtUIdCTLALVThJMY0G+u5FbyAbd0bnSCV5JeoRxl BTFPDwTPjdKdpftlVZFkH5svT9zGKP2xxhX7rm2nsVYslnIQJy0+8S1U4GW4kF+ApAmE SFcrGzhTLdNGO1+mTDi66TdTooQI6zCoiYy6gSKxnPhdJC8HxwnBElDlQGC1vVB+PQZ9 L+tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jYC9v1Z1TC/eRVDb6B6iUcOvbi2c078flAMPYhklKtQ=; b=p0NT1jwaW6YXue3i1NnxBRtcbARIRsN0127aukrNUxsJvu4u4wF7xGQmYqlgf9///S l+XM/N3LFsfjv7nn1LjY+8hwtuTk9tZnxXJOCkQZd2BPnVFu1lGu0MitWk5R480s98Bd /CulA/WFlnZ0FLmMVSjf1s9OovAIUERPhVt8QUNfYzSAeOWZXEQ0up3FAqKtnXy6ruZi qcb0G4bIRq4fNYr3cD2Ss4DJjhpOuH76702tcZlrYtblYGO+dibD+4oYGHf57nGmxHyJ XjAN6GK1YsG2dvC1IfYVzcXmwGdvoSaM0SY4vMt3NL7EzNGWMsn7z+oAqv/j52dhJNt3 +ITg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wETpD6sa; 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 s22si11539406edt.207.2020.09.08.09.09.35; Tue, 08 Sep 2020 09:10:01 -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=wETpD6sa; 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 S1731235AbgIHQIV (ORCPT + 99 others); Tue, 8 Sep 2020 12:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731039AbgIHQAE (ORCPT ); Tue, 8 Sep 2020 12:00:04 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF0D0C06179B for ; Tue, 8 Sep 2020 08:56:39 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id o5so19638766wrn.13 for ; Tue, 08 Sep 2020 08:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jYC9v1Z1TC/eRVDb6B6iUcOvbi2c078flAMPYhklKtQ=; b=wETpD6saEAEz/nnn8zVtwhh+gaFPha+TeS89jJ1i0WXRSxkwSLmbkgYLe8LJONzyMS DoB7HEnSel284io7HecToViYhGiJ/osVBiEYD5yf36sYhXeLWHEvuky/VfFW+7XxkgGB VNk4oD+jr9cpDC8j7R2bk16HED+JGEVY/OcjOdN2e+kZrHY2LHNqjx+alq560KySCd1/ RwuqL+2rbOxyAm0vQxuu+ygoqRDiR/sxu6RsaVECGbE7ZTmzbo3vAPc3y+pfvc+FtQcc g1bQM/CkUw5uoAWK6aYaUslAe00EShXz22vICKweKwyYvAPpqK2uKAcCW+a4z8jnwfTk tehQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jYC9v1Z1TC/eRVDb6B6iUcOvbi2c078flAMPYhklKtQ=; b=aPPGpkPbgaj118C1mWjkjZM082+NknRP4OWJnU/eyYvKQaMV4GJ481xS8bJ2KfXHZY KPXQw6iXtSK/WOQs2/+KaOyPE7ybEsKh0Sm7Yddg2QXzp7gsox8TbVgcAS7oA65gpLs5 I3s4kuQlKFF3aFoL+CG/3bywIaRyIlH9wpv3WVFtceSz5ofJAytuxIE7gjkegtR9pQrE 7cc3wopxWCUOhwH3aLEM2yKC0X7MIJoRA0gtZQUQ0sZsbZvIOEjzNMw2C+5JLvh/NquS +Em6KQmxWOrHQn1H/+uFiutk7q1t08lLC1RoEHscznhsbLKr3VH6MwexwG27HLygfjVA e5rw== X-Gm-Message-State: AOAM532sXaXA05KZEeL3PabCKGvZ93hG9xw3527V12HuqUUnZyfI4Mi9 Xg2JajqcCObhwVMuGXwleMz9UA== X-Received: by 2002:a5d:4a4b:: with SMTP id v11mr335425wrs.36.1599580598237; Tue, 08 Sep 2020 08:56:38 -0700 (PDT) Received: from elver.google.com ([100.105.32.75]) by smtp.gmail.com with ESMTPSA id h184sm34756040wmh.41.2020.09.08.08.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 08:56:37 -0700 (PDT) Date: Tue, 8 Sep 2020 17:56:31 +0200 From: Marco Elver To: Vlastimil Babka Cc: Dave Hansen , glider@google.com, akpm@linux-foundation.org, catalin.marinas@arm.com, cl@linux.com, rientjes@google.com, iamjoonsoo.kim@lge.com, mark.rutland@arm.com, penberg@kernel.org, hpa@zytor.com, paulmck@kernel.org, andreyknvl@google.com, aryabinin@virtuozzo.com, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, dvyukov@google.com, edumazet@google.com, gregkh@linuxfoundation.org, mingo@redhat.com, jannh@google.com, corbet@lwn.net, keescook@chromium.org, peterz@infradead.org, cai@lca.pw, tglx@linutronix.de, will@kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH RFC 00/10] KFENCE: A low-overhead sampling-based memory safety error detector Message-ID: <20200908155631.GC61807@elver.google.com> References: <20200907134055.2878499-1-elver@google.com> <20200908153102.GB61807@elver.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.14.4 (2020-06-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 08, 2020 at 05:36PM +0200, Vlastimil Babka wrote: > On 9/8/20 5:31 PM, Marco Elver wrote: > >> > >> How much memory overhead does this end up having? I know it depends on > >> the object size and so forth. But, could you give some real-world > >> examples of memory consumption? Also, what's the worst case? Say I > >> have a ton of worst-case-sized (32b) slab objects. Will I notice? > > > > KFENCE objects are limited (default 255). If we exhaust KFENCE's memory > > pool, no more KFENCE allocations will occur. > > Documentation/dev-tools/kfence.rst gives a formula to calculate the > > KFENCE pool size: > > > > The total memory dedicated to the KFENCE memory pool can be computed as:: > > > > ( #objects + 1 ) * 2 * PAGE_SIZE > > > > Using the default config, and assuming a page size of 4 KiB, results in > > dedicating 2 MiB to the KFENCE memory pool. > > > > Does that clarify this point? Or anything else that could help clarify > > this? > > Hmm did you observe that with this limit, a long-running system would eventually > converge to KFENCE memory pool being filled with long-aged objects, so there > would be no space to sample new ones? Sure, that's a possibility. But remember that we're not trying to deterministically detect bugs on 1 system (if you wanted that, you should use KASAN), but a fleet of machines! The non-determinism of which allocations will end up in KFENCE, will ensure we won't end up with a fleet of machines of identical allocations. That's exactly what we're after. Even if we eventually exhaust the pool, you'll still detect bugs if there are any. If you are overly worried, either the sample interval or number of available objects needs to be tweaked to be larger. The default of 255 is quite conservative, and even using something larger on a modern system is hardly noticeable. Choosing a sample interval & number of objects should also factor in how many machines you plan to deploy this on. Monitoring /sys/kernel/debug/kfence/stats can help you here. Thanks, -- Marco