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; }