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=-6.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,INCLUDES_PATCH, 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 02557C433F5 for ; Wed, 22 Sep 2021 08:32:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A0D076124C for ; Wed, 22 Sep 2021 08:32:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A0D076124C 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 393596B006C; Wed, 22 Sep 2021 04:32:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 342736B0072; Wed, 22 Sep 2021 04:32:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20A64900002; Wed, 22 Sep 2021 04:32:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 114B86B006C for ; Wed, 22 Sep 2021 04:32:36 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B74A72BFAE for ; Wed, 22 Sep 2021 08:32:35 +0000 (UTC) X-FDA: 78614543070.30.DAED388 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf03.hostedemail.com (Postfix) with ESMTP id 61C4C30000A4 for ; Wed, 22 Sep 2021 08:32:35 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id 5so1273684plo.5 for ; Wed, 22 Sep 2021 01:32:35 -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=1vngS2lLFpX3T2rXXyf0bdb29JPkoUdlNBskWHD774k=; b=OxLvV2bRCQYkP9+l2Vlws5bL2v+cR5gRM7Z01D+2/5+LnXLYJK6CeI8mhHfLHPeMAS UIFpcdXsFiAbqRNtxbxdaW7CE7CbS+cIlyV3YrXIK8QkH7uJtWpLgytBnN5hWYVSl/i3 TfZj5nRgu/h9EYjEj4WHb9MOYXvpq6lDudCL8FJ6hMmv9cYSX1rlNKyG9HoiWPwJmwPT DIevCepsGiwzpJJ4l8cJNWuW5bcfV5P6zvWOZhT/zIjBf47x6PXN0wgJ5dpNM1YhkHo3 zTsIl6zNC+CMtW0uVrXEba5HGBjYH3zT4QfjrOzLOUig0Llzovl73gfliMeSpTVXPXdp RrwA== 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=1vngS2lLFpX3T2rXXyf0bdb29JPkoUdlNBskWHD774k=; b=TJup4H6nXYOFBHIKJoMhKspNNdm4k/VYeEFrWsHSBuOxsFSSXpO3uqRtswa1hq+bNN 7xaZXDrIsXPJpObEDGDN1mqsEDeibGJNp9qg1rhlgLk4FRVfNd8qGekD/P47zBJWTK0j GOQ4qsvJ1NXLtfRJg7PPOm/xMfxX2NJ8D/A4Pl12q/TQ5YxHdYQPNtlqP75oWg7QI82r mnwrwcolVKWptz8HXeuhsjkXigNEgISxSJsmPq4dm+U0NgeMJVy/jM6I4Ta559u6P7O/ mxBRCyCCtq5215hYO3gVpma/phAjYLIS0KaVUPFUA9D+x1mMxz5pLwXKg96QYyVlUwoR yvEw== X-Gm-Message-State: AOAM532BoCWKdmSynVGfxNIuPVselCAUnm5QpsNg/ElLIkmywFeCgDE8 CCh9Eya9LaVFyU+n+aGIfFU= X-Google-Smtp-Source: ABdhPJw/BLSytIi3rtAX6V4TCQIMXbjagraOTa5pwNL7yhu5hVmfxY8eLMphBzyOFF80+jG2ykYaRA== X-Received: by 2002:a17:902:dcd5:b0:13d:97c6:c480 with SMTP id t21-20020a170902dcd500b0013d97c6c480mr21343565pll.70.1632299554488; Wed, 22 Sep 2021 01:32:34 -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 k14sm1820644pgg.92.2021.09.22.01.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 01:32:34 -0700 (PDT) Date: Wed, 22 Sep 2021 08:32:28 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Matthew Wilcox Cc: linux-mm@kvack.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , linux-kernel@vger.kernel.org, Jens Axboe , John Garry , linux-block@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [RFC v2 PATCH] mm, sl[au]b: Introduce lockless cache Message-ID: <20210922083228.GA79355@kvm.asia-northeast3-a.c.our-ratio-313919.internal> References: <20210920154816.31832-1-42.hyeyoo@gmail.com> <20210921154239.GA5092@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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 61C4C30000A4 X-Stat-Signature: 5oktdwyxwiinkr351i9ziju939p9m5yz Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OxLvV2bR; spf=pass (imf03.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1632299555-642050 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: Hello Matthew. There's good news. in v3 (work in progress now), I fixed some bugs (I hate kernel panics!) And for test, made NAPI use it. it works pretty well. On Tue, Sep 21, 2021 at 05:17:02PM +0100, Matthew Wilcox wrote: > On Tue, Sep 21, 2021 at 03:42:39PM +0000, Hyeonggon Yoo wrote: > > > > + /* slowpath */ > > > > + cache->size = kmem_cache_alloc_bulk(s, gfpflags, > > > > + KMEM_LOCKLESS_CACHE_QUEUE_SIZE, cache->queue); > > > > > > Go back to the Bonwick paper and look at the magazine section again. > > > You have to allocate _half_ the size of the queue, otherwise you get > > > into pathological situations where you start to free and allocate > > > every time. > > > > I want to ask you where idea of allocating 'half' the size of queue came from. > > the paper you sent does not work with single queue(magazine). Instead, > > it manages pool of magazines. > > > > And after reading the paper, I see managing pool of magazine (where M is > > an boot parameter) is valid approach to reduce hitting slowpath. > > Bonwick uses two magazines per cpu; if both are empty, one is replaced > with a full one. If both are full, one is replaced with an empty one. > Our slab implementation doesn't provide magazine allocation, but it does > provide bulk allocation. > So translating the Bonwick implementation to > our implementation, we need to bulk-allocate or bulk-free half of the > array at any time. Is there a reason that the number should be 'half'? what about something like this: diff --git a/mm/slab_common.c b/mm/slab_common.c index 884d3311cd8e..f32736302d53 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -455,12 +455,13 @@ void *kmem_cache_alloc_cached(struct kmem_cache *s, gfp_t gfpflags) } cache = get_cpu_ptr(s->cache); - if (cache->size) /* fastpath without lock */ + if (cache->size) /* fastpath without lock */ p = cache->queue[--cache->size]; else { /* slowpath */ - cache->size = kmem_cache_alloc_bulk(s, gfpflags, - KMEM_LOCKLESS_CACHE_QUEUE_SIZE, cache->queue); + cache->size += kmem_cache_alloc_bulk(s, gfpflags, + KMEM_LOCKLESS_CACHE_BATCHCOUNT, + cache->queue); if (cache->size) p = cache->queue[--cache->size]; else @@ -491,13 +492,13 @@ void kmem_cache_free_cached(struct kmem_cache *s, void *p) cache = get_cpu_ptr(s->cache); if (cache->size < KMEM_LOCKLESS_CACHE_QUEUE_SIZE) { cache->queue[cache->size++] = p; - put_cpu_ptr(s->cache); - return ; + } else { + kmem_cache_free_bulk(s, + KMEM_LOCKLESS_CACHE_BATCHCOUNT, + cache->queue - KMEM_LOCKLESS_CACHE_BATCHCOUNT); + cache->size -= KMEM_LOCKLESS_CACHE_BATCHCOUNT; } put_cpu_ptr(s->cache); - - /* Is there better way to do this? */ - kmem_cache_free(s, p); } EXPORT_SYMBOL(kmem_cache_free_cached);