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 X-Spam-Level: X-Spam-Status: No, score=-1.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7760DC433EF for ; Mon, 20 Sep 2021 02:54:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EAECA60F6E for ; Mon, 20 Sep 2021 02:54:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EAECA60F6E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 35D7E900003; Sun, 19 Sep 2021 22:54:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E613900002; Sun, 19 Sep 2021 22:54:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 186FB900003; Sun, 19 Sep 2021 22:54:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 05E3D900002 for ; Sun, 19 Sep 2021 22:54:16 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A68AB8249980 for ; Mon, 20 Sep 2021 02:54:15 +0000 (UTC) X-FDA: 78606432870.35.B0679F3 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf19.hostedemail.com (Postfix) with ESMTP id 627C8B0000BB for ; Mon, 20 Sep 2021 02:54:15 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id m21-20020a17090a859500b00197688449c4so11637069pjn.0 for ; Sun, 19 Sep 2021 19:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mBw05sV24CGbBPxa3HJ1K125rdehCVx17LjyHhUTWT8=; b=KlM0TLYvKHq3hYTlt9aFuUlIEAPoGkvzMugqBOMKWuLHbiIHnW0qWbNX0XxNdXEMXO beoxuhxJ3sf6V92HHU2Iq+x/pP4SjAa5UoFeZgO5JgNZnE7TK1tX+tfjS8XzZpDtKId0 k0gDfiBwMJFf8DzKpu62qDga7z0QFHRk/R161Cc9/bdCgnppk4DpzWLSTAFRSdmz1a1O zlbJA8xjiQQ63cFQwa6MDgsZuaoNEF7L8aZxPlw2XOFtTRlbv6sviO7Krx1bKPd/rh7G p3Y2z57w93mLSt7VZQs82h0Ixy49m/mM9gJLC5oA2R9Hz+vHFr7kZjSK/g8IW4RB9DS8 epOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mBw05sV24CGbBPxa3HJ1K125rdehCVx17LjyHhUTWT8=; b=PSK1+05l4B8o0xJJff2NgjQeetl+Posk+zWltfyGaB2hPN3LQZgYYdq2QUcvO1EkUQ mrA9CyHStdvngBtEKcBFlIuMtWpDij5SZiINzn/0x1LIXprJIBSfkbBtrfNbLaXwZNrR OyVV8ZHA1oD4261PARiZKjkXDtpqATNdiGaKD53YI5vBx0EvFxsqf8XXDbaqj0vXIGNT UPibuT1sq5D0wXUVUoNImvqBE90GQtoN0Xbi8g8YQDhVNfMevx5HKDK6GjTS+kuo4Byc 1+9ho/9cBLJ6blXmp832HiLxNby4Z+EZ775vMcsZkPUdJ0T+Vmb2Fau4tJlbraOlD3Gb jvXA== X-Gm-Message-State: AOAM5314P65pyBA9HK79lYIqzp3rsMtVFYhJayiREsioubRZVEzXjLgL SFk0lr55mpcmChOzQitr0AE= X-Google-Smtp-Source: ABdhPJzBo+Nn1cOKj3Hk8PWmMve4xNxaTOIfPMYC3c8Uig13mfjJu6jwazq8Hutl8ObH3D0jfUawPg== X-Received: by 2002:a17:903:310c:b0:13c:91b2:2ada with SMTP id w12-20020a170903310c00b0013c91b22adamr20518888plc.69.1632106454348; Sun, 19 Sep 2021 19:54:14 -0700 (PDT) Received: from kvm.asia-northeast3-a.c.our-ratio-313919.internal (252.229.64.34.bc.googleusercontent.com. [34.64.229.252]) by smtp.gmail.com with ESMTPSA id k190sm12597937pfd.211.2021.09.19.19.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 19:54:13 -0700 (PDT) Date: Mon, 20 Sep 2021 02:54:08 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Matthew Wilcox Cc: Christoph Lameter , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jens Axboe Subject: Re: [RFC PATCH] Introducing lockless cache built on top of slab allocator Message-ID: <20210920025408.GA3028@kvm.asia-northeast3-a.c.our-ratio-313919.internal> References: <20210919164239.49905-1-42.hyeyoo@gmail.com> <20210920010938.GA3108@kvm.asia-northeast3-a.c.our-ratio-313919.internal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: hpn4wn7xk8a5e3f4y6c6d7w3kzzsadpd Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KlM0TLYv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 627C8B0000BB X-HE-Tag: 1632106455-864067 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: On Mon, Sep 20, 2021 at 02:53:34AM +0100, Matthew Wilcox wrote: > On Mon, Sep 20, 2021 at 01:09:38AM +0000, Hyeonggon Yoo wrote: > > Hello Matthew, Thanks to give me a comment! I appreciate it. > > > > On Sun, Sep 19, 2021 at 08:17:44PM +0100, Matthew Wilcox wrote: > > > On Sun, Sep 19, 2021 at 04:42:39PM +0000, Hyeonggon Yoo wrote: > > > > It is just simple proof of concept, and not ready for submission yet. > > > > There can be wrong code (like wrong gfp flags, or wrong error handling, > > > > etc) it is just simple proof of concept. I want comment from you. > > > > > > Have you read: > > > > > > https://www.usenix.org/legacy/event/usenix01/full_papers/bonwick/bonwick_html/ > > > The relevant part of that paper is section 3, magazines. We should have > > > low and high water marks for number of objects > > > > I haven't read that before, but after reading it seems not different from > > SLAB's percpu queuing. > > > > > and we should allocate > > > from / free to the slab allocator in batches. Slab has bulk alloc/free > > > APIs already. > > > > > > > There's kmem_cache_alloc_{bulk,free} functions for bulk > > allocation. But it's designed for large number of allocation > > to reduce locking cost, not for percpu lockless allocation. > > What I'm saying is that rather than a linked list of objects, we should > have an array of, say, 15 pointers per CPU (and a count of how many > allocations we have). If we are trying to allocate and have no objects, > call kmem_cache_alloc_bulk() for 8 objects. If we are trying to free > and have 15 objects already, call kmem_cache_free_bulk() for the last > 8 objects and set the number of allocated objects to 7. > > (maybe 8 and 15 are the wrong numbers. this is just an example) > Ah, Okay. it seems better to use array. Using cache for list is unnecessary cost. array is simpler. > > Yeah, we can implement lockless cache using kmem_cache_alloc_{bulk, free} > > but kmem_cache_alloc_{free,bulk} is not enough. > > > > > I'd rather see this be part of the slab allocator than a separate API. > > > > And I disagree on this. for because most of situation, we cannot > > allocate without lock, it is special case for IO polling. > > > > To make it as part of slab allocator, we need to modify existing data > > structure. But making it part of slab allocator will be waste of memory > > because most of them are not using this. > > Oh, it would have to be an option. Maybe as a new slab_flags_t flag. > Or maybe a kmem_cache_alloc_percpu_lockless(). Oh, Now I got what you mean. That is a good improvement! For example, there is a slab_flags_t flag like SLAB_LOCKLESS. and a cache created with SLAB_LOCKLESS flag can allocate using both kmem_cache_alloc, or kmem_cache_alloc_percpu_lockless depending on situation? (I suggest kmem_cache_alloc_lockless is better name) it seems MUCH better. (because it prevents duplicating a cache) I'll send RFC v2 soon. Thank you so much Matthew. If there's misunderstanding from me, please let me know. Thanks, Hyeonggon Yoo