Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp186538pxy; Fri, 7 May 2021 00:30:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF1SKHJmO95gXhUlE/fm6ThhO0bKw5vDwuc7G2YrskHJFBjvnE+eO9pq4fn/idlAhAv5BT X-Received: by 2002:a63:4c66:: with SMTP id m38mr8589771pgl.157.1620372603643; Fri, 07 May 2021 00:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620372603; cv=none; d=google.com; s=arc-20160816; b=gM7Nq7IUEHYFll7xU+2p7yy++cZa0pD+98giwW35zXrBxlWwf+efd1l0Lg18HMU37U 0sofr7VI3NW43ccMes7IqrSOCAT3UWak90sJjDEUc7Rqlr601Vqsy5urW3lDLUz2wqSp 8fuywHyCns+BnxR6ogW5g+UKJ5cYCRJ4q4GjYl209259Ocp6yiPYg9n+jmLqOqzz0ptb cpIV+dTLslyDJm+C9FXdDWSfA4PMyYvLNph2iv7AmB8iawJwanO/Avm0qBXU40U2kEj5 z/XwWgYIg+DqarGdNc8W/L4e+od0e112WPUt9Ww/V/AVomVHO8lii2EBzY+gFayVtGEa gsLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5QMYEa6puQXBOEG+O6tTaTEgtrWwSdoO23hCLMWVhmA=; b=RJZpVKAoYY7Zl/FuHg1C4rC5t0V9HR7m+xNbrkG+E9BTGxyQqL2YfMH1VhdWhVGj4G DScfyb/3cF2DdpxkCT3QECjNhv7L9o4wn1R8TLwmf4RCrTzhGWZ7JCiRYAq76gfKWS6o lZ15sYbW3EAMXi1GcaMet5V2rLrfR5FjwahCfLEWoy6h8A1luvpXOyXtTDuqpeYZoIw5 Ms6YKuh9uynG8Yid88Cg7oSc2kN6m+buMXTQn7fgZVi/XrYDsz9TM0Hm+ce4PJJsnjQY I9n/5iXI8Y2qbfkVt1WLYpRBMZMxBx4w+NFmVREYCqY97LLjrcHL4LRtrACARdbhHWt8 z0Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b="hdyY/ZRp"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si6054413plj.248.2021.05.07.00.29.51; Fri, 07 May 2021 00:30:03 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b="hdyY/ZRp"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233897AbhEGFra (ORCPT + 99 others); Fri, 7 May 2021 01:47:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbhEGFr3 (ORCPT ); Fri, 7 May 2021 01:47:29 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EC92C061574 for ; Thu, 6 May 2021 22:46:30 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id gc22-20020a17090b3116b02901558435aec1so4770100pjb.4 for ; Thu, 06 May 2021 22:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5QMYEa6puQXBOEG+O6tTaTEgtrWwSdoO23hCLMWVhmA=; b=hdyY/ZRp0zaTHGB93v9guBByXiAWJNp82XAvn21vWb8WxO24CM2HZaJiiwXKWs235W UI+CAmzo0KybZ+vPgEvBiSfvXX1Yu85mHvxsBPJU9PdaQbFCJ6HDeMDAtLd9P6VGR116 6DBmpEhJfAEJBpe7AzbWn/r3yfA+QzAxQW2/axKv6MNb3kxg49GXHQwtQTwXrwDnzTF6 lCQoyBGfe9hJbbolVuZPADjY0sU4m4axB/4TxCIT4odv99TeM6v8ru90NNnK1Vzz6Mu6 N6kqyzSRYygq2DfqB2Z2UcirOmcOiyWjQ24lC5OXWiV3XCXzaAymp6LLlzRZEErwpT0h qG9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5QMYEa6puQXBOEG+O6tTaTEgtrWwSdoO23hCLMWVhmA=; b=VNwCk4vAGYTPRHQFeD2PPf19VFOfu/h0vhNWgwDqyzahi6LejRP6OwHFrD+LQ6atwH 1Jl3+sdgE3hXTqNgutxRSG7YSaladTTZaVHOsrZbrAMBhzl3sb9+Q99l12MPZs1tJnWS ZGciqptl2QjegdJVNhQIh5ZQHoO8qD/8SXciQjrvsf1m/LoC8GykZqWOr9u6rJ6z5ekg jfd6RperAXv4TVUlCbzkIuXUu8rSaEU05xXKyuYLTVAp/EhAfuCQGxFMqOFtqV29rmpX 3BpKTm1jvsxRkt8Skinix6wqP3DpBptbg/pDHn65K6Hq9R3vKapxJQNHLkKQ7PWKdsr9 EzEQ== X-Gm-Message-State: AOAM5319WO9qJEkD/HI6oFdvsFQKskYBzlxjh8lzxPhLjREdb6pArMHh dNlVRC9cS21LEHp9Xy3NJ4DzShem6gXP/80fh32r4g== X-Received: by 2002:a17:902:e54e:b029:ed:6ed2:d0ab with SMTP id n14-20020a170902e54eb02900ed6ed2d0abmr8084770plf.24.1620366389736; Thu, 06 May 2021 22:46:29 -0700 (PDT) MIME-Version: 1.0 References: <20210428094949.43579-1-songmuchun@bytedance.com> <20210430004903.GF1872259@dread.disaster.area> <20210430032739.GG1872259@dread.disaster.area> <20210502235843.GJ1872259@dread.disaster.area> <20210505011331.GM1872259@dread.disaster.area> In-Reply-To: <20210505011331.GM1872259@dread.disaster.area> From: Muchun Song Date: Fri, 7 May 2021 13:45:53 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 0/9] Shrink the list lru size on memory cgroup removal To: Dave Chinner Cc: Roman Gushchin , Matthew Wilcox , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Yang Shi , alexs@kernel.org, Wei Yang , linux-fsdevel , LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 5, 2021 at 9:13 AM Dave Chinner wrote: > > On Mon, May 03, 2021 at 02:33:21PM +0800, Muchun Song wrote: > > On Mon, May 3, 2021 at 7:58 AM Dave Chinner wrote: > > > > If the user wants to insert the allocated object to its lru list in > > > > the feature. The > > > > user should use list_lru_kmem_cache_alloc() instead of kmem_cache_alloc(). > > > > I have looked at the code closely. There are 3 different kmem_caches that > > > > need to use this new API to allocate memory. They are inode_cachep, > > > > dentry_cache and radix_tree_node_cachep. I think that it is easy to migrate. > > > > > > It might work, but I think you may have overlooked the complexity > > > of inode allocation for filesystems. i.e. alloc_inode() calls out > > > to filesystem allocation functions more often than it allocates > > > directly from the inode_cachep. i.e. Most filesystems provide > > > their own ->alloc_inode superblock operation, and they allocate > > > inodes out of their own specific slab caches, not the inode_cachep. > > > > I didn't realize this before. You are right. Most filesystems > > have their own kmem_cache instead of inode_cachep. > > We need a lot of filesystems special to be changed. > > Thanks for your reminder. > > > > > > > > And then you have filesystems like XFS, where alloc_inode() will > > > never be called, and implement ->alloc_inode as: > > > > > > /* Catch misguided souls that try to use this interface on XFS */ > > > STATIC struct inode * > > > xfs_fs_alloc_inode( > > > struct super_block *sb) > > > { > > > BUG(); > > > return NULL; > > > } > > > > > > Because all the inode caching and allocation is internal to XFS and > > > VFS inode management interfaces are not used. > > > > > > So I suspect that an external wrapper function is not the way to go > > > here - either internalising the LRU management into the slab > > > allocation or adding the memcg code to alloc_inode() and filesystem > > > specific routines would make a lot more sense to me. > > > > Sure. If we introduce kmem_cache_alloc_lru, all filesystems > > need to migrate to kmem_cache_alloc_lru. I cannot figure out > > an approach that does not need to change filesystems code. > > Right, I don't think there's a way to avoid changing all the > filesystem code if we are touching the cache allocation routines. > However, if we hide it all inside the allocation routine, then > the changes to each filesystem is effectively just a 1-liner like: > > - inode = kmem_cache_alloc(inode_cache, GFP_NOFS); > + inode = kmem_cache_alloc_lru(inode_cache, sb->s_inode_lru, GFP_NOFS); > > Or perhaps, define a generic wrapper function like: > > static inline void * > alloc_inode_sb(struct superblock *sb, struct kmem_cache *cache, gfp_flags_t gfp) > { > return kmem_cache_alloc_lru(cache, sb->s_inode_lru, gfp); > } Good idea. I am doing this. A preliminary patch is expected next week. Thanks. > > And then each filesystem ends up with: > > - inode = kmem_cache_alloc(inode_cache, GFP_NOFS); > + inode = alloc_inode_sb(sb, inode_cache, GFP_NOFS); > > so that all the superblock LRU stuff is also hidden from the > filesystems... > > Cheers, > > Dave. > -- > Dave Chinner > david@fromorbit.com