From patchwork Wed Jan 27 08:39:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12049343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E2C8C433DB for ; Wed, 27 Jan 2021 08:39:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 23F7A20719 for ; Wed, 27 Jan 2021 08:39:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23F7A20719 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F03C76B000A; Wed, 27 Jan 2021 03:39:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB46C6B000C; Wed, 27 Jan 2021 03:39:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9226B000D; Wed, 27 Jan 2021 03:39:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id C6EAE6B000A for ; Wed, 27 Jan 2021 03:39:24 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9210B180AD83B for ; Wed, 27 Jan 2021 08:39:24 +0000 (UTC) X-FDA: 77750905848.05.care25_2f0b72827595 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 6B50B18045E8F for ; Wed, 27 Jan 2021 08:39:24 +0000 (UTC) X-HE-Tag: care25_2f0b72827595 X-Filterd-Recvd-Size: 3783 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 08:39:23 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id y11so1135414ljk.1 for ; Wed, 27 Jan 2021 00:39:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=P9lsVAKuBeBy2NX/pLEuuHxAXZwhA0q0v6LjUigA9EE=; b=tPPtxq2C0rnzakrAue8RUnc/cYNQycZEWSjqIe12+D0acBd7JVrnwtz0l08bXST059 qU9ghvOoXBEINqButtZ46DcKKehka4fH9mxqI+xEenb1RnJ8/XMpSAJxQnophnLy8fNC Xb+brmbcQ/U5XAVsMFVXAvSCW6Tm5whDZYRokTplLY6vsV5LDdcTVDdl14kTmUL8JjOo RLzvjm3NZbxgacRbfdpLXUo5xqaVQmvQIbUpVoiyong7IOeR7O0jYsoc7ZFGzUz6xQhn cRiwJ2IKn1dwrOQFRjn8Fx5InCPV7GcnQTafw02cuaJ3kJ8AUjgJLx3tL0qLeuZNBtmC glug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P9lsVAKuBeBy2NX/pLEuuHxAXZwhA0q0v6LjUigA9EE=; b=ebyGADrup7fsOpU0wWAtWiZnGXzaS9lktn2E3RHPAv3TiIu7PsKuWG1d6QTZVz5fCa zPFW37ZaMr5Rwnm1IGMwSi7OugnD8lMvEpanenPsLbZ+QqDy4Yhq+F1ZgHdpJ6BEwIYY WicRfWN+RuSKLxhgPsvQJZHJBQxVrs3B/rbJqm8kb8PuAsPoAVlHGzpUj7lI6Zs7XmMO NgwfKK4lxlR5hg1hPOFoioV3kRVd7zz20O78cC9C2muJ9YkCJJcuw5bdMCoZcX4g8Pjj np5Xre90mbYiQKeiutxzR58kVU4zt5eimrpMrBr4NKSOsLFVCjpsuTz9obfNpTG0ROYj SOZg== X-Gm-Message-State: AOAM531ekDy84SzmMdJsRdbhgwkL0gvSx5iQJ42b/HcmF09OLCqrnbLo wCmlxHSu1Jd+Gaa//UZQCKr2wNXSils= X-Google-Smtp-Source: ABdhPJw8lRLLD12bDPjd3bzlcAQTPU9VKVUeUDR721tBg3D6W8juBw8DpSjE/v1XelSKuHNSKc7SWg== X-Received: by 2002:a2e:b819:: with SMTP id u25mr4960144ljo.458.1611736762221; Wed, 27 Jan 2021 00:39:22 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id e10sm394458ljn.79.2021.01.27.00.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 00:39:21 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH v2 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Date: Wed, 27 Jan 2021 16:39:16 +0800 Message-Id: <20210127083917.309264-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 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: In case the vma will continue to be used after unlink its relevant anon_vma, we need to reset the vma->anon_vma pointer to NULL. So, later when fault happen within this vma again, a new anon_vma will be prepared. By this way, the vma will only be checked for reverse mapping of pages which been fault in after the unlink_anon_vmas call. Currently, the mremap with MREMAP_DONTUNMAP scenario will continue use the vma after moved its page table entries to a new vma. For other scenarios, the vma itself will be freed after call unlink_anon_vmas. Signed-off-by: Li Xinhai --- v1->v2: No chnages. mm/rmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 08c56aaf72eb..31ef76180c53 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -413,8 +413,15 @@ void unlink_anon_vmas(struct vm_area_struct *vma) list_del(&avc->same_vma); anon_vma_chain_free(avc); } - if (vma->anon_vma) + if (vma->anon_vma) { vma->anon_vma->degree--; + + /* + * vma would still be needed after unlink, and anon_vma will be prepared + * when handle fault. + */ + vma->anon_vma = NULL; + } unlock_anon_vma_root(root); /* From patchwork Wed Jan 27 08:39:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12049345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D9FBC433E0 for ; Wed, 27 Jan 2021 08:39:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB84E2067B for ; Wed, 27 Jan 2021 08:39:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB84E2067B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 84C026B000C; Wed, 27 Jan 2021 03:39:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8002E6B000D; Wed, 27 Jan 2021 03:39:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F0056B000E; Wed, 27 Jan 2021 03:39:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 564D26B000C for ; Wed, 27 Jan 2021 03:39:27 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1E19A363E for ; Wed, 27 Jan 2021 08:39:27 +0000 (UTC) X-FDA: 77750905974.05.debt40_410c02b27595 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 0097318046547 for ; Wed, 27 Jan 2021 08:39:26 +0000 (UTC) X-HE-Tag: debt40_410c02b27595 X-Filterd-Recvd-Size: 4549 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 08:39:26 +0000 (UTC) Received: by mail-lf1-f50.google.com with SMTP id q12so1483413lfo.12 for ; Wed, 27 Jan 2021 00:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sMPs2kasgWaN2fa94H0Fjocpw0mMzf/O27rXBVFzYcY=; b=DGvKNRKf79FAAEZFjRvUotCWF95kOyIFIvHLufus1uPtAtyGgk2P2qGfx+iHQZHI+D FLszStpjo4OojZA7sksM2tMJHQTZiJ5KSFXWt+LklsN6QaDZe76cx5rsxD9iJfB4qfLu u/4Ab1ICNZDjLWjHj4T/XBX2nJyXXiP7sd8Ta8Y8ZTTiwAgxvXu9HNzah5CA+EMqX1tE bFsKAtuo4MgnjxJA6z31SFROWXKZUWXMKKsGG9iB4KjOpJFYkxC3YfQ3VeYtacS9M1Gp xR9u+HB6dcvJ6/4Gapsjkf8Tgf2gDKw78YbtUHBftSBxH0k96KpA/QGOLc17jAIdxHdV rmtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sMPs2kasgWaN2fa94H0Fjocpw0mMzf/O27rXBVFzYcY=; b=oE13EGr5Uw9A70pP38XyWvJqCFC1BEgiRFKJ5+u+ir9NldiBIoo0W4VLLYAtOtCUbA uyN2y1rdH831oxk3IpdyH+Yz9Gdcqz0/c3LncDxHSQSvH+zU0UuR2UR7jK3ql1RrSHNc fZquqb7doGkGTcNUmB3716oQPAxP3lHi8h9rqXnSYh9uPngV1n14NaOqgfc84UuANzVj Nqlb2I0+ky1ZqA+722O1k8DfgNk9RJgr3/eyOMd2MuE6NobNRcCMM5zXeJLEYBvDoR6H a2mGl10eawojv8C9D0gTLl0sSy+D07H8dACFijUyHhhDhTcfq6jv6Wd6eVAAjfEfk7aA GjCg== X-Gm-Message-State: AOAM530cc4NJAPEp75S2ZL/WeW51IxD+n84rkjABrnr0COtKcchsCfLY 4pfkB6TwQZyZqfd7buwKCGmFvu1qPV8= X-Google-Smtp-Source: ABdhPJwOQtywLPHJgR8sSFAXZg0TRuw7swvizHkVuqE2i782laTcJMQyqLcHeRMQA/Obng11HzrXHw== X-Received: by 2002:a19:23c5:: with SMTP id j188mr4871584lfj.430.1611736764922; Wed, 27 Jan 2021 00:39:24 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id e10sm394458ljn.79.2021.01.27.00.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 00:39:24 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Brian Geffon , Lokesh Gidra , Minchan Kim , "Kirill A . Shutemov" , Vlastimil Babka , Andrea Arcangeli Subject: [PATCH v2 2/2] mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success Date: Wed, 27 Jan 2021 16:39:17 +0800 Message-Id: <20210127083917.309264-2-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20210127083917.309264-1-lixinhai.lxh@gmail.com> References: <20210127083917.309264-1-lixinhai.lxh@gmail.com> 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: mremap with MREMAP_DONTUNMAP can move all page table entries to new vma, which means all pages allocated for the old vma are not relevant to it anymore, and the relevant anon_vma links needs to be unlinked, in nature the old vma is much like been freshly created and have no pages been fault in. But we should not do unlink, if the new vma has effectively merged with the old one. Cc: Brian Geffon Cc: Lokesh Gidra Cc: Minchan Kim Cc: Kirill A. Shutemov Cc: Vlastimil Babka Cc: Andrea Arcangeli Signed-off-by: Li Xinhai --- v1->v2: Need to consider the old vma just been partially moved, if so we must keep the anon_vma links for remaining mapped pages in old vma. mm/mremap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/mremap.c b/mm/mremap.c index f554320281cc..ec6c63e3ea66 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -595,6 +595,14 @@ static unsigned long move_vma(struct vm_area_struct *vma, /* We always clear VM_LOCKED[ONFAULT] on the old vma */ vma->vm_flags &= VM_LOCKED_CLEAR_MASK; + /* + * anon_vma links of the old vma is no longer needed after its page + * table has been moved. + */ + if (new_vma != vma && vma->vm_start == old_addr && + vma->vm_end == (old_addr + old_len)) + unlink_anon_vmas(vma); + /* Because we won't unmap we don't need to touch locked_vm */ return new_addr; }