From patchwork Tue Jun 27 04:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293986 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 70DC3EB64DC for ; Tue, 27 Jun 2023 04:23:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07D9D8D000B; Tue, 27 Jun 2023 00:23:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F21C18D0001; Tue, 27 Jun 2023 00:23:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D99D58D000B; Tue, 27 Jun 2023 00:23:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C74508D0001 for ; Tue, 27 Jun 2023 00:23:42 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 96BA01A0841 for ; Tue, 27 Jun 2023 04:23:42 +0000 (UTC) X-FDA: 80947234284.08.424D0C8 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf04.hostedemail.com (Postfix) with ESMTP id D64344000D for ; Tue, 27 Jun 2023 04:23:40 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=uyhBbu35; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687839820; 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=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=ID11nKKiljNhQM0s1xcloQ0BaaXSpr/+GEuSeCUXqFuev1dA5JuxNFQ0aAA95c69in/CBu sb1tnykmsIIfZGe3ZY4Ze5/PW4XFyXFaj60VXcnrmywWn9BELTs5ggYYdvLYHujMpCh2Ef cwlFP+xE06tn3zndqcQ878ZqALb6TD4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=uyhBbu35; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TGSaZAYKCKkbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839820; a=rsa-sha256; cv=none; b=JrmL4drl8NdGd+s/ZtImQJKoC1ct/peC56ZucOxBoiKX07Hlg40uo5oNXZUZPdJ+lyuoUT g7Os/NXR0CDqSQMm2U17qklijP0bCabkFWzdczqrSEWplzfng5x84aBAQ2z0VEaCEBhImX ovYss2gV9VxQ8VxlyHW9UHHgTXHLSrk= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bb2fae9b286so5206590276.3 for ; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839820; x=1690431820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=uyhBbu35AtD8uFc7lNVRhrhL9FZssNEc1U3YlNjnS6/vWb6a5ERBcwBMaYSPxjJ/Mk Qe5HTpNa5XqvLjiojjNbFmZN0xmWKkvRVR4N08jGcpfsLakGmZkxol+hWOUA2MEdPtG3 CCWMkRdx3oFd6/Dcq2ziTDhiHH5hTD+8UeRRw0fdTOeqAixqf3jfdQ7B3ZgYpw+aT0x0 7n1tbaJiroElOh+0zEGZhbUInAo3kZrsUt6r5yZG0ZhF8kLRGvyK6fttt1xmJKJlC+bc 8aGAiRC7PO3v1V82sW0UO8XGuG6YrM7whEZUcc8FMaVdHAxabZ1AEzNvmsHlLQ8otu9G mugQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839820; x=1690431820; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S48dBfG0SWV0QU4tyl9ann+yNi8sxz8gZYLMNRkbGeY=; b=gCFbbi05HUl9fr9Ep9jofLodsJzhB0Yk27+eEvT46a+nRp1+Mn1UcbomCBJS3EgwZF HlCKOlY4f0yYMb6ghhcvVF8FBUctRO/aN8kNqOYmziiq9AfvaAVeYmTDrh7wn184USCR arF//pqFyUqba8ohclH+AaKMTlRIB0FR4o81OY3X8W3Pek7OxqH17EpwZGHGnOrvE+A9 1JkEsp4X3iUvdDiKYYWmLg075tw1XzljN7VFOuScgBuiQO8rvirW5wQOr1MYOAY0UAVd kqz1VOVg/Dnyouw5tJLko/f9th2FadxfQG7YUeOn0ry49Lj1ounpbb3+6HNcShmdj1Kt 4h3A== X-Gm-Message-State: AC+VfDyx7bjq4KIpK7oZubSKDNLjtgSkggZ+8V4MMB6yo6ttK1wb0gQG Wkdm1BbPQgKWWezpD76Biu5H3WVkkI8= X-Google-Smtp-Source: ACHHUZ7TRsCUwE2ZwvAugNjG47XxvELjQ1x8vS3tmisicM0hRabZmbuVIm5qRhxSsRS9QjFAyyEcLENdUAY= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:e78a:0:b0:bc4:ef98:681c with SMTP id e132-20020a25e78a000000b00bc4ef98681cmr6584157ybh.13.1687839820015; Mon, 26 Jun 2023 21:23:40 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:20 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-8-surenb@google.com> Subject: [PATCH v3 7/8] mm: drop VMA lock before waiting for migration From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspamd-Queue-Id: D64344000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ct3nw4m4n79sro8n984fht6gc4ch33di X-HE-Tag: 1687839820-32337 X-HE-Meta: U2FsdGVkX1/+0jar+Swu/BS+UNxjw194n/EoQiiIWsutLAiqdV4/EDj1ozcF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+CFyMbP3yYJYQc+wletXFgXheCZ1amVHYF47/lMQkrRnvbM2VvyM3SdCk2G1973zM3HbYdozdBsphCOPWa/j2WtzGxe08e6nLhXeHDZNsIsJkNSCmuXpqRZKRB1VH2FRt8BmJTycfqj7or6QM9lbroJoTW7TG50vjA8LQ4zUZYzItBQURWOWTvmEuXfzTDl/girG+tVcr3PqHkJjU6LReCiT+9vGQ7NOKLinQo0W0ZXAcRvCWXujmczSk9bPyBWtUNZ/1/27Uv1G36HJLs3568ZVTcshxs2/pfod0HwqY/D8tBlRq6wRbsDXH8Wz3iANh5z5mZ1PVeRTnp98YlfbqxtDYQuMQ0IiVQ3a95rxFMfiYvJyjsvv6NRy5nImjFTDS2fZoEvAFquqbkJmvszcSe0HOG3mqgf9pstoQeFCqMDYoWd9HaVB/2zk/US/GNFxkJwXQlPJAXxs/8Po4= 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: migration_entry_wait does not need VMA lock, therefore it can be dropped before waiting. Signed-off-by: Suren Baghdasaryan --- mm/memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 5caaa4c66ea2..bdf46fdc58d6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3715,8 +3715,18 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) entry = pte_to_swp_entry(vmf->orig_pte); if (unlikely(non_swap_entry(entry))) { if (is_migration_entry(entry)) { - migration_entry_wait(vma->vm_mm, vmf->pmd, - vmf->address); + /* Save mm in case VMA lock is dropped */ + struct mm_struct *mm = vma->vm_mm; + + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + /* + * No need to hold VMA lock for migration. + * WARNING: vma can't be used after this! + */ + vma_end_read(vma); + ret |= VM_FAULT_COMPLETED; + } + migration_entry_wait(mm, vmf->pmd, vmf->address); } else if (is_device_exclusive_entry(entry)) { vmf->page = pfn_swap_entry_to_page(entry); ret = remove_device_exclusive_entry(vmf);