Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp30375rdb; Mon, 15 Jan 2024 10:55:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPVnsxMnCiAq0R/D++bfObo9x548kCyUXaiZo/o3/3q3cZAiyz4ATcHEw0d/cryNrGeGPI X-Received: by 2002:a05:6a20:879f:b0:19a:366e:8339 with SMTP id g31-20020a056a20879f00b0019a366e8339mr4972241pzf.75.1705344946228; Mon, 15 Jan 2024 10:55:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705344946; cv=none; d=google.com; s=arc-20160816; b=bMBVJDOqAbx4jtS0GESZoWI6+nQBk6pheoiTvukW6RsxDcNVciF10MwQEfTFfYsBH8 piPvdvpJgc27IjSrIU7yxntvlPOIT6mDKU8t0SBADHz7KMqFRafC44FHqyHlEYQkpYHN m/pPE2smaZQKQ9MEQ9wOnpn3ef9TmcSSMajb4B5xpyCRhk4u1XC+HHiTGshVHShgIjAM 5H/I/GZq3BKOYTy7tPCLfJo9sb1Iw+6/BoCPyMrO3OJQ9BCoBVSHKkMMfMhCEDSiBJrv ehzHj+xdmHPSyjiv9LXEKoK6v088CPB/c0OMnzn2w5tbT1WNqnGq1KALPk2JIzma5Wdk YK7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=h71RO1NDquEnr4gtDmmeh0KDfuRnGTvN/5LqJWciXao=; fh=HVx+l6ikhg+n58FeoeQPBmJNbG13f9lDW9HE3xPzAhA=; b=nJzKnoVBLYgq9s8Cr3NyFsaTBZzRKF2hSf4BcyrsdwOGQIAxyZCtWFp6vh17b/7QEt 6yqpmRg8ngBbJG9laeiB8e1fg9yOfh34NkxQnDqWjymjxCytP0VJ6Um3a+Q2SPnY1pby YfXh4Txu8+YNGfHZK6Rs43MDD3qow0mCL8FQeOPUSaEDAwuINOZxRmHU6EAftO6EkTWX +d3oFylGdrdPgWGrnTHz1CI18oiSDXiYXW0vIZDLBXLRZQh1cz4Hkazt6uFKWiA8/qzb k0mC0F/TR/l5xMOHmbrq033OKAjQcurWaxGig4JSzrhnSkWn4Rum0IeiTqcklH8r1kNK 3tag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PWFanYlo; spf=pass (google.com: domain of linux-kernel+bounces-26400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bx11-20020a056a00428b00b006db752cf3c0si3587785pfb.257.2024.01.15.10.55.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 10:55:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PWFanYlo; spf=pass (google.com: domain of linux-kernel+bounces-26400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D9344285CEB for ; Mon, 15 Jan 2024 18:38:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44DC018E29; Mon, 15 Jan 2024 18:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PWFanYlo" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D26AB18E08 for ; Mon, 15 Jan 2024 18:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5f9e5455db1so87570687b3.1 for ; Mon, 15 Jan 2024 10:38:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705343921; x=1705948721; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h71RO1NDquEnr4gtDmmeh0KDfuRnGTvN/5LqJWciXao=; b=PWFanYloImSYzyDoqoTyA69nj7jbjEpC6UyPJdXM6KZvqfEvuQYJGsgGyxRkmvLDmP HGMGLjvb0eD1Dps13pQEcAEU/J5JOGKYT3Ic+abp7Tff/RoDLrF2N7SUNO6vwuY017OA wmMKxssPsj/Ic3P8PQTq6zbaJlhCxGnehTQcs/fMp/eMvaiRCRR1Pn/mcQTsyoAUK6F5 QVpq1v/PlYWNHDPDXOSBH9f6LzS/mryaqRQgJ17LbnsVTEmTbqHoTfMxjLss26TqMGWf mEdI8B281lEW+/IxLMMva/jFGcBObMN7P2HK3xfN/yDRX8aXfY7+EEyClt+xV1INvmZi MfjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705343921; x=1705948721; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h71RO1NDquEnr4gtDmmeh0KDfuRnGTvN/5LqJWciXao=; b=gTCy2rZH1RAVeUW3S7X/i4JVg+hs23nYGTH+J6EOL/7GAmLJ007FZwv3AE6/7ocxBe L3I/OSoks5eABPKGk9+OJrMR6p4F+LmXzMQL+8aU7MDH9qsAC3aoHiDk11/ZuwyTAO/2 58R0aXxfzQTYJM3rjHHLi7VXfXWLTDOrXmmkFU4JPLKJ4Bn/0fC5mU2b11w28xmnQptO EiSWB8alaJvsz6DMfRvn+KC0t+FkOD4W9pH3bZuLz4YnlIrGgaWZLRCqPTkmvRZiWygo c/QE8qh64gBrtsX4+Z1smF+t15aq1D+Myx/cHeOuQuKs9+ik1bsDXpw5Of6hcjPqhFV3 FSXw== X-Gm-Message-State: AOJu0YxuqoHB/Mrk7prRPNwU7TreBMDINkHhdXWX3WXLQCZuUsBB1VIL UDn9kWCi2AmT1OAvrTs7K/dCU9/mh1I/vpHEuw== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:3af2:e48e:2785:270]) (user=surenb job=sendgmr) by 2002:a05:6902:2490:b0:dbe:f1e8:ae66 with SMTP id ds16-20020a056902249000b00dbef1e8ae66mr231824ybb.5.1705343920890; Mon, 15 Jan 2024 10:38:40 -0800 (PST) Date: Mon, 15 Jan 2024 10:38:33 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.381.gb435a96ce8-goog Message-ID: <20240115183837.205694-1-surenb@google.com> Subject: [RFC 0/3] reading proc/pid/maps under RCU From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, dchinner@redhat.com, casey@schaufler-ca.com, ben.wolsieffer@hefring.com, paulmck@kernel.org, david@redhat.com, avagin@google.com, usama.anjum@collabora.com, peterx@redhat.com, hughd@google.com, ryan.roberts@arm.com, wangkefeng.wang@huawei.com, Liam.Howlett@Oracle.com, yuzhao@google.com, axelrasmussen@google.com, lstoakes@gmail.com, talumbau@google.com, willy@infradead.org, vbabka@suse.cz, mgorman@techsingularity.net, jhubbard@nvidia.com, vishal.moola@gmail.com, mathieu.desnoyers@efficios.com, dhowells@redhat.com, jgg@ziepe.ca, sidhartha.kumar@oracle.com, andriy.shevchenko@linux.intel.com, yangxingui@huawei.com, keescook@chromium.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, surenb@google.com Content-Type: text/plain; charset="UTF-8" The issue this patchset is trying to address is mmap_lock contention when a low priority task (monitoring, data collecting, etc.) blocks a higher priority task from making updated to the address space. The contention is due to the mmap_lock being held for read when reading proc/pid/maps. With maple_tree introduction, VMA tree traversals are RCU-safe and per-vma locks make VMA access RCU-safe. this provides an opportunity for lock-less reading of proc/pid/maps. We still need to overcome a couple obstacles: 1. Make all VMA pointer fields used for proc/pid/maps content generation RCU-safe; 2. Ensure that proc/pid/maps data tearing, which is currently possible at page boundaries only, does not get worse. The patchset deals with these issues but there is a downside which I would like to get input on: This change introduces unfairness towards the reader of proc/pid/maps, which can be blocked by an overly active/malicious address space modifyer. A couple of ways I though we can address this issue are: 1. After several lock-less retries (or some time limit) to fall back to taking mmap_lock. 2. Employ lock-less reading only if the reader has low priority, indicating that blocking it is not critical. 3. Introducing a separate procfs file which publishes the same data in lock-less manner. I imagine a combination of these approaches can also be employed. I would like to get feedback on this from the Linux community. Note: mmap_read_lock/mmap_read_unlock sequence inside validate_map() can be replaced with more efficiend rwsem_wait() proposed by Matthew in [1]. [1] https://lore.kernel.org/all/ZZ1+ZicgN8dZ3zj3@casper.infradead.org/ Suren Baghdasaryan (3): mm: make vm_area_struct anon_name field RCU-safe seq_file: add validate() operation to seq_operations mm/maps: read proc/pid/maps under RCU fs/proc/internal.h | 3 + fs/proc/task_mmu.c | 130 ++++++++++++++++++++++++++++++++++---- fs/seq_file.c | 24 ++++++- include/linux/mm_inline.h | 10 ++- include/linux/mm_types.h | 3 +- include/linux/seq_file.h | 1 + mm/madvise.c | 30 +++++++-- 7 files changed, 181 insertions(+), 20 deletions(-) -- 2.43.0.381.gb435a96ce8-goog