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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 6664CC433B4 for ; Fri, 7 May 2021 05:46:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E3A6F61075 for ; Fri, 7 May 2021 05:46:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3A6F61075 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 81CBF6B0088; Fri, 7 May 2021 01:46:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A5456B0089; Fri, 7 May 2021 01:46:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 620E16B008A; Fri, 7 May 2021 01:46:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 413DB6B0088 for ; Fri, 7 May 2021 01:46:35 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F3BAE8249980 for ; Fri, 7 May 2021 05:46:34 +0000 (UTC) X-FDA: 78113350350.25.426396C Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf29.hostedemail.com (Postfix) with ESMTP id E1F48EF for ; Fri, 7 May 2021 05:46:26 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id x7-20020a17090a5307b02901589d39576eso2032537pjh.0 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=RyJ1uxJDAz5+MlZvd5+jvx0UnE+xHoCcDMlULsT58BV3lFYPs/DAY5G1aKsuFcX5dR klxtuoLZ76MooXVVIy4bBvO90LMVmXKjAY2spC1U6z3QhZm1CGGgF2vhMdR8CHiRWCrm 1jBFbmqXwDkAzDc4jroBNLG8XOM3LQhkpIvumpYZahHkz6jZfmc5cFgR2Zk3k/qqk/Yb vFI6E1R9kRfcYAE91QuU2l09qPfOMvJUIFe1rgPagAgRfysA0rylxXXxyMCRPGQfTJpx odC3me82NE1u1m64ifUO4lGsOBNfxzW12rTi3aOPSLxHwLCima7KrtjKf4QbELaTL7KZ trFQ== X-Gm-Message-State: AOAM530bwRl2c88je7lSRHfAQtJPT3Rvm5KGciZsWK+NfxW6ILn8YIF6 er9G/FIYdF78aXVNWTNxBeT4dQY+9aP9FE0Lsup55Q== X-Google-Smtp-Source: ABdhPJwBHnWooalbHPmdSUpXCowHfy3SHRmS+7fnjNEon7F2Y9NK9R/hhSADwZCSxVqHcubCFzZvs7pRBteBN2R6fAU= 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" Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b="hdyY/ZRp"; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam03 X-Stat-Signature: cbhsrohuo53i98137s4qho5ew1j7u457 X-Rspamd-Queue-Id: E1F48EF Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-pj1-f54.google.com; client-ip=209.85.216.54 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620366386-936433 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 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