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 4B020C48BF6 for ; Tue, 27 Feb 2024 01:08:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E1F04401D3; Mon, 26 Feb 2024 20:08:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9915D44017F; Mon, 26 Feb 2024 20:08:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8334A4401D3; Mon, 26 Feb 2024 20:08:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7162B44017F for ; Mon, 26 Feb 2024 20:08:27 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2D7FDC0AF2 for ; Tue, 27 Feb 2024 01:08:27 +0000 (UTC) X-FDA: 81835798254.19.AD4D912 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) by imf15.hostedemail.com (Postfix) with ESMTP id 56F26A001B for ; Tue, 27 Feb 2024 01:08:25 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bdE0yncu; spf=pass (imf15.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708996105; 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=LDqTcIZQa3Py6GKquioM//Kg1mkaTH/E6XkLDhhVkKA=; b=QVI9m8QYPTaKErHnawEyqZpR9LAKmB1vFbLnYTQZI5HMOermqCB1lCyKoN8enqVUu8usRV nze13VAJ2S3t2LQ9NEgI3vE4wx3dEkIENsHG/hs6Or5aAVB6wCZKtdn8pEkJZD6yzpUt7z xK/AQBCVSiv3Jg9kd4wajlrhEy+FCvk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708996105; a=rsa-sha256; cv=none; b=IOQS7YPqzqxvtDjYmx+gyho0aUou7v7Xk0/YwRw3g92EES0IMgvVjZ7UYW+HDdqZ4pj+5C SiESeYwugn/uQUw4dVC/PvVF2+44Hwiip8/7JUiUZiNVP/WQOF0jWa6MtTc7H/jJuPFoXe RPNv0TuQHI5qtlcxuCzTd+GtvmacJU8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bdE0yncu; spf=pass (imf15.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Mon, 26 Feb 2024 20:08:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708996103; 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=LDqTcIZQa3Py6GKquioM//Kg1mkaTH/E6XkLDhhVkKA=; b=bdE0yncuc7HxxM4Jlh2IsKA/P41J/BHIakFTP9fe3EbJEfWD3lWcaNP0YpNT1nhBXSBMym FJaTltOEZ80h8T35T1nxpEP2+WT53DjHCaGoXNfnGCSvnhfkBfFDigAXDD4OYP0emAY0Cd p4TF/x13QfiYhshHe7c0dMiNVOcqlHo= 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: 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: <49354148-4dea-4c89-b591-76b21ed4a5d1@paulmck-laptop> X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 56F26A001B X-Rspam-User: X-Stat-Signature: dxdt5fky7riq6owrtcg38n3fhprge77q X-Rspamd-Server: rspam03 X-HE-Tag: 1708996105-593104 X-HE-Meta: U2FsdGVkX18FWyhTn+DflHIBKAM8AJ69UMMpoZ1h0zllNQkyea+Aw5uX1zInz1X+dOoreDjGTsJupE++8phGCQiguMxboF335jz+549BVecOVquoa9SRby8s1kPl0mUhdDelmd0N/W2ZGlqQXKPqvOlHUE0ZlAtS8W5NZWQv8s9Jbr+mzYspI0vmrnjxPrgFkRnUTfKXE1RnWlo6+lNJclNByoP9xv1q6EIh0CVKTOZLXZiaabY4rLvFqMYhzYxrvs5r3KApENe8qsENSfj1X3hG/bVTKItcLjXM8+iWWW7X9+uUf8XF+L9r9Bcl2uED8IMaukWzqFWmUUHEdQ6bcWomORoaKq0Ox1iPPLzcS4zqMpxTki80N1Dxr7EoRqyU261Us4LL1i+ZFDO2Os39dh0IFQTMI3Iu+XgOUuslr9eLqlg5qQ5W09WXD0wyy7miDBEdmjk49IKc41OsOJepxLLihDdeVZ8s0oFeB9qbm3r5W2J7TqjCOrbmoVGFieuVg5OcGIT/1gAM6fnqouzqAfvAJNarPn/CMGZ1u4xuoI1ZorQ64pfK7SFzSP6MK4xxg+J+FCg75cuDFU0NqS2L5EV/5SCYGxiatxQ7RANIdkrzP9n+iaeEw+xSHtJkmCBKmEIbk7JBtqZBHu73jSVSCqJj2PvBidPQGmIE5y7KN1ki2ZVXZZG0WR/lAqAwfcOTofMlSF9sScQtsg920tWTze+wiBdavuTJV60iyNAtVMPjIkKXFN4Xc//6xUoiyHmDbhWJ5/hxU+yV4EfrUu+msVuGZd7SMdBQMCCpk54TniglCw5Ky811eZhwP+Po7vvKh0GU5L1Ayz1U7IrZCNvAFvgFiABW+ybcbwcSD1T20DQMYdKrMlkXA+bgk/cyyAfwSzrfQWBYgfdtUaC7ZQ0RjsvFBBK8Dko9I5DtWg7XQVt5AaN6LR77HzpRfD35/4nCVdIdIHaTbT8N6zLlHoO b7EKZiJ3 1YYYZGSF4//fjmxbfOIMAGxxl2kg1m5LJTxeeXkTjXFf9Drz5VPvCVxfNou5Yc7KmSJe76sXcugMWNuzoY7IOOl5OMA== 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 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 :)