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 13BA6C5478C for ; Tue, 27 Feb 2024 06:21:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81A2A4401EC; Tue, 27 Feb 2024 01:21:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BC754401E8; Tue, 27 Feb 2024 01:21:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65EE74401EC; Tue, 27 Feb 2024 01:21:22 -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 52A074401E8 for ; Tue, 27 Feb 2024 01:21:22 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2B1B0160A19 for ; Tue, 27 Feb 2024 06:21:22 +0000 (UTC) X-FDA: 81836586804.27.0C94917 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) by imf19.hostedemail.com (Postfix) with ESMTP id 41CFB1A000B for ; Tue, 27 Feb 2024 06:21:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="q+wpQAr/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.171 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709014880; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0GSq7+i8kqkYZe31UVWQlh2crqMmMhxEGm5D2e74FWM=; b=JYJBPu34XYWF9VR8GxBgCdLB6fMejPUr5fjuMVOnf7yM/ZQ0Ya+cvKFaqkmQtIo1VMoRRH EAADFOD4qsMim2n2gx+zyt9rlQEKdzpzPvoyziW1mSfn1DJm9F3tx11J1U43ymuh4JbOKA 1VmHJi4Wv08kuh/TVE8s6HrplKcfkUE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="q+wpQAr/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.171 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709014880; a=rsa-sha256; cv=none; b=PP1I4mkSMpW1pZ7MDWHTArRAFE4s/gdH+ffUCI8BFheVdEU3lmX8HaAUFWKABURB77/g/v OrZ6QIZ4VJ7tJQkTFWmuFMJp0jnJrO+E3ZS0zAQ+SruBh/Xdwc1qekf0nY/PkfXz96j96b 9LPGGZhEjNoZNvbrWOD/jr9ia5yblDo= Date: Tue, 27 Feb 2024 01:21:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709014874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0GSq7+i8kqkYZe31UVWQlh2crqMmMhxEGm5D2e74FWM=; b=q+wpQAr/wKRDCeFvxG8VegbD/UXQkLTkXiSjdML7AT/xs8//hjv+wvp3q1fXFI+hTRKoC3 2MwNw8AU477SlGNCO/v8H5+Xd1VzsTzso7sqwTbWgmX26oMvCVgE6lhv26Mlkisb02ACFK 7KKqYDATvEmgtCfeVdX9KEDJ0sJ3Ako= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: "Paul E. McKenney" Cc: Matthew Wilcox , Linus Torvalds , Al Viro , Luis Chamberlain , lsf-pc@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm , Daniel Gomez , Pankaj Raghav , Jens Axboe , Dave Chinner , Christoph Hellwig , Chris Mason , Johannes Weiner Subject: Re: [LSF/MM/BPF TOPIC] Measuring limits and enhancing buffered IO Message-ID: <6xpyltamnbd7q7nesntqspyfjfq3jexkmfyj2fekrk2mrhktcr@73vij67d5vne> References: <5c6ueuv5vlyir76yssuwmfmfuof3ukxz6h5hkyzfvsm2wkncrl@7wvkfpmvy2gp> <49354148-4dea-4c89-b591-76b21ed4a5d1@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 41CFB1A000B X-Stat-Signature: dzzgupzxddsjyi3xkj7imtu7yp5589yc X-HE-Tag: 1709014878-587005 X-HE-Meta: U2FsdGVkX18Aq3dnHXz1lAqsbphcBGzKUjQh2ZaBrez4Woq0FKkb/8P3SJdQYrxd15olwpPUX/uHxRCZr7pvsEsEGHbyNrbZGB2RabtatjaKzrfjV8sTo1NCe+BM9b76b6ji6+RIhI1js/gQBkrlFHj0bMbOd9VQqoLS0UHURj9EpA9bqkVvFq98W64Y7WGX90vFEEiT76RgwjHV+0PALBMpzJcy4d2lH+BHTrDrJX+EyMME24JyxDNwOiZKnTYlKFUOjKAvs9/j7m5jMuiTzofG3YAOvkQbX2kyQKAmJr9L4t9yHhCOrE28lf/okQW3baUoZaNshEeHyRbtDBWzmlOcgtdd8r8aCZR0cngFL5FvIvUCvXxJvd8UYca+XvM5oeSoGQH6koSZ2qqJsajNEyPO+7Po5/ITZ5h4K5xXc4dk8eMAf8/EOrYpnIO7xpSSPhL3dLJZalZqjXBcq+BW5UySyUiQ6IGV2XWwnHsyuQ1iS0pZH5LYNUjC+GhuO1ghbVntprdCXtdyTzw3wFvCRAKR3HIUIkW19IqlEQ+gQGktSHhFW499OXT3gCL0UEIB8QHyRi8P9npU36QN92o+NJWgwuscgSbLNMkHa002qntHEHJaWMQP3LqE8oEX7ncDnye6MkRgjaZyunLvMrThPdI3xnNTLBYS9Qir0URiMNcvenD2o6Vs5KpWZDqe60SvFKD9VFgWfQhSGXg2nqOtQ4tYEEmUv3w25X7XZoRQk5yLErtZMnBd6rFnUnPfLPl/YRL2r6ipEYwjmfG850AIwLc8KY6zS7ZQ6DiZSginL3k= 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: List-Subscribe: List-Unsubscribe: On Mon, Feb 26, 2024 at 09:17:41PM -0800, Paul E. McKenney wrote: > On Mon, Feb 26, 2024 at 08:08:17PM -0500, Kent Overstreet wrote: > > On Mon, Feb 26, 2024 at 04:55:29PM -0800, Paul E. McKenney wrote: > > > On Mon, Feb 26, 2024 at 07:29:04PM -0500, Kent Overstreet wrote: > > > > On Mon, Feb 26, 2024 at 04:05:37PM -0800, Paul E. McKenney wrote: > > > > > On Mon, Feb 26, 2024 at 06:29:43PM -0500, Kent Overstreet wrote: > > > > > > Well, we won't want it getting hammered on continuously - we should be > > > > > > able to tune reclaim so that doesn't happen. > > > > > > > > > > > > I think getting numbers on the amount of memory stranded waiting for RCU > > > > > > is probably first order of business - minor tweak to kfree_rcu() et all > > > > > > for that; there's APIs they can query to maintain that counter. > > > > > > > > > > We can easily tell you the number of blocks of memory waiting to be freed. > > > > > But RCU does not know their size. Yes, we could ferret this on each > > > > > call to kmem_free_rcu(), but that might not be great for performance. > > > > > We could traverse the lists at runtime, but such traversal must be done > > > > > with interrupts disabled, which is also not great. > > > > > > > > > > > then, we can add a heuristic threshhold somewhere, something like > > > > > > > > > > > > if (rcu_stranded * multiplier > reclaimable_memory) > > > > > > kick_rcu() > > > > > > > > > > If it is a heuristic anyway, it sounds best to base the heuristic on > > > > > the number of objects rather than their aggregate size. > > > > > > > > I don't think that'll really work given that object size can very from < > > > > 100 bytes all the way up to 2MB hugepages. The shrinker API works that > > > > way and I positively hate it; it's really helpful for introspection and > > > > debugability later to give good human understandable units to this > > > > stuff. > > > > > > You might well be right, but let's please try it before adding overhead to > > > kfree_rcu() and friends. I bet it will prove to be good and sufficient. > > > > > > > And __ksize() is pretty cheap, and I think there might be room in struct > > > > slab to stick the object size there instead of getting it from the slab > > > > cache - and folio_size() is cheaper still. > > > > > > On __ksize(): > > > > > > * This should only be used internally to query the true size of allocations. > > > * It is not meant to be a way to discover the usable size of an allocation > > > * after the fact. Instead, use kmalloc_size_roundup(). > > > > > > Except that kmalloc_size_roundup() doesn't look like it is meant for > > > this use case. On __ksize() being used only internally, I would not be > > > at all averse to kfree_rcu() and friends moving to mm. > > > > __ksize() is the right helper to use for this; ksize() is "how much > > usable memory", __ksize() is "how much does this occupy". > > > > > The idea is for kfree_rcu() to invoke __ksize() when given slab memory > > > and folio_size() when given vmalloc() memory? > > > > __ksize() for slab memory, but folio_size() would be for page > > allocations - actually, I think compound_order() is more appropriate > > here, but that's willy's area. IOW, for free_pages_rcu(), which AFAIK we > > don't have yet but it looks like we're going to need. > > > > I'm scanning through vmalloc.c and I don't think we have a helper yet to > > query the allocation size - I can write one tomorrow, giving my brain a > > rest today :) > > Again, let's give the straight count of blocks a try first. I do see > that you feel that the added overhead is negligible, but zero added > overhead is even better. How are you going to write a heuristic that works correctly both when the system is cycling through nothing but 2M hugepages, and nothing but 128 byte whatevers?