Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2005407rwb; Mon, 7 Nov 2022 08:07:35 -0800 (PST) X-Google-Smtp-Source: AMsMyM70z+Lu9aJ+OOT5XbKxZFn8Zw6bEqE+FMWxgTzPBacNtaxWubKXAEQGyiL5y4YAbFacA4yu X-Received: by 2002:a17:902:e945:b0:186:ba20:76e8 with SMTP id b5-20020a170902e94500b00186ba2076e8mr51848387pll.165.1667837254883; Mon, 07 Nov 2022 08:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667837254; cv=none; d=google.com; s=arc-20160816; b=OMchTLexK1mR9Gd/tEPHh+jb2di9d77JIuPBYui7m2+w67GwtrF7EdGm2SLWc2btc8 shf68z6PW4biptOUZvV3d3skd4jn4Mvp+HoYvswxZpPi47Dt7K3+zpEgx4W+PxslQjiR GOYkycDx4vDoztZN3dTaZSbDSge6KsQ7beWP13G8J5sPw12m1J6uVxywoY8QAeIgZH2n IEM0MAMvdwuUQgz1Po5bQGblAapP7ts7AYzPRyUdSP7mDtSJ6/SMxPMm1TwmEnaOa11z pqEILNEQu7Sz5A9NfgWBedm8H0z1JsniIXcZbGFoufR4LRZypOmMHUSDaqiV9/YYmNLi O2qQ== 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=IITd8EQrY06zpsnvdK0dLKdgj3UcdcbIn9cavEKCvvE=; b=pftmnitdY7wHvVQahyEJK2Q7j6UEDbvbA0uwRDYt7gMKY5R+zTptiHrNf1WHt6EKWm o/I04VJsS4PHh9fYYmsNj68yLGx52yQBmLzdOQ29RDPPGV6DSYQ0to2/ESHYXSnUrgmT GmlEkNBCD869L8Q14qcEjfGokz7PPabieN6sAYmtQiJ1EC4C/XAAk6zPLK+B0zD1gZNU 2mR8yprKo1NVDK2tYNlAxVUfkwVo6J+aMBdKh5n+xEAHpyYOAt8jQWN4IRg1GMfCYTlH k/rIxLKAsqGRkz3cd/QIGtw9OBOBw4JrzILQCcGaLdi+5VylEit05ZKZUr8MWsroBpMb 6pxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=Zyh+TFzt; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a056a00130200b0056238741ba7si12216645pfu.174.2022.11.07.08.07.19; Mon, 07 Nov 2022 08:07:34 -0800 (PST) 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=@soleen.com header.s=google header.b=Zyh+TFzt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232475AbiKGP7t (ORCPT + 92 others); Mon, 7 Nov 2022 10:59:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbiKGP7r (ORCPT ); Mon, 7 Nov 2022 10:59:47 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 604DA6361 for ; Mon, 7 Nov 2022 07:59:46 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id sc25so31257575ejc.12 for ; Mon, 07 Nov 2022 07:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IITd8EQrY06zpsnvdK0dLKdgj3UcdcbIn9cavEKCvvE=; b=Zyh+TFztkylFfIJjhF7e3ln1pqKsHjlcPRTlwDPW040eSVRHTt0unIS2z0vhwrpwlR gMP2vb8ln3hscKXDKYkmMnQ3/qm/hIdHKiLQoJCZuasZgekNVu57Prdtuk6LnIq0MqzT +fz1ya4IIIMn4+c5F640/fuxSsWS8PjcHvyVyhjL72Fxxl36TdXJrwBW1ZP7cnZENFHS zLmY+Ta1T+fdWDBBKIvf92W8VN/gKQ5/8PebZRqH8GSJBwusRTFXJl4UV/jSMmL9Muk+ wzdu8GwFLpVkPfuEA2Ra1EVIiwqIwHqvGWB1OoJVr72DmJB3xNUS/1WayxPrN6MAqY05 nQog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IITd8EQrY06zpsnvdK0dLKdgj3UcdcbIn9cavEKCvvE=; b=H7musHinXxfias+jsckd2SZE5++Nih7wKQ3yNyl7wqPwlcFoCTz4viiA1g9knGiU2W MrFRmUhDh7tl9z66ga1u8/rTU7tlQnBwV7a3hhoQXj/qgFr6+MhVWJIRlf3Zy53GAKpB ody0J4D4ArHyfOZDvojpskc1Tsvrw7z9bo483KPjOSk8p7kBM1/TvCH+VUH66+CiQSV2 d1XatnEHC4Amb3r4sEeoN82gDZa/FNz4YaQ/UOCX09KimgH0nwv/S7nc+wtvTXEkgEJ9 Gj+AwI5sd3J9LevrU8nJiXjy35fNu1ClqEo0crLevJhGoOrqHf7cOAk5/G++8rRMytyf WD2Q== X-Gm-Message-State: ACrzQf0agg2Pej9GFJGJRnXP28Zn457pNMdPT/0zUfWYk1Uof+e5ZXxE oVnOxjYdAi2KTmWjjmP36xCVDttbJhC1Vu1FeUsPkw== X-Received: by 2002:a17:907:c26:b0:7ad:f6c8:d6c with SMTP id ga38-20020a1709070c2600b007adf6c80d6cmr31255335ejc.640.1667836784893; Mon, 07 Nov 2022 07:59:44 -0800 (PST) MIME-Version: 1.0 References: <20221105025342.3130038-1-pasha.tatashin@soleen.com> <20221106133351.ukb5quoizkkzyrge@box.shutemov.name> <20221106165204.odb7febmnykhna2h@box.shutemov.name> In-Reply-To: <20221106165204.odb7febmnykhna2h@box.shutemov.name> From: Pasha Tatashin Date: Mon, 7 Nov 2022 10:59:08 -0500 Message-ID: Subject: Re: [PATCH] mm: anonymous shared memory naming To: "Kirill A. Shutemov" Cc: corbet@lwn.net, akpm@linux-foundation.org, hughd@google.com, hannes@cmpxchg.org, david@redhat.com, vincent.whitchurch@axis.com, seanjc@google.com, rppt@kernel.org, shy828301@gmail.com, paul.gortmaker@windriver.com, peterx@redhat.com, vbabka@suse.cz, Liam.Howlett@oracle.com, ccross@google.com, willy@infradead.org, arnd@arndb.de, cgel.zte@gmail.com, yuzhao@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 On Sun, Nov 6, 2022 at 11:52 AM Kirill A. Shutemov wrote: > > On Sun, Nov 06, 2022 at 08:45:44AM -0500, Pasha Tatashin wrote: > > On Sun, Nov 6, 2022 at 8:34 AM Kirill A. Shutemov wrote: > > > > > > On Sat, Nov 05, 2022 at 02:53:42AM +0000, Pasha Tatashin wrote: > > > > Since: > > > > commit 9a10064f5625 ("mm: add a field to store names for private anonymous > > > > memory") > > > > > > > > We can set names for private anonymous memory but not for shared > > > > anonymous memory. However, naming shared anonymous memory just as > > > > useful for tracking purposes. > > > > > > > > Extend the functionality to be able to set names for shared anon. > > > > > > > > / [anon_shmem:] an anonymous shared memory mapping that has > > > > been named by userspace > > > > > > > > Sample output: > > > > share = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, > > > > MAP_SHARED | MAP_ANONYMOUS, -1, 0); > > > > rv = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, > > > > share, SIZE, "shared anon"); > > > > > > > > /proc//maps (and smaps): > > > > 7fc8e2b4c000-7fc8f2b4c000 rw-s 00000000 00:01 1024 > > > > /dev/zero (deleted) [anon_shmem:shared anon] > > > > > > > > pmap $(pgrep a.out) > > > > 254: pub/a.out > > > > 000056093fab2000 4K r---- a.out > > > > 000056093fab3000 4K r-x-- a.out > > > > 000056093fab4000 4K r---- a.out > > > > 000056093fab5000 4K r---- a.out > > > > 000056093fab6000 4K rw--- a.out > > > > 000056093fdeb000 132K rw--- [ anon ] > > > > 00007fc8e2b4c000 262144K rw-s- zero (deleted) [anon_shmem:shared anon] > > > > > > > > Signed-off-by: Pasha Tatashin > > > > --- > > > > Documentation/filesystems/proc.rst | 4 +++- > > > > fs/proc/task_mmu.c | 7 ++++--- > > > > include/linux/mm.h | 2 ++ > > > > include/linux/mm_types.h | 27 +++++++++++++-------------- > > > > mm/madvise.c | 7 ++----- > > > > mm/shmem.c | 13 +++++++++++-- > > > > 6 files changed, 35 insertions(+), 25 deletions(-) > > > > > > > > diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst > > > > index 898c99eae8e4..8f1e68460da5 100644 > > > > --- a/Documentation/filesystems/proc.rst > > > > +++ b/Documentation/filesystems/proc.rst > > > > @@ -431,8 +431,10 @@ is not associated with a file: > > > > [stack] the stack of the main process > > > > [vdso] the "virtual dynamic shared object", > > > > the kernel system call handler > > > > - [anon:] an anonymous mapping that has been > > > > + [anon:] a private anonymous mapping that has been > > > > named by userspace > > > > + path [anon_shmem:] an anonymous shared memory mapping that has > > > > + been named by userspace > > > > > > I expect it to break existing parsers. If the field starts with '/' it is > > > reasonable to assume the rest of the string to be a path, but it is not > > > the case now. > > > > This is actually exactly why I kept the "path" part. It stays the same > > as today for anon-shared memory, but prevents pmap to change > > anon-shared memory from showing it as simply [anon]. > > > > Here is what we have today in /proc//maps (and smaps): > > 7fc8e2b4c000-7fc8f2b4c000 rw-s 00000000 00:01 1024 /dev/zero (deleted) > > > > So, the path points to /dev/zero but appended with (deleted) mark. The > > pmap shows the same thing, as it is looking for leading '/' to > > determine that this is a path. > > > > With my change the above changes only when user specifically changed > > the name like this: > > > > 7fc8e2b4c000-7fc8f2b4c000 rw-s 00000000 00:01 1024 /dev/zero > > (deleted) [USER-SPECIFIED-NAME] > > > > So, the path stays, the (deleted) mark stays, and a name is added. > > Okay, fair enough. After thinking about this, it makes sense to remove "path" entirely. The pmap without arguments will show the user named segment as "[anon]", but with -X argument it will show the full name: pmap -X 7fa84fcef000 rw-s 00000000 00:01 1024 262144 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [anon_shmem:named shared anon] 7fa85fcef000 rw-p 00000000 00:00 0 262144 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [anon:named anon] In my opinion this is better to stay consistent with regular anon memory, and also to minimize the chance to surprise the existing scripts. Pasha > > -- > Kiryl Shutsemau / Kirill A. Shutemov