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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47816C4332F for ; Mon, 6 Nov 2023 17:41:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96C9D6B01A8; Mon, 6 Nov 2023 12:41:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91E2D6B01A9; Mon, 6 Nov 2023 12:41:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E4346B01AA; Mon, 6 Nov 2023 12:41:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6C1D16B01A8 for ; Mon, 6 Nov 2023 12:41:42 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3C6DC1A07FF for ; Mon, 6 Nov 2023 17:41:42 +0000 (UTC) X-FDA: 81428246844.20.2C920C5 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf17.hostedemail.com (Postfix) with ESMTP id 7825240007 for ; Mon, 6 Nov 2023 17:41:40 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="SBuj/84z"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699292500; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PQokn8UoRY8iyQHlIyiff09+YQ846OAlOmMikNVi4QE=; b=l7P8kjhpZyaLiEMdfeM66OtZweQ8ruSLjNbARbWSEEulZs02m8H+UWhCOEP3hlil2lWoAd HRpmpua1vdNr7FTnZwwPtUecR1QGWujkgJz3dOHnMypK//zeZOMtZP3cuelQNs5Zepql1M JLECuAsKHYOtr2MijOjC6Ljn+d5Zfgs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="SBuj/84z"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699292500; a=rsa-sha256; cv=none; b=Mq5yHJXy+l4AhU4a5xOYUorRL79T0fxuOv9bANbVP6FxYPIkt2KvnqeBzvTfKC2su39Pr4 o+khS+6/kZ+sctkAhePeUtXF1u5R+B7vi/YFrA2014Zxb94WnrYIQc2GpcSmdSjFhGZnzt 9rd524cPYto6VerzZjdF4b42F1izy2M= Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-280200949c3so3493411a91.0 for ; Mon, 06 Nov 2023 09:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699292499; x=1699897299; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PQokn8UoRY8iyQHlIyiff09+YQ846OAlOmMikNVi4QE=; b=SBuj/84zO7uCtJOjAgW6/pwSxz0YuTBixBdig6YVS72R9IYmqJexVV+J0uEBn+adYZ kp0nWcamBdyn6Ije/bKEdIACtMuT3CqKfGg1vGdEVLIB1RzyGDoP5tOjIKAJU3PwEvAD ubmijqqE1/lgdZHD2dyx0q2A55qkavjQGiC90q7O+zvCU480aecUCt/KdEK49cPvcgNU GP0Zu/mhgLmGQ6d3TI1+dm6XAwvWmYqhXH0yZLOyjBWJ68A1LFzO0EwSOPmzrLeJzJS9 9CCh+86x5oVEisNkt1plq+uxlgHax1KaxW70eDGIz8RNoxjuBybY3vfjSxEQRW2ZdJc5 cpLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699292499; x=1699897299; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PQokn8UoRY8iyQHlIyiff09+YQ846OAlOmMikNVi4QE=; b=hGvO9ZKHMc9Lm8IvlTfZkyK1jIMNDwRiZRyJvz5BTyDjphahV/xC0pE+loy0C5okTp GSL3Q5Cgi7X18Lj1M2kUpNSv2+BEmiJGsPK9V5NWglShh0dEyVUvz+weBW7AxnoBYbtS WJ+J4AW5tVVTmftUN/jN4u/Z25tfjpb879Y5W8a+fNmoejMndu6+EEu0QHPYiHvE/Jxn uQvYYeUhbEf07tmFDa+6NJGW2Yk0xuKFB06pLFcPhdPOWSgGIlMwS/Mk/Dl/hRyFoqie N+/v39cC3rSp4B8L232F7ctk21wcDD3c9q+lyk/VwOgHSLOERUcHD9jvs3A+C4CTrUfs iTkQ== X-Gm-Message-State: AOJu0YxwYms+pt4KYyOs5+hQ8r29Wsa26Z0xBQj+eaaq9HEfGAbKkgQq x5tS9xCTfRa299ednoi+Htlp5RtbOmuhIe/9NWXO5LRg X-Google-Smtp-Source: AGHT+IHiAqA6yTXob/0lQXEwVw+XGA3f3QODgmaimdSwl1J9rXBTTAEdCQf7hLfeBep3tDL+zvrXQld8T9b6eCfMYp4= X-Received: by 2002:a17:90b:4a50:b0:26d:17da:5e9f with SMTP id lb16-20020a17090b4a5000b0026d17da5e9fmr10375032pjb.1.1699292499209; Mon, 06 Nov 2023 09:41:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Mon, 6 Nov 2023 18:41:28 +0100 Message-ID: Subject: Re: [PATCH v3 00/19] stackdepot: allow evicting stack traces To: Marco Elver , Alexander Potapenko Cc: andrey.konovalov@linux.dev, Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 7825240007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: hjmhgw9pzgkqtikd5fkr8snrd8i9grs5 X-HE-Tag: 1699292500-438135 X-HE-Meta: U2FsdGVkX195zp7Og4Fna4DG3xLENyzHALoys98pn0T79+EeC3XpS0E/AfHXz5K2X7bRwalJ5ifnYS0+RVvoh6LA8Mmb/wtCehKfJCpbMW/9fhZReWWQvtNROPW/V4uCI/zI2UufxBUMQv/j4MfaDwkToamOeEa0zcEmJXQWHup5CA3+sQkmyVb55fq2fKVkIT3PGN0f175GUez7dpPxsOh7/kXdJ+ylyLFkK2TXpjBSI7aHp2Z1/b3CrbpavLsEqTaLFVTfxJbq24oa21GA0vJLIDlNpQu+PFEZcn7SzdsDg4UuH5PnLUvhh3MRNIvT6KYNiK0q9zdYRnVJkO5iMqggQSV2h2/oGf7KUPEN5iM3DQ6NViJZBmfyTzQ7xy8G/vqoXl82MTVFg0e5lvsffOQeybcyPA83gUjf7a7DfW/JwX6idnnvhFrH8MHKd9BYWSO8DigU7h/x1sFP1G3Q/iQBwOwY76VtXew77zezOgYgDBLXXKuGdi4DV7FWXYUExzWJhORlnFkuXbwxt/hVnCaFmZU+fIibnUmEzKqR5OQuGsdpFG59pSivAAuhaXVVIRBp/Ve4+gyagJuOHHhASO2lej2BU1Ly/AADS9nYEcJKbS/r5EGwE3hhNI4q1d1zkizEryw03fmiS31OZdvIQDomV67x/6F5nrDJeP6tmiXp38lig9W4hjRDL8HvEwAOoQ55Dm/fXY0J+buC7MCuUDrbFvUw9kGgD7Cat95Ox7F0lYPAnEJqObDM+AGm97PrQC5UxPYPGDi9+QosxSTG8DhVt93x2sEA+RVXRIUu89K7xpmKhehA6cnWaI8Cxq7BDzzfJVJSKdNu2wCBIH0B+inOHJxwtRfbfOT70c1BYdEu0LlM9XHJSAgjgjTvf0pnfbmnPIWWTHQ7myOcdi+dX9RcrlLndvVbvdqGXa0naox9dWsePuIAglIXDWbt7C8yPgdAYtVf9v1vaHU3PWq j+2zHh4f mqvizo6h+gIzxJDpVOrc4TobTIt4+1/EM0VeFCjt4ArR7pphVqJJQ7UCqwb/TWrAE2JDjARCnKeERJJrK5DfD6wfV/bvpyN1Z75Zb6VmBl6GJJ1Pu/YImwdvwOK4rncNGPvty2M4VOiAsdez2/AKtqwqxHF9nfSaW4DuFXSH6dVH1N3zlYYet5o/yQ5ztZVMAuKcb669nb0BXWl8EAHKnRqD2gvoVhiCzue6DT5blveVMO/ESvbP0b0yQZRbhMIvlVStThrXoXT1vGKPH/OV6lhcp5xWCXOntyGbPtYUCXDuoRhoFNdR/kD5jewfkAc6GjF+mND46y8Fmpgy3dT3KlNiyk92RTZqRK77o/wpjZ98gQjvE+cMWLtZ7fm31zu9qJ+7BAaFkEo6xk4SzGIEOKX2oiQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000128, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Nov 3, 2023 at 10:37=E2=80=AFPM Andrey Konovalov wrote: > > On Tue, Oct 24, 2023 at 3:14=E2=80=AFPM Marco Elver wr= ote: > > > > 1. I know fixed-sized slots are need for eviction to work, but have > > you evaluated if this causes some excessive memory waste now? Or is it > > negligible? > > With the current default stack depot slot size of 64 frames, a single > stack trace takes up ~3-4x on average compared to precisely sized > slots (KMSAN is closer to ~4x due to its 3-frame-sized linking > records). > > However, as the tag-based KASAN modes evict old stack traces, the > average total amount of memory used for stack traces is ~0.5 MB (with > the default stack ring size of 32k entries). > > I also have just mailed an eviction implementation for Generic KASAN. > With it, the stack traces take up ~1 MB per 1 GB of RAM while running > syzkaller (stack traces are evicted when they are flushed from > quarantine, and quarantine's size depends on the amount of RAM.) > > The only problem is KMSAN. Based on a discussion with Alexander, it > might not be possible to implement the eviction for it. So I suspect, > with this change, syzbot might run into the capacity WARNING from time > to time. > > The simplest solution would be to bump the maximum size of stack depot > storage to x4 if KMSAN is enabled (to 512 MB from the current 128 MB). > KMSAN requires a significant amount of RAM for shadow anyway. > > Would that be acceptable? > > > If it turns out to be a problem, one way out would be to partition the > > freelist into stack size classes; e.g. one for each of stack traces of > > size 8, 16, 32, 64. > > This shouldn't be hard to implement. > > However, as one of the perf improvements, I'm thinking of saving a > stack trace directly into a stack depot slot (to avoid copying it). > With this, we won't know the stack trace size before it is saved. So > this won't work together with the size classes. On a second thought, saving stack traces directly into a stack depot slot will require taking the write lock, which will badly affect performance, or using some other elaborate locking scheme, which might be an overkill. > > 2. I still think switching to the percpu_rwsem right away is the right > > thing, and not actually a downside. I mentioned this before, but you > > promised a follow-up patch, so I trust that this will happen. ;-) > > First thing on my TODO list wrt perf improvements :) > > > Acked-by: Marco Elver > > > > The series looks good in its current state. However, see my 2 > > higher-level comments above. > > Thank you!