From patchwork Thu Sep 1 17:34:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12962968 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 B84A1ECAAD3 for ; Thu, 1 Sep 2022 17:35:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5382580018; Thu, 1 Sep 2022 13:35:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E8938000D; Thu, 1 Sep 2022 13:35:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3885780018; Thu, 1 Sep 2022 13:35:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2B6AC8000D for ; Thu, 1 Sep 2022 13:35:28 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F193B40FD6 for ; Thu, 1 Sep 2022 17:35:27 +0000 (UTC) X-FDA: 79864218294.18.E808012 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf14.hostedemail.com (Postfix) with ESMTP id 7846E10003F for ; Thu, 1 Sep 2022 17:35:27 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id s15-20020a5b044f000000b00680c4eb89f1so4878703ybp.7 for ; Thu, 01 Sep 2022 10:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=p6utfGSGU2ZWrUa6c0eUAGSz6ILgySPKVkHsaiIDl8M=; b=LbkT/AkX1WcT/2fyJlqSXegH2trsBNyd6QrbYfZ/YY10o0bOfV+Ix+uJLegE6lSF35 ne85BxCuyx7lBpnSiZ42TY86RYtZR3AAc5vYrFsx4gBxgTwamIONmdTxtR/0iKqdUJEh gCGpqjCaOQV7LzbqDjbUJKDXfAR5/j45YmmGmhxu+HXk+Hwd00xyXauy+PEzZWtLyw4U rqIn+41hVfJNUiIovZy6pL0FSV03X1G3rIrczW6PRcfgw8lXvG9gGaQmr8gUZrra+vXa CCuSzq9IAYSPtY4Wqdt70146omIRNbSeU/rl39Xw+3e0A38BgKuGXtDi12EMKnqTbGy3 VnZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=p6utfGSGU2ZWrUa6c0eUAGSz6ILgySPKVkHsaiIDl8M=; b=ny1HITUU/AP6bYOiwE2jRGBF+yWD+2ER3D2qEIYrnNYc52Lm2P6Rs4xW/1Exznz6hp uaeSwjMWag6pw4PZseS9Ggyb2ONNmbsVTTAv52Oxmb0b39cI9FCHOFRniBMU2xRFROlx N2R1G7Rbwuaq3B4jm13rnBu4zGbtqxcYpF8JHAvb/Hee/NAh/gvboxe4MH96+jwOZHIa d89Uo7ZVuE7Y21l0swa0bEptMu66yiA8c09C1LmT0WRObXmSwD5Un5oh4Q90tSbOrUQa Xm55G4j/K+dQzTj5OQxujrxN3XLXS4e7izsVpwvkcC0jxFw3NOc7+Lpq9iQ9uBGO4HNU Wq0g== X-Gm-Message-State: ACgBeo3uH94nXdFzaQR33eX9IB3SEiFT+4zonNVWOlWakPA86WAz0ikU wRZkQtBKXPG/7U8iTxNgqzSyOEhEBmXToYA5YX+BMdSNITlMLN9+uAyYQRmf6exkohbuuuf6ls4 cPsCXG1U= X-Google-Smtp-Source: AA6agR4JzlVLX4tUxHHNIbaNOZW1dz2wXadaTbKwNizSq+Zw9LDNKeWUkMtSnrbieYwXe2AgTTBR2su3VSU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:1bfc:e7ee:6530:4449]) (user=surenb job=sendgmr) by 2002:a81:5cc4:0:b0:327:59f2:d673 with SMTP id q187-20020a815cc4000000b0032759f2d673mr22886370ywb.272.1662053726626; Thu, 01 Sep 2022 10:35:26 -0700 (PDT) Date: Thu, 1 Sep 2022 10:34:50 -0700 In-Reply-To: <20220901173516.702122-1-surenb@google.com> Mime-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220901173516.702122-3-surenb@google.com> Subject: [RFC PATCH RESEND 02/28] mm: rcu safe VMA freeing From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, surenb@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org X-ccpol: medium ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662053727; a=rsa-sha256; cv=none; b=yBCYY0MRSiVaaygYIc0kP2GyjGuC0qWGhZXphHhmSnCRRUmQbQayLHXasYl9PP9sQqgWWO ZWaQh4GW3n2kfX6RkkGxo5Hzwj9mqFKJp7DIOM9P8Zbieg99rCnqwn+m/jVTuhA9Ek0QEX 4Jjn56ScXdKdRqSPTWUmeoxL+r9zfZg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="LbkT/AkX"; spf=pass (imf14.hostedemail.com: domain of 3Xu0QYwYKCJsNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3Xu0QYwYKCJsNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662053727; 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=p6utfGSGU2ZWrUa6c0eUAGSz6ILgySPKVkHsaiIDl8M=; b=E4R8FQGEU4SMykgrGjsnFNDkuA4XQGn/tbMpT6sTcL62O7fGjODrqgdlSF9x4L3Dv9HJ82 Nk63IexFhYcvDg6Cms+q4tgiJ/7v1oPuDE2WQpzGsTWvKSa9Nlt3RAZKni0FPhR11y48Ln 8U/sccmkFo+atGup3zVtLzUGMfsCzD4= X-Stat-Signature: dxxnef53kcfecpjf7p666qhj5oz6bf9e X-Rspam-User: X-Rspamd-Queue-Id: 7846E10003F X-Rspamd-Server: rspam07 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="LbkT/AkX"; spf=pass (imf14.hostedemail.com: domain of 3Xu0QYwYKCJsNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3Xu0QYwYKCJsNPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1662053727-135976 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: From: Michel Lespinasse This prepares for page faults handling under VMA lock, looking up VMAs under protection of an rcu read lock, instead of the usual mmap read lock. Signed-off-by: Michel Lespinasse Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 16 +++++++++++----- kernel/fork.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index cf97f3884fda..bed25ef7c994 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -403,12 +403,18 @@ struct anon_vma_name { struct vm_area_struct { /* The first cache line has the info for VMA tree walking. */ - unsigned long vm_start; /* Our start address within vm_mm. */ - unsigned long vm_end; /* The first byte after our end address - within vm_mm. */ + union { + struct { + /* VMA covers [vm_start; vm_end) addresses within mm */ + unsigned long vm_start, vm_end; - /* linked list of VM areas per task, sorted by address */ - struct vm_area_struct *vm_next, *vm_prev; + /* linked list of VMAs per task, sorted by address */ + struct vm_area_struct *vm_next, *vm_prev; + }; +#ifdef CONFIG_PER_VMA_LOCK + struct rcu_head vm_rcu; /* Used for deferred freeing. */ +#endif + }; struct rb_node vm_rb; diff --git a/kernel/fork.c b/kernel/fork.c index 90c85b17bf69..614872438393 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -481,10 +481,23 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) return new; } +#ifdef CONFIG_PER_VMA_LOCK +static void __vm_area_free(struct rcu_head *head) +{ + struct vm_area_struct *vma = container_of(head, struct vm_area_struct, + vm_rcu); + kmem_cache_free(vm_area_cachep, vma); +} +#endif + void vm_area_free(struct vm_area_struct *vma) { free_anon_vma_name(vma); +#ifdef CONFIG_PER_VMA_LOCK + call_rcu(&vma->vm_rcu, __vm_area_free); +#else kmem_cache_free(vm_area_cachep, vma); +#endif } static void account_kernel_stack(struct task_struct *tsk, int account)