From patchwork Mon Jan 15 18:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13520079 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 7262CC3DA79 for ; Mon, 15 Jan 2024 18:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAC0E6B0080; Mon, 15 Jan 2024 13:38:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5C486B0083; Mon, 15 Jan 2024 13:38:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D24BF6B0085; Mon, 15 Jan 2024 13:38:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BFD5C6B0080 for ; Mon, 15 Jan 2024 13:38:43 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 75C5240541 for ; Mon, 15 Jan 2024 18:38:43 +0000 (UTC) X-FDA: 81682406526.28.5CEEEA3 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf17.hostedemail.com (Postfix) with ESMTP id CC7FC40006 for ; Mon, 15 Jan 2024 18:38:41 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eFu+YUbO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3sHulZQYKCHEhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3sHulZQYKCHEhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705343921; 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: references:dkim-signature; bh=h71RO1NDquEnr4gtDmmeh0KDfuRnGTvN/5LqJWciXao=; b=JqaX8DQb8fu8GkfVR/UPLN9dOODqhqrEAHSj2wRd93uINY93IJKcGt3c+LDHRXHxJx2Ql/ OK6HQEcb5Vnhajz2CXIjl8C2SAhENmY7waMirvYQd7NqbOOujnfs+cCEFDpcC2RBWW7S83 MpNOcZgfZPeHH2V1iJ2SECVp8Bv7GKM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eFu+YUbO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3sHulZQYKCHEhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3sHulZQYKCHEhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705343921; a=rsa-sha256; cv=none; b=iJUvBArCxrG85PkUvqIyLWoeVf8+mLdXMLqvF4CDYmtG3AicyP/Wy2k/0e5BhdE5sQrskx WTCKzIPwH+/BZJhCQ6ixSJ6foSxowNHBH8f50jU45YJdXcu572hJd4HB15rXWnGh2sRCSK kuEbGusX3zpNTGVXc7BgiCcBmtPZQuQ= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbed0713422so7030455276.0 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=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h71RO1NDquEnr4gtDmmeh0KDfuRnGTvN/5LqJWciXao=; b=eFu+YUbOxR1tJQSit6H3fwInE6qbTnkmRCxfDiyz9oVeI6Uv89UbybudLwpIG6gk30 3in2QuWRR6sLZXnyh0qhTwqsuFzDfVtzaOCNRdYH3b96hbRM8e7994r9CT1j5b0tLWem u/7HAAs//SleLYYCBiUdr4eghYGCUoGU0FRaFm3CGhaX1yzjZnfs/dIfrl28EwF0Wgbb 5K3BGTJvPp0Cfi6fDvK34AsWDy3NFMwXGNsgS+NNKtc02HpInHdfC8zwfjkQi9pqifuH 7nCYV9uyBhSfpJ1FiiIFX9RKgaXcq5M6E6S9CA7/OZfUEe3a5v6zkUd/yBwN4QbYfDov Di/Q== 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=Tc8/5Htu03EekfHZgP4r0NXhDb+ikoMCHMfD/wL15CSIZGCNNGRmDJ7+aKrKWLdGKo dV/ZhGa3k3dCn1NBE7mqGY7RdYdA1LqEFTH6WcX+XHQWQPe5k1iNUWB6Q6kWFKB0HW/9 hq3ZIRVO2lHSudnDFDPab4lAZgNF0dqGcXHfVytFbzaNSmcSq9PTReaooVm4xaaLCImp WSHzn92Z6XxsYNNpkWqn66PO89QoAlJFMFijt3T+yKMRjtTd7K+XlwxAW4+7Usljl7sy eD3M4GkMH95gAZ/JSstbF4Uys88BcMY7989pQr1JXD6822A2hreUtZqhVTPgInkfo9EA +ZNg== X-Gm-Message-State: AOJu0YzXs3BI0DPxHLFXRZTsac2UCXP1bsyu9cZaCdqJ1kOfaj1ugpAT B3uKBC6NG75hMHRMQs4e2fNwa+0w55RoXjEE4Q== X-Google-Smtp-Source: AGHT+IEasZ8zke0C8rGvXIloFTS/ZxsYcfACcxs//8QPDynbwpqTjoH00TTO/N1uZn7b+i3uXt1z2YeGMvw= 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 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 X-Rspam-User: X-Stat-Signature: b39xruqb7s3oyeeby4uomtxbuonsd4qk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CC7FC40006 X-HE-Tag: 1705343921-562321 X-HE-Meta: U2FsdGVkX19dce+t7mdFyGRjmEchdEIAo/9DRJW0Ifa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ReY6lWtExbzLVjEelBGMGi4NW49JgdpETcV6ZeACTN1/TIwr3ihQx4VZJmm1Q4stk6oj9VsBemyAiAZU3noRknLYzPab+1NQJbLageY7Dzti40qFZMi5fOcSmlDoX/72XPl3biE7mCEQe634oXZCnWUJ8beglfczxkzHPAxKmHx2qixwPis07MulEyzlVwDHBdCgKAgzPcBUfvyoIADHRP+riqGnlGJXaa8p8eVfDVUQrg7KraAl+LK/8roVFlaeOKKTvGvz2ReFAMScBH59A0eQmBrTaMV7Sg8GxGya+LLdg8t+K4R87153Y7dtFNnC1xpk9ov/3knb9nUYQRYuIuzkGIpVZFqx1gT3+GVK4IhJCcwPpjmcGfTaZ5lTUYuKr7M11J0sXlnDRhnoKeCr0zXwNeZLiS2sfnYEDuArBECSnKFj2YKAJfZi1xjyJJ1URsRACjoL4W2sKAnaPTq2uMdWu3rZZhtVFfmzJ2xwGeNtB6ft30KUatX4J2aZr/K8nMduSHzrOfoQ3FjeBWf2yIroZzcVsrvkCzRQ1GNp8EdDsWUr8OprdRI21Om86LsJTKpPQ8MbRGJZ0+yUFxjaP6adlv8qTo2ioD3SSgJdkX6txg6F0ZZF54aU4EoNHBhgt6penrHxpB9eDj5uT8UjrAsmzDQ35pQxfXPb2S4A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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(-)