From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 198F31E0B9C for ; Sun, 28 Jun 2026 07:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782632871; cv=none; b=pD+2xD1gLMUDZqv8hopQxu2ZMHGbEPnZpiSze2yWH8Fz8tsD4nRX0X/f8s6Lnebg9SmZaQR3Gk1C+lCJT+dijX9/Poswgk2VRZviewf50anaTjZ2WUvk7k6Hd/8YI3yLmM3kIHHufIbfuSi59Syx8qlHWZEIDrAQ8+L7tiDiP1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782632871; c=relaxed/simple; bh=zlqQDq9il2mJiGCkFKVeX7uGrdSCcLPn0uOBVWu8fGI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aw1/vCycb+ERzIetnaoR7ZP250UM4dOsvrr9vyOh+SMhxpA9lkUgIO9j62YeoevvSbEVN5/fXZcwWfv/qrGbrgSD2OvMpUE8TbSlENAwBx9xl1iNN+qcKoDlSpEB/2iF38j8LvNe38eiPFLJejzlP/F8TskwOCWdHmhq8lIz3O0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P1Cp5PT8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P1Cp5PT8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 222FD1F000E9; Sun, 28 Jun 2026 07:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782632869; bh=WOXsSp9elfJ7spiFgdSwpNJTwjePPuVq0k4sQC7N0jI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=P1Cp5PT8znUS78WKkff45gZAe5Y+yGxs0RhcpgBYQkrjmmY+DQ+eid31PV05A9NXC R/dL/GK5gvATP7vSgLn/2QJVQVMZvi66gsB0IpUEZ6bwZ4b1jC/+Voi0tGRtaIREer ZCkCKhg52+5LjTCsRkS4mMQvafseCD8XIuBWAaPHWWWssabY2Q/lJgBM1NNrfnmkxb my6sWiwQXkj3EfhfT4Ad/R2oCm4yBw2UK7+sdm2sFQpHYElYZco56WZBXX4UXwDBRT ohFD1NGFzCtYVGwB2bbMuNTj5/PkfswFKqg8d8wrl/0Cz3sbVSmo+5Xq07s6WMb0Pj pu/17arSdaIIw== Message-ID: Date: Sun, 28 Jun 2026 09:47:45 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/slub: serve slabobj_ext array from a strictly larger kmalloc cache To: Shakeel Butt Cc: Harry Yoo , Andrew Morton , Roman Gushchin , Hao Li , Christoph Lameter , David Rientjes , Suren Baghdasaryan , Usama Arif , Meta kernel team , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Danielle Costantino References: <20260625230029.703750-1-shakeel.butt@linux.dev> <62453403-954c-4cf1-8924-6d38184b0810@kernel.org> <09267187-6c85-438f-8791-4cce8d07892a@kernel.org> From: "Vlastimil Babka (SUSE)" Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/28/26 5:23 AM, Shakeel Butt wrote: > On Sat, Jun 27, 2026 at 07:58:12PM -0700, Shakeel Butt wrote: >> On Fri, Jun 26, 2026 at 07:11:33PM +0200, Vlastimil Babka (SUSE) wrote: >> [...] >>>>>> Fix it structurally by removing cycles of every shape: serve the array >>>>>> from a cache strictly larger than the one it describes whenever it would >>>>>> otherwise come from the same or a smaller cache. Every reference edge >>>>>> then points from a smaller to a larger cache (here kmalloc-1k's array >>>>>> moves to kmalloc-2k), so the relation is a DAG and cannot contain a cycle. >>>>> >>>>> This will fix the problem. >>>>> >>>>> But this will waste memory as we need smaller obj_exts array >>>>> as the size gets larger. >>>>> >>>>> We should probably create a new kmalloc type to avoid cycles instead? >>>>> (needed only when memory profiling is enabled, though) >>>>> >>>>> That would also prevent recursion even further. >>>> >>>> Yes but I assume that would add kmem caches even for users not using memory >>>> profiling. Anyways, I think that is a separate discussion. Am I understanding >>>> correctly that you don't have any concerns with this approach? >>> >>> Umm, the memory waste is a concern? >>> >>> Minimally I'd now want to only do that size bumping when allocation >>> profiling is enabled. Ideally that means both configured in and not booted >>> with "never". >>> >>> We probably should have done that already in 280ea9c3154b2. Because AFAIU >>> memcg-only obj_exts array don't have this issue (or maybe they do have the >>> [1] issue? Harry?). But if memcg-only should keep avoiding the same size >>> bucket, it can keep what it was doing and only memalloc profiling would do >>> the strictly larger thing. >> >> memcg should not have this issue as normal kmalloc caches do not serve memcg >> charged objects. > > I am wrong here as I went back and see d8df600b67d7. (8dafa9f5900c upstream) >> >> So here we can do dedicated caches as Harry suggested or make this size bumping >> very specialized as Vlastimil suggested. What do we want long term? Orthogonally Maybe long term we make kmem_buckets unconditional and use that. >> we do want this fix to be backported easily to older stable kernels. I will see >> how does this narrowed down size bumping looks like. >> > > BTW I think we need something like the following, right? > > if (mem_alloc_profiling_enabled()) { > if (obj_exts_cache->object_size <= s->object_size) > return s->object_size + 1; > } else { > if (obj_exts_cache->object_size == s->object_size) > return s->object_size + 1; > } Yeah. >>> >>> Suren's input would be also nice to have. >>> >>> Thanks! >>> >>> [1] https://lore.kernel.org/oe-lkp/202601231457.f7b31e09-lkp@intel.com >>>