Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1520037imi; Sat, 23 Jul 2022 08:09:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1twmzilSK4fiktgdFElG9YPT7iy078ER12bmKXaa84XDFuvoS4IRsPQrx0qt79GPdrKjBeM X-Received: by 2002:a17:907:60cc:b0:72b:40a8:a5b with SMTP id hv12-20020a17090760cc00b0072b40a80a5bmr3702767ejc.379.1658588985900; Sat, 23 Jul 2022 08:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658588985; cv=none; d=google.com; s=arc-20160816; b=I3IgIqiQ0dMKP8B3Shv+L6wgVaz0SsrGPOHqSXQ3+BYl5qzOa0A+J8RiYx2YsxrTgW ssiOzph7PCzVz1W4D96cYnh3i+iIAsZ6eW9Vx/YcsoySRiJ1NHddXkx/T9q4wuwOc1Mf SLv4gwoBJ/Olvk9P+T/+9kmbqt0uzQ7Vpso26zzg0Y5Oghyj0NgnVfsOzl4zAjUUTmwE oICoRXGDXRLotbGvPMtzm2DeaR60VfAglwKegbVb83cGP5PdaGqtTgnfukx0Rg6sX7S2 c7OXj7GjdxiR+xquHPrrvme1RVNfw/TdJHHlbZfVq9OL5i1sOXin0JSAQoMP7eJ32HBr CGAA== 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=mEoPEbeOyWxlrBYzTjx3/LLOWXpb1CcPOZICGC0v96M=; b=Pk+/+rR3QmWpL5Qtr0vBlHE0YnHc+xLX+n8sSPU3vMP46jC8lAmWbS5zI9IyQ9RJug PVnLHj3mIUcF3uUNMDt+hOCJ3vRmQPPFtUbfwOXp1Py/bGiMzhsrG76DiMOmGSJk3xbt eyM3vgU5HsOOuDHSKuDwnGUQcbnqjosdQyrpSkxCX4rWd4E1GHmAnmV0AExIrYz7YxR7 Hhez85WPqbJKLBU16VH8fsp8jTLOz65VeALoWIb0ouI0/pfCwWYLdc+HCJjvXLhiSOwz 0l6vXyM7TDouCnQE3VGq48RZchrlPl0akaSIus0JDqA9tB+vmcJ9MfrwiIV4Cm6+xElt KjxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="jr/xvpvb"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i21-20020a05640242d500b0043a4cff7e3csi3424499edc.423.2022.07.23.08.09.20; Sat, 23 Jul 2022 08:09:45 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="jr/xvpvb"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237468AbiGWORy (ORCPT + 99 others); Sat, 23 Jul 2022 10:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237385AbiGWORw (ORCPT ); Sat, 23 Jul 2022 10:17:52 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7FF1183BC for ; Sat, 23 Jul 2022 07:17:50 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id b143so11252834yba.11 for ; Sat, 23 Jul 2022 07:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mEoPEbeOyWxlrBYzTjx3/LLOWXpb1CcPOZICGC0v96M=; b=jr/xvpvbVmNf+xIG0dbLCrMyluMNU3l3gZeFwLtkhnYy/4UleXz2aomwnjH+3TbMKl 11dBUhnttUE/J/yKFXfQN03yrN4WFewxF/+VJ/kcL6pFsFUOYhgePHT7kQM1GWHE4cnj J0HF2vx93jhldzsXpN3975BnFyYHwrHhHDTW6S28Y1Bp+thJmDbF88XkOqYjLcRbtVMz EymXnwDWc6excfS/Vg36Y6KXmCjFyN9Fy9ta6W1R+MsF1Y9qT+ckV60hFtIARmjwjo36 hhkKLiL31tekMRZqBQY+Ta4faait4JFH08LLjUBAqpKD/CnXK6iHsPwk/7J98gJf2WT9 7zEg== 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; bh=mEoPEbeOyWxlrBYzTjx3/LLOWXpb1CcPOZICGC0v96M=; b=Y6OBpZ+J05NXTDmag+an012cmT+7blgaYg3WIDIdwmuwWFM7Vg0+7KYMJ5wWZRrLFG WoOGMARA+dSES+CgGW65WrgHcep/JugAjQwAn6LsrPDg8+VSQdpLr2sumubNiN8dveFJ uZV8Cm6CXSUAWjcsJYW6wQgHBfVbPtDRM4aEeWN5/+hkcH6kNupjgW4d2aaghZeva/if PngxMe0diwz/1505Q2ZnO5oNviWDM9qyJ0mKh7PxD/xkRmFlQCilFgJrML8sJQhdZIfC q2lOh8HSk97f8SkGGlkmV6ldz48ariM0uLuOjNBMnbTqt1a9SUqKGj8U6G7COStqSdRG R+Zw== X-Gm-Message-State: AJIora9jpPxOUog66b+EMSmJaTgMWyKmvy/pbC7S6VmstQsT7ILnO6/V wg7Ud0C7QWyKVgQGQrdvMQEwC+bmLDL6y8OsBVEJWA== X-Received: by 2002:a25:2f4a:0:b0:670:ea89:72b2 with SMTP id v71-20020a252f4a000000b00670ea8972b2mr3546504ybv.427.1658585869576; Sat, 23 Jul 2022 07:17:49 -0700 (PDT) MIME-Version: 1.0 References: <20220722162934.1888835-1-mcgrof@kernel.org> <20220722162934.1888835-3-mcgrof@kernel.org> In-Reply-To: <20220722162934.1888835-3-mcgrof@kernel.org> From: Muchun Song Date: Sat, 23 Jul 2022 22:17:12 +0800 Message-ID: Subject: Re: [PATCH 2/2] Documentation/filesystems/proc.rst: document procfs inode timestamps To: Luis Chamberlain Cc: "Eric W. Biederman" , Jonathan Corbet , Kees Cook , Iurii Zaikin , Zhang Yuchen , David Howells , Deepa Dinamani , Christoph Hellwig , Linux Doc Mailing List , linux-api@vger.kernel.org, linux-fsdevel , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Sat, Jul 23, 2022 at 12:29 AM Luis Chamberlain wrote: > > The timestamps for procfs files are not well understood and can > confuse users and developers [0] in particular for the timestamp > for the start time or a process. Clarify what they mean and that > they are a reflection of the ephemeral nature of the filesystem > inodes. > > The procfs inodes are created when you first read them and then > stuffed in the page cache. If the page cache and indodes are > reclaimed they can be removed, and re-created with a new timestamp > after read again. Document this little bit of tribal knowledge. > > [0] https://lkml.kernel.org/r/20220721081617.36103-1-zhangyuchen.lcr@bytedance.com > Reported-by: Zhang Yuchen > Signed-off-by: Luis Chamberlain > --- > Documentation/filesystems/proc.rst | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst > index 9fd5249f1a5f..9defe9af683a 100644 > --- a/Documentation/filesystems/proc.rst > +++ b/Documentation/filesystems/proc.rst > @@ -59,6 +59,15 @@ The proc file system acts as an interface to internal data structures in the > kernel. It can be used to obtain information about the system and to change > certain kernel parameters at runtime (sysctl). > > +The proc files are dynamic in nature and allow for developers to make the > +content to be changed each time a file is read. The proc files and directories > +inodes are created when someone first reads a respective proc file or directory, > +as such the timestamps of the proc files reflect this time. As with other > +filesystems, these proc inodes can be removed through reclaim under memory > +pressure and so the timestamps of the proc files can change if the proc files > +are destroyed and re-created (echo 3 > /proc/sys/vm/drop_caches forces and > +illustrate the reclaim of inodes and page cache). Thanks for fixing this. > + > First, we'll take a look at the read-only parts of /proc. In Chapter 2, we > show you how you can use /proc/sys to change settings. > > @@ -328,6 +337,13 @@ It's slow but very precise. > system call > ============= =============================================================== > > +Note that the start_time inside the stat file is different than the timestamp > +of the stat file itself. The timestamp of the stat file simply reflects the > +first time the stat file was read. The proc inode for this file can be reclaimed > +under memory pressure and be recreated after this and so the timestamp can > +change. Userspace should rely on the start_time entry in the the stat file to > +get a process start time. > + I'm not sure the value of those comments since the above description is already enough to tell people the timestamp of /proc files or directories can be changed in some cases, which already includes the case of /proc/PID/stat. If we really want to take /proc/PID/stat as an example to show the timestamp is unstable, I think it is better to move those comments to the above section where you explain why the timestamp can be changed . Thanks. > The /proc/PID/maps file contains the currently mapped memory regions and > their access permissions. > > -- > 2.35.1 >