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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BEACC433FE for ; Mon, 7 Nov 2022 15:59:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84EF16B0071; Mon, 7 Nov 2022 10:59:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FECE6B0072; Mon, 7 Nov 2022 10:59:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C6656B0073; Mon, 7 Nov 2022 10:59:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5AB226B0071 for ; Mon, 7 Nov 2022 10:59:47 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 229051A017A for ; Mon, 7 Nov 2022 15:59:47 +0000 (UTC) X-FDA: 80107106814.13.D82A919 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf15.hostedemail.com (Postfix) with ESMTP id 828EAA0009 for ; Mon, 7 Nov 2022 15:59:46 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id ud5so31387903ejc.4 for ; Mon, 07 Nov 2022 07:59:45 -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=nCjvdYWg2GwWY78f8W5G7YD1BLmGL7Iu8TZjmFqZCger3S3W5YbIBFT6fGD7fk4WkG fuB7dF3vUCI1VlFkb6poHtMSru8fFYhJuW8jWMjb9DkiBu6dmeGAZmcfSRzdjS//QJQF 9ponXPoPJjqe+LEh4qbAFsp1Kr4b/Lg/bu6c9UDC1OIVxtZ4eAp39hvL7Cg7Xd5ZGjcP YQRUzbESpARBqKdNFLzCUnFTH23BcsYAjR9mqkO7b/B91zdy95WIo+HFPQOaUdXb1ek4 3puQAl6/BHzIBN9i9wB+UDyBHGERMPICnNUbIFwr7ARqagmpH2djQlU+5PMYOmBs2WH/ fDWw== X-Gm-Message-State: ACrzQf3eZHG+LwRggVdG3966mGup27VHJFEJQ6Ir+67TCIhEGtsr+sR6 ItQDOo0CaizM5aMgDZvPSDYaVO0IVPK0ZcVpMuewfw== X-Google-Smtp-Source: AMsMyM6eF24oy4Q00nqEXNLtxRfg2QD7eeW1/AHtxkxp9g4K556Ph5XLWbzIFR8X3u4YTP0rNgLgqHrCfId/TXUbV0U= 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667836786; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IITd8EQrY06zpsnvdK0dLKdgj3UcdcbIn9cavEKCvvE=; b=TTpavqU12RBfzpJ0uC1Lh2kVCqVeWGLvHGUthmEKFWm7WTmU9sWUN2dIdYx1l+WMjTVAwc FV2S6UomKkEwsmpSHDWiVJmzbdRxpEY6rezF5z0VzKb1z1khmI7IOM5/QtlBDHf/yRh+Fa d8ci43sHneJi6zr8Za4gWAX3kgsmARI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=Zyh+TFzt; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667836786; a=rsa-sha256; cv=none; b=PJ5sa8iiCQUNm6isFa8outbeCimtBMIofF/UVfbelczziMVFZwSoQID/+7hokr3vcZS8JK iYxA1yYm1C7doo4kRUoLosxbpnn8ifauXsYTaLJJMk2cZJ+Fn87guDUjiKwM+7ZqxeNV8s J8hcTiNx+gmxmDY9N+tP4GAfv3eYjus= X-Rspamd-Queue-Id: 828EAA0009 X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=Zyh+TFzt; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Stat-Signature: mcdfundhj6ncryd1bocxgsezz3hn5n6n X-HE-Tag: 1667836786-842860 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 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