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 247F7C4332F for ; Sun, 6 Nov 2022 13:46:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A05028E0002; Sun, 6 Nov 2022 08:46:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C1DB8E0001; Sun, 6 Nov 2022 08:46:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A5848E0002; Sun, 6 Nov 2022 08:46:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 786C38E0001 for ; Sun, 6 Nov 2022 08:46:24 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 572651C6551 for ; Sun, 6 Nov 2022 13:46:24 +0000 (UTC) X-FDA: 80103141888.24.239B32B Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf04.hostedemail.com (Postfix) with ESMTP id C3B8C40006 for ; Sun, 6 Nov 2022 13:46:23 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id y14so23943676ejd.9 for ; Sun, 06 Nov 2022 05:46:23 -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=GvHQw3MpKj2ew4Zx/51KfKsxcxJrFJHe+YH+/eJYORk=; b=N9HjxklYjNnVUpsQa7gObZNQIWxnPEfkN9h9tvbSf93K+9IBDhZrWm5fEN3Rkw8lJU G3vs/KXs2ZAXg9NN+9S/f+Y2ZeKzsbozQ3glkgiBuFCzEsQPCPX1zgg98zjNf+sG3z2b ndESYkRIYVlPy4FH/IQiT+D3WYyDmpHFsPjUhnJBRBT9+K2Pb95goVC8TDMYiVm99n7u VGvOvrLEuu5V0KGcG3529n0VP0AJaiprJ/S1nbnG4bLTflyApzny5mWY6M78FFbVmfp6 nFCtwIQVM9JhHqQ5+Ra34PjRNbHLB4UbFncNssCaA5T1VSUCgFDGHIFx98az5sW/17RS d6Ig== 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=GvHQw3MpKj2ew4Zx/51KfKsxcxJrFJHe+YH+/eJYORk=; b=Tyvkxq9aDqowWN9Q7q3wJPmrzUKrQEgoZqtoDhpgkeasCU4Tp2kkiQKpqSPbJ70Cks z1uG+ZMWGqZBVxuhasezx375f9GqoHZvjbs9hXuQjyDFxYRjZj38Zd622u4QzBk0b5zg iQ8jT/+z1L9SmEV+vwTuslt7NmR105oHpjjKEBiqxsky83v8wXXjpDDAKky1dr3xCWp/ je4LrLMdGcC3/FpdYvD8ALhUlKVmlsz7Q8U2t5PVmICRe5OwS3MJjh/i3rjNTw+CdqSQ CvkPifbDreqxSXZ86D/nUuHNAkVS6No3SriyBT9Ssew5WXllK04Xm9FifzcJinIRU9LD 2pkQ== X-Gm-Message-State: ACrzQf0n6lZkpUS4iAwDk8GYIuhuh1N1Ived9nlO2CmxkBExPA5+NBZv fUoya6fHYMzEev27P2Ss6IMWQpkoU064mAjWX/xVUg== X-Google-Smtp-Source: AMsMyM78WuDidk5mI0iEui7TMptFInZ54NSTtJrPLDVW2NaWzWUctfakaLoEEaiVIvZFa+8OCij0apca/1fIBEpqNUM= X-Received: by 2002:a17:907:31c1:b0:742:28a3:5d08 with SMTP id xf1-20020a17090731c100b0074228a35d08mr42823663ejb.112.1667742382309; Sun, 06 Nov 2022 05:46:22 -0800 (PST) MIME-Version: 1.0 References: <20221105025342.3130038-1-pasha.tatashin@soleen.com> <20221106133351.ukb5quoizkkzyrge@box.shutemov.name> In-Reply-To: <20221106133351.ukb5quoizkkzyrge@box.shutemov.name> From: Pasha Tatashin Date: Sun, 6 Nov 2022 08:45:44 -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-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=N9HjxklY; spf=pass (imf04.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=1667742384; a=rsa-sha256; cv=none; b=KfHQJ58+JjGsIEkGxufM9cAcD3DQolxpANvorGXm/7xVb/dFnSoOX8q/7FqDJ2bZet6MbX 3iqxFy1hWuPoL8uDZsCkI0RCJkc4DdCY6MzE3c4R5sdOfacUjUv4C4N7rC/oHuy0fWmCYe AOaFkjQCefmy8zosScm1f8zS9P58tmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667742384; 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=GvHQw3MpKj2ew4Zx/51KfKsxcxJrFJHe+YH+/eJYORk=; b=icjeKERhktMRQqpRhkx9YyLA7eNx/Ox8enbTFvkT04CBKqZzNoeQAci3gc/TSdl3smlwJs nWi5D8xbn7wTyCIDuArYpCv4kFHkkCnvPKI/j0T8N2TuEHyBHs3nZMlGIxd2DTBRNCGV57 dHr7Y+5Kbpe7zPg8sKmGkUjb1BXrMGc= X-Stat-Signature: me5b7btymim3a8jcipjc9axbegdobdmu X-Rspamd-Queue-Id: C3B8C40006 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=N9HjxklY; spf=pass (imf04.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-Rspamd-Server: rspam05 X-Rspam-User: X-HE-Tag: 1667742383-840897 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 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. Since this is anon memory, we can get rid of the /dev/zero path part entirely and only print the name when the user specified one, but this would change the output in pmap command to show all anonymous shared memory as simply [anon]. Pasha > > -- > Kiryl Shutsemau / Kirill A. Shutemov