Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2163033pxp; Fri, 18 Mar 2022 04:58:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE/X404TZhO7qjwaEY7d18RSYqTnfLQF1U6adGgxuTeZzdJkA5N00cG/vxX4CWAQEU8adl X-Received: by 2002:a17:906:6a0f:b0:6d7:1021:2bd2 with SMTP id qw15-20020a1709066a0f00b006d710212bd2mr8980364ejc.395.1647604682029; Fri, 18 Mar 2022 04:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647604682; cv=none; d=google.com; s=arc-20160816; b=tIj7XJItL3QACp+eh5P6aX80mbpRJ0KM1UHbTZd3t7UvkTFXLP8RWqYa/1X2HkaXtX 4Fgl6PujCNyybtVN4ipr2eMdMHaZdgDMkN20j+sLmYQVeKGrbLla5UBph8PbkZgjvZNO 3uR7cmyKuFAS2v3SyhMVMYCA5DHi7weK9+Uz3ehaIXiinJb+VDnsp45V3MwTZuigN9Xh +rot72HvW3azYFcCV+Fqn3T0yhPrnDSYpzYjDz9X/yO/n+H2QzY1NMDE2LX3drA8IZA9 LOjnntVCjgJj0S5GBoD0bdvLbo6dBF9KEJ0USpHotixiQSjAtjyf5YY8iwuZfNO+JMlh du5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ah0sFHBrNeCGFAv3lamX5tp5CChwx2V2ddiNsKmIEZU=; b=xtHZaz9wz3p1rZMzDOJurBMhBQRQUt/r6Cpmcj9X6IrVtbsnQvxlNfEPgnXh3uzGqM 04/FBq7hieJ0FGOqPgufdP0gvLmKAH4Xl2ud7NSbIqCBdtkb/SVC2fq4dnCz1PN6Qx13 DeSTVKaCUzzRWdt1wh47hciHSxWcZwDVDHw0GNGhJH+DkcKwGJyik0sgB6HamqfkRKdf 70nQXIbzKdrZnR/Yr8gmBmYQMoYdLkm0jlkkPIg5LWoipkBSAooJBodqL/YMhqUMK85u jB8PvkaI7C6Ts3o+2WzKlK/VQVsr/Oe8uCNyDtd5pHUUnCFXK39F3WHV9/8OrrSdIWgU ybgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ENEJUMO5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a170906270200b006df76385e97si1167381ejc.823.2022.03.18.04.57.37; Fri, 18 Mar 2022 04:58:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ENEJUMO5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbiCRGwt (ORCPT + 99 others); Fri, 18 Mar 2022 02:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231635AbiCRGwq (ORCPT ); Fri, 18 Mar 2022 02:52:46 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772FA205BC3 for ; Thu, 17 Mar 2022 23:51:28 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id hu12so5899854qvb.6 for ; Thu, 17 Mar 2022 23:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ah0sFHBrNeCGFAv3lamX5tp5CChwx2V2ddiNsKmIEZU=; b=ENEJUMO5x78+VpstvWRt5QR96WX9DzLVsA/B/NIjCyezFxTehliQwXn27dYcnDaxfY dNRzD0yCoxib68Tc+HXSXLdevRvUQrhwUGC+ninc1STy/q9vPfHEL0qKpgN11wifZ5So cdpXsRYm6sC5fweNWbF3fCduBD36es03DWGlBZmDanI7wyMmHgNoXni5KCPGCFFnZeIS IZk0DWhhYFJErNJa7iUiAwpjp30CdJBzHRhuzAgN2YCHqAK/ifAed1UV0btNGf5p83Ar 6osnY9QtWd92qecolbdxQEk3w473sjcDK/OhaRzJb5muvtObG9HSSFoqOD6kmpxagy+q xJJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ah0sFHBrNeCGFAv3lamX5tp5CChwx2V2ddiNsKmIEZU=; b=d35t4XBiSAwWRxHXu/FcgaY6jyx44D6Haqbl3NIjrKotnOrGjAKvzmqJbNfitLgcew P0Bhe5h/YI6KAHDyKIWMgMqM5FXCpn7KMBTGXNfEapevBRxAmKjncMHtmMd4HMD1emVY C/MBIx+TOfy3h70GBdxbFdkRgXDchfn3w+Xu4TZIWczAq+63DnhdEovl1I4FE92DHrpP fei5L3T0vf8jrhsHD0Iz5Er9ON1N3No8czXDucow3+SGpdwbX9LaQe+V1VWKt8g+qdsi jeDYAKntf4CR00l/kKlS5+5I/iEwFkElbqAve+RhiwZn6HyRRTteLA2HCsrTpX/MQ+TC cV4A== X-Gm-Message-State: AOAM530oIe2LU17xPlJM27igLITx2pDNQvtm0iCJeyo4ohS9KThtiJ9o FfDrjEbDss0NtsZWAlrWmacYtO0v4qIlO800z/91nVkDlfA= X-Received: by 2002:a05:6214:5297:b0:435:7a09:1eb9 with SMTP id kj23-20020a056214529700b004357a091eb9mr6117166qvb.127.1647586287576; Thu, 17 Mar 2022 23:51:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: hui li Date: Fri, 18 Mar 2022 14:51:15 +0800 Message-ID: Subject: Re: discussing about proc_misc_d_delete To: Alexey Dobriyan Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yes, there may be overflow problems when increased very rapidly (refcout of /proc/pid/net/). Dentries are put on lru as they may be accessed again in the future, these dentries will never be accessible for the system, keeping them on lru is a waste of memory, releasing them may be a better choice. In the production environment, we see more than fifty million proc_inode_cache, using "echo 3 >/proc/sys/vm/drop_caches" takes long time and may cause performance problems as drop cache is a heavy work. Besides, we believe that in function drop_pagecache_sb there is a chance that s_inode_list_lock may be held for long time as "inode->i_mapping->nrpages =3D=3D 0" is always true which may defer inode creation and deletion under /proc when there are too much proc inode caches. Alexey Dobriyan =E4=BA=8E2022=E5=B9=B43=E6=9C=8817=E6= =97=A5=E5=91=A8=E5=9B=9B 17:54=E5=86=99=E9=81=93=EF=BC=9A > > [cc linux-kernel ] > > On Mon, Mar 14, 2022 at 11:54:37AM +0800, hui li wrote: > > We noticed that, commit 1da4d377f94 (=E2=80=9Cproc: revalidate misc den= tries=E2=80=9D) > > introduced proc_misc_dentry_ops as default ops for /proc dentry, > > dentry ops for /proc/pid/net/stat/ is set as proc_net_dentry_ops, > > which will revalidate dentry each time when this path is resolved and > > dentry for the stat file is removed from dcache. This time, if files > > under /proc/pid/net/stat/ are in use, then dentries of these files > > will be put in lru when closed, which is meanlingless, as parrent > > dentry (stat) of these files are remove from dcache. > > > > This can be reproduced when use linux command "while :;do du > > /proc/;done=E2=80=9D, then refcount of each dentry of /proc/pid/net/sta= t/ will > > increase rapidly which should be deleted at once. > > Are you worried that reference count can overflow? Those dentries will be > flushed eventually and reference count goes back to normal values. > This is easy to see with "echo 3 >/proc/sys/vm/drop_caches". > > > I think this problem may by solved by checking whether parrent > > dentries are in d_cache inside proc_misc_d_delete, or set > > proc_misc_dentry_ops->d_delete =3D always_delete_dentry, just as what i= s > > used in kernel version 4.x and 3.x. > > --- a/fs/proc/generic.c > > +++ b/fs/proc/generic.c > > @@ -236,6 +236,16 @@ static int proc_misc_d_revalidate(struct dentry > > *dentry, unsigned int flags) > > > > static int proc_misc_d_delete(const struct dentry *dentry) > > { > > + struct dentry *p; > > + for (p =3D dentry->d_parent; !IS_ROOT(p); p =3D p->d_parent) { > > + if (!spin_trylock(&p->d_lock)) > > + break; > > + if (unlikely(d_unhashed(p))){ > > + spin_unlock(&p->d_lock); > > + return 1; > > + } > > + spin_unlock(&p->d_lock); > > + } > > return atomic_read(&PDE(d_inode(dentry))->in_use) < 0; > > }