From patchwork Tue Jan 19 07:51:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12029427 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.8 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 0651CC433E0 for ; Tue, 19 Jan 2021 07:51:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 885EA23133 for ; Tue, 19 Jan 2021 07:51:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 885EA23133 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 14D7D6B00B0; Tue, 19 Jan 2021 02:51:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1035A8D002C; Tue, 19 Jan 2021 02:51:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E92CF6B00D5; Tue, 19 Jan 2021 02:51:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id D46046B00B0 for ; Tue, 19 Jan 2021 02:51:41 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 97F988249980 for ; Tue, 19 Jan 2021 07:51:41 +0000 (UTC) X-FDA: 77721755202.22.cap55_350289427550 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 7600A18038E60 for ; Tue, 19 Jan 2021 07:51:41 +0000 (UTC) X-HE-Tag: cap55_350289427550 X-Filterd-Recvd-Size: 4331 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Jan 2021 07:51:40 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id s26so27705648lfc.8 for ; Mon, 18 Jan 2021 23:51:40 -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=ppRGVid4KX8+LR5x+qk0yJr3Ttzfl4jL4uXDvn0B7Hk=; b=MsBqoC/WiiU1lKHSQFp28njMaGh1345ZgQs0KoNbwZRVEVzk9XiiFytSX5xBxmjaYJ oJXGWXyZ2MlneULdlSun9fOIMZLrPv1WfTcvp+UTJPp29UMhvrPWL2t7nJBa0DLJYYza NKK/5PqPcTaOwbHp8lR2v7tgebh+P4f1sgii4bkUCEbVHY+yNJxciOIG9oVSqUu4Ydtg Hi80f50dt8I+nlgGMJBdQukJYSyNMIn9MMt1k9YeQ2FfWTQEReq5yvbNoIsXbK4UlqXW 4Lx+4VapLe8+ikLDeEOcrLa/SF6G2D5pO4m6HBOY6DoiimYeknKsoZgHxxbEQ35enEqG 5tvg== 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=ppRGVid4KX8+LR5x+qk0yJr3Ttzfl4jL4uXDvn0B7Hk=; b=QQc8JNVFdQ+cHv3fRB/aiMYE7hVKi3Kp6/jhMy4wt4moLH6AgmN6TFWNgLkuWcIJsj UgY4LFerm+PQRMuK0AY1hBjJiE5ou9EX26TCXCNbeEZg+nYKoZppnuie7djZx4i9GuEi VNb3kiYhL0kdRtijNnLKITNJ3vuXmeIHRK+vH1ZfGJ1d8uRxpetWQqy971VcAxZjCXsi mdHivWXa6kZfAgj7m8vJdMS3pzqRVvpUPw8eNv9ajP0wdZKGTj5pRBdfLXa2Lo6Dh37J DWs+akUS9YGJ7DAjqffEVSQpFGjGZlMQzSdVrWKxS9mEVFmzRa0u3a6vwDjiy3JFCd5w wUyQ== X-Gm-Message-State: AOAM532ETsCUz/4vHGudKC/CwzksFe7rcRhNdQ6DrAgPcIHdV6NEa+Z5 76tWT8+OwzvRycW80yyjxD2L7SsTVgc= X-Google-Smtp-Source: ABdhPJzw4caPYL/bezXEo2jIO8bbLd9djyp9cvdWn8YmfqWHLx9uyG+/v+dA8cCdEPrzacE2Fzqudw== X-Received: by 2002:a05:6512:131f:: with SMTP id x31mr71415lfu.552.1611042699663; Mon, 18 Jan 2021 23:51:39 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id s1sm1955108ljs.0.2021.01.18.23.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 23:51:39 -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 2/2] mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success Date: Tue, 19 Jan 2021 15:51:26 +0800 Message-Id: <20210119075126.3513154-2-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20210119075126.3513154-1-lixinhai.lxh@gmail.com> References: <20210119075126.3513154-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 will 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 --- mm/mremap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/mremap.c b/mm/mremap.c index f554320281cc..7745b672e1a6 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -595,6 +595,13 @@ 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) + unlink_anon_vmas(vma); + /* Because we won't unmap we don't need to touch locked_vm */ return new_addr; }