From patchwork Tue Jan 19 07:51:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12029425 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 1D739C433DB for ; Tue, 19 Jan 2021 07:51:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8443922D71 for ; Tue, 19 Jan 2021 07:51:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8443922D71 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 B5E9A8D0017; Tue, 19 Jan 2021 02:51:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0E7C6B00CE; Tue, 19 Jan 2021 02:51:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A247B8D0017; Tue, 19 Jan 2021 02:51:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 898496B00B0 for ; Tue, 19 Jan 2021 02:51:39 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 42EA51EE6 for ; Tue, 19 Jan 2021 07:51:39 +0000 (UTC) X-FDA: 77721755118.19.train28_1e12d6d27550 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 220E71ACC2C for ; Tue, 19 Jan 2021 07:51:39 +0000 (UTC) X-HE-Tag: train28_1e12d6d27550 X-Filterd-Recvd-Size: 3755 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 Jan 2021 07:51:38 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id n8so12038162ljg.3 for ; Mon, 18 Jan 2021 23:51:38 -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=uuGQRAJRZZ+5+wnwR/xXDjgCBVhuAJlZaw/GcYybCFE=; b=Jqt8ZWYUYoKKxhy7QdzJO78nPwlCkdM9OGHclNMkAVnG4Xydmy9mqnHlXmQn2TKUbH SIGxRlT/N0QdDJKn233ZZsEtO1Ipguw//upni9KZVytexOFNXJ/Sl7i6zFK3f1gFP9yp ifAfcoRrzrAXvVC1JZJVt5aZusH/I1iW0KDPW6xVmSYHAsezJubJGFs0jvdB6si0UH5v RkpzbM8ix0ND2MKwfoA3mIVxj6Gz29+jpyLohgpcO1M1JvLBBbIjBPw8iV+gU4DsDlcb WnxdlHEO+oHVx5suF+sqUojQ0VsjOvlQ2Vl5FDY2fKMGoMY8XEzjRDTtm4ehs2NLjlmx k4lA== 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=uuGQRAJRZZ+5+wnwR/xXDjgCBVhuAJlZaw/GcYybCFE=; b=WlUaf2/Su+WZY42/wozenpYhFbZOh5IHocc7XSTo4/q470pDFoM3yuepd7IOrDz3kg M0CXyDR5zEhAsizDbeNoPrc1wwnZtr6Y3ntdG9nwDbTvW5fdMuSu0icO8D5ZiaXRETuo JlNLPCtAoV72ZGXzyU+8GJ8pHELj2Ug9KVoQ8XUM9tLp1liqd+oWRXPMNz23XEosnD9M GLy1oYoutTVk7q0q0kxfsr89diPYy+SrlRTxgv+XU8dHOX09Mumre/Z+l8R0rEyVUDQz PY4bIMduI054OXv1qfuwmK9K9FsNJ3Nkxo2eApjPnWki5xCfBD7RNZfseeJqB9pRMNy9 ueXA== X-Gm-Message-State: AOAM533+C6aoTaAgRZYEWaZwhzC6P7eUVg8Qvltvh+BOhMUkSki5QYrV mAtf78/jgZkgPW1O82hH+Bw4x4h93NU= X-Google-Smtp-Source: ABdhPJwLFyvR/5h7ZFRpSsp+rKtwdFcrplkQnIKJCf7RitjDUgDs22gKTCh8ieGCu5Z+bZ28pBHZBQ== X-Received: by 2002:a2e:984c:: with SMTP id e12mr1348131ljj.71.1611042696996; Mon, 18 Jan 2021 23:51:36 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id s1sm1955108ljs.0.2021.01.18.23.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 23:51:36 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Date: Tue, 19 Jan 2021 15:51:25 +0800 Message-Id: <20210119075126.3513154-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 --- 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 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; }