Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4840480rwj; Tue, 20 Dec 2022 16:03:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXswCGfdd6CXCzU7dKdl7oedTBCnZwXU1Vz17ZlyOslRXqdNNGRq3q7Pv/QqqQQzjsUicu3J X-Received: by 2002:a17:90a:6e0b:b0:219:d72:2ea5 with SMTP id b11-20020a17090a6e0b00b002190d722ea5mr29744pjk.2.1671581030155; Tue, 20 Dec 2022 16:03:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671581030; cv=none; d=google.com; s=arc-20160816; b=f7PHGgNcOjs6lWRnEdgqz96clzVIqYkKdaFXs+zFRfWF2aHvIsY+fy7A8cK0SHoiUO 9Ihsyq+6OsxK3C5lp7511cCyYO4zjXJfkxSYInsigaNCSVWnqX26TUvQ3QF798NnrbOb fp3PAl+L0gQW9HOkeqBYhDKTDUR8dFLRzIHADYgGOhbB30UNk8bD2W6DB/u8reSAPIk/ AEm5nUJadpD18WZhASZCtVQFLGpkrj5c2kqZEJ4QNp1Dkuaqv6p9ZBrFLzZBYN2ep4sr lQkJsgtJiVNKZmO3viNwk76K+ibQlH3qmXHuy7n4DHas5sXKHNtRH0a+n3/PnumNmAVb Mdgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=pzTn8ur1XtUN2Eo2Nx2CrqTa1RIIIWnV7wMZmTTSeVA=; b=ux8Po7JMGmEMzicAlTnvAc3qCO0+svNjTb627XX1C0p65Hn+SIKn2Z/8dH9HamlO1M 3NBtrXjPr5vIXlOapziEAyOcgP4ArxKzYSSgefhe/3enF33C5kEqWK4W2Ce/m6Dp4DSU JslPDkjZcT4Y7X05OI2s1kcz8SgwEcW25pZ0z6HEiR33Bhkpjg6O4G36AGWQDJiG42jz 74c6M2EHS7eT4vCKMKDCXls9aaZANtDBtsNDKPmZqJK0E8ixZKQ/qQv0sV4IzOnBPeab fJ/eACo+fY1QbjoCllyx2NzwdlUzDjvaCAarT1U/QZO9lJ1+Me4K6HL2ksfU5Ujwwjvb V+5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hsswEVk0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a63e105000000b004783935de72si15270090pgh.45.2022.12.20.16.03.41; Tue, 20 Dec 2022 16:03:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hsswEVk0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbiLTX4v (ORCPT + 69 others); Tue, 20 Dec 2022 18:56:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233010AbiLTX4s (ORCPT ); Tue, 20 Dec 2022 18:56:48 -0500 Received: from out-204.mta0.migadu.com (out-204.mta0.migadu.com [IPv6:2001:41d0:1004:224b::cc]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194071CB24 for ; Tue, 20 Dec 2022 15:56:46 -0800 (PST) Date: Tue, 20 Dec 2022 15:56:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1671580602; 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=pzTn8ur1XtUN2Eo2Nx2CrqTa1RIIIWnV7wMZmTTSeVA=; b=hsswEVk0//IyZFc2+E1WqZAHxe0CFtd4/DVo+x3UvNn/+X9mxF5n56d2exL+WLYeNkoin4 RV2YPPvXag2wbDau0BBIZQAVrRT6bPBeabW/xRTj4cmq2EguhpTRKggNZhdUfVWd8erRnf dyDxVHaidT492nQGMk1Ux/lVIr0RqRI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Shakeel Butt Cc: Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Muchun Song , Andrew Morton , Waiman Long , Sven Luther Subject: Re: [PATCH RFC] ipc/mqueue: introduce msg cache Message-ID: References: <20221220184813.1908318-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 20, 2022 at 03:28:11PM -0800, Shakeel Butt wrote: > On Tue, Dec 20, 2022 at 12:59 PM Roman Gushchin > wrote: > > > > On Tue, Dec 20, 2022 at 11:53:25AM -0800, Shakeel Butt wrote: > > > +Vlastimil > > > > > > On Tue, Dec 20, 2022 at 10:48 AM Roman Gushchin > > > wrote: > > > > > > > > Sven Luther reported a regression in the posix message queues > > > > performance caused by switching to the per-object tracking of > > > > slab objects introduced by patch series ending with the > > > > commit 10befea91b61 ("mm: memcg/slab: use a single set of kmem_caches for all > > > > allocations"). > > > > > > > > To mitigate the regression cache allocated mqueue messages on a small > > > > percpu cache instead of releasing and re-allocating them every time. > > > > > > > > > > Seems fine with me but I am wondering what is stopping us to do this > > > caching in the slab layer for all accounted allocations? Does this > > > only make sense for specific scenarios/use-cases? > > > > It's far from trivial, unfortunately. Here we have an mqueue object to associate > > a percpu cache with and the hit rate is expected to be high, assuming the mqueue > > will be used to pass a lot of messages. > > > > With a generic slab cache we return to the necessity of managing > > the per-cgroup x per-slab-cache x per-cpu free list (or some other data structure), > > which is already far from trivial, based on the previous experience. It can > > easily lead to a significant memory waste, which will fully compensate all perf > > wins. > > > > So probably we need some heuristics to allocate caches only for really hot slab > > caches and use some sort of a hash map (keyed by cgroup and slab cache) to > > access freelists. What I miss to commit more time to this project (aside from not > > having it), is the lack of real workloads which will noticeably win from this work. > > > > Sven provided a good example and benchmark to reproduce the regression, so it > > was easy to justify the work. > > > > Thanks for the explanation. I think we should add this to the commit > message as well. I do think we should have a general framework for > such caching as there are other users (e.g. io_uring) doing the same > and some future users can take advantage as well e.g. I think this > type of caching will be helpful for filelock_cache as well. Anyways > that can be done in future. I agree. One way I'm thinking about is to provide an API for creating objcg-specific slab caches. All objects belonging to a such slab cache will belong to the same objcg. In this case the accounting can be even faster than the previous per-page accounting. And the user of such API will be responsible for the lifetime of the cache, as well as the decision whether to use the local or global slab cache. Thanks!