Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3243647pxf; Mon, 22 Mar 2021 01:18:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx04LejGSekaWF8Hr14TvxOCb3t/zawawajG0v2+aR/wKSElVX1ajszwkMsO0VKWlj5x2Kj X-Received: by 2002:a17:906:4107:: with SMTP id j7mr18209858ejk.185.1616401086806; Mon, 22 Mar 2021 01:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616401086; cv=none; d=google.com; s=arc-20160816; b=xoCZxVLFeV6hg68oNf2NK8M6DhHyWSR/LRZp37rY+2cEImCeqcvHFVI44WKJagkJww FNGYx0CHUxAxihZXe3CJ+Fd84n9zTYGFoA5tvmefWgvf8/wB0HryaS+OSRZUJrGg6UO4 Z1BQsQWw8Xh/oIoTgZeWv6qWQg5ZAizBapCSZYEQuTpvWS97UWzJ8y9A4oHMyNpXsBXd URiPsfw4A+SER4i+vstcj+PZnONX5BlGrRMJ0cVaYsMwSpurTB3W1O7hGmURW+6F8yOG mWR4LnUFlthjy/L0l2KWGRlVHiB0atLwC/m20wTS3Bb2lbKwnWA4tJLQQSObPwbMdiQT snQg== 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:date:dkim-signature; bh=3UcZ7X0BPfyvpZ2kfhXVZxzYo1lJR/oLtPPQ3opNY70=; b=YIpQrEgfnCFjMKFZ3btl/kh5bqOKR0SZigPV5Zm2hOJUK1FfNSb4QD2g/57bH4JSYK fsPGqM4N933cbRO0ppoVrzPgHzpbwE2VaZbSnSKl8Lu+ImIVosa1+9IOrBkQ1sMIz71T TJEidmEwZnLt2VFgVUDHnsOvtD/bCsj0UvY2+EAZ7S1cbEZs9aItywDTAo2mcEt1nkHp 0qvi25SPkfPcl8HuC8d+1TlQjlKlpCjKOiGuz9X3PgUpA50/jc3CtDewwLsBBMl9S4TQ FFaTJAaqfwFcN0AcyigdPbqScQ9mjN9ru7ziurU3oSYuwnBj699zkIWb/ZR8GzI28REG QYiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ZwHWUWpa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz16si10794663ejb.586.2021.03.22.01.17.43; Mon, 22 Mar 2021 01:18:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ZwHWUWpa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbhCVIQT (ORCPT + 99 others); Mon, 22 Mar 2021 04:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbhCVIPr (ORCPT ); Mon, 22 Mar 2021 04:15:47 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DD1C061574; Mon, 22 Mar 2021 01:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3UcZ7X0BPfyvpZ2kfhXVZxzYo1lJR/oLtPPQ3opNY70=; b=ZwHWUWpaI1u32wbEwfRB0niJx6 R9hu8b7S2ayxyCcBkuE7mzDuGi/LOxKIAZAYH7GEgzfk+zxan/+xBkzcXjsMGq5ixffAjANLVgGxX KpzYDUMRpTheAPaIPEqRF4Ayek/aEHxPuniOB/PpHBazqTrmyLPKFZ+p6kIwlvfgBqFZc3j1k/1oq cqWMRPdKXd0gzEba9MnTvwCtq15zfiR1uYTTIYXBC9cFw4DMCFpAg95vp08L0OEQGgNt5bI8jPmz2 tEBgey1STuXk7Tw1ConfIoM3wTRfRuUZvJQPCVFUH/0lNCk6dMRlX0wl4DV4LSH6bO5UvT6Dh4+2r 3rIl3bTg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lOFiS-008CCP-TG; Mon, 22 Mar 2021 08:15:15 +0000 Date: Mon, 22 Mar 2021 08:15:12 +0000 From: Matthew Wilcox To: Namjae Jeon Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-cifsd-devel@lists.sourceforge.net, smfrench@gmail.com, senozhatsky@chromium.org, hyc.lee@gmail.com, viro@zeniv.linux.org.uk, hch@lst.de, hch@infradead.org, ronniesahlberg@gmail.com, aurelien.aptel@gmail.com, aaptel@suse.com, sandeen@sandeen.net, dan.carpenter@oracle.com, colin.king@canonical.com, rdunlap@infradead.org, Sergey Senozhatsky , Steve French Subject: Re: [PATCH 3/5] cifsd: add file operations Message-ID: <20210322081512.GI1719932@casper.infradead.org> References: <20210322051344.1706-1-namjae.jeon@samsung.com> <20210322051344.1706-4-namjae.jeon@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210322051344.1706-4-namjae.jeon@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 22, 2021 at 02:13:42PM +0900, Namjae Jeon wrote: > This adds file operations and buffer pool for cifsd. Why do you want this buffer pool? Do you not trust the slab allocator to be able to do its job? Because what you have here looks slower than the slab allocator. Let's follow this through for the best-case scenario (a buffer of the right size already exists): > +void *ksmbd_find_buffer(size_t size) > +{ > + struct wm *wm; > + > + wm = find_wm(size); > + > + WARN_ON(!wm); > + if (wm) > + return wm->buffer; > + return NULL; > +} OK, simple, we just call find_wm(). > +static struct wm *find_wm(size_t size) > +{ > + struct wm_list *wm_list; > + struct wm *wm; > + > + wm_list = match_wm_list(size); First we find the list for this buffer ... > +static struct wm_list *match_wm_list(size_t size) > +{ > + struct wm_list *l, *rl = NULL; > + > + read_lock(&wm_lists_lock); > + list_for_each_entry(l, &wm_lists, list) { > + if (l->sz == size) { > + rl = l; > + break; > + } > + } > + read_unlock(&wm_lists_lock); > + return rl; > +} ... by taking an rwlock, and walking a linked list?! Uh ... > + while (1) { > + spin_lock(&wm_list->wm_lock); > + if (!list_empty(&wm_list->idle_wm)) { > + wm = list_entry(wm_list->idle_wm.next, > + struct wm, > + list); > + list_del(&wm->list); > + spin_unlock(&wm_list->wm_lock); > + return wm; Great! We found one! And all it cost us was acquiring a global rwlock, walking a linked list to find a wmlist, then a per-wmlist spinlock. Meanwhile, there's no guarantee the buffer we found is on the local NUMA node. Compare to slub, allocating from a kmem_cache (assuming you create one for each buffer size ...): void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags) void *ret = slab_alloc(s, gfpflags, _RET_IP_, s->object_size); static __always_inline void *slab_alloc(struct kmem_cache *s, gfp_t gfpflags, unsigned long addr, size_t orig_size) return slab_alloc_node(s, gfpflags, NUMA_NO_NODE, addr, orig_size); static __always_inline void *slab_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node, unsigned long addr, size_t orig_size) do { tid = this_cpu_read(s->cpu_slab->tid); c = raw_cpu_ptr(s->cpu_slab); } while (IS_ENABLED(CONFIG_PREEMPTION) && unlikely(tid != READ_ONCE(c->tid))); object = c->freelist; page = c->page; if (unlikely(!object || !page || !node_match(page, node))) { object = __slab_alloc(s, gfpflags, node, addr, c); } else { void *next_object = get_freepointer_safe(s, object); if (unlikely(!this_cpu_cmpxchg_double( s->cpu_slab->freelist, s->cpu_slab->tid, object, tid, next_object, next_tid(tid)))) { note_cmpxchg_failure("slab_alloc", s, tid); goto redo; } prefetch_freepointer(s, next_object); stat(s, ALLOC_FASTPATH); No lock, anywhere. Lots of percpu goodness, so you get memory allocated on your local node. What's the scenario for which your allocator performs better than slub, on a typical machine that serves enough SMB that it's worth having an in-kernel SMBD?