Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4674892ybl; Mon, 13 Jan 2020 18:23:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzL0ZtdOV5Bbf3iuSdp46WPA/PubCErMSX4oswQ3yQX4zsYdJEmEIfrPvotYtHid9O2Qbvv X-Received: by 2002:a9d:74c7:: with SMTP id a7mr15891215otl.7.1578968629462; Mon, 13 Jan 2020 18:23:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578968629; cv=none; d=google.com; s=arc-20160816; b=DaH3cTkahaZtBijNa6KhkRY9wBPMLED5RHR6Z6LT8kqmvE+cHd7ID2O7HwPNd1Qeix HhczwP5Qw9y9Yr66qOD8cPLh/Vyr2++wFmMAPnVeuoHzdsGDsLa5mabgMVztEfe+hPx6 aV5aOvOSHBMfZfYYGVh/KRRqBY5hjf2z6Km1KMZhCWnPthpHde22/KyqWSpWKUfRvyqC vFdg90F4ElybDIybf7Oj/f5dvVjojnR7Jq13NFq2/3IJUsKyaKzpv2U72jpFxIGN+yE0 GFOZVPRcBMXeRjcJsst+D+7TnIzE1oWTdWdRnAPQPfdnsFt2G/QoPPIoK23CeTXMilR0 Rojg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date; bh=aPWsq62qlX8f3x9FatgRRi4SBQFp4NR9NZFTel2Ndn8=; b=RGNqQ/hADsodXc21Tj3xKqgqzyrL7imVSQI4yqPhHvnn9/kReTjhS/ayZbaQCrxiUd TWrI5rFMxOhiv/BWWIwR+sjMTwj5pZi/pYcLquHuXr4MNrDq5CoQfMVjlGxq4tHMJ3X5 mz/g0qTfvXZCEHSZKvJ0rsO7qu9Qtv8cSGamrxmibHE4xEt01Ywp+is0AzO3z8zn+S+B MJwNenAEjZHnxjJQE6zXtoPXzB5dgFDXieCVEKDxPIM1CQj1wjPa+SXgQexxhO+d/UyU 5dnrtE8D3UhG/NxwhmVGwt1Sz8dYAnQ9/98j40xz574iOzjZyoAmAoTWZpTfp7oefLV2 fWug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a205si6860598oii.95.2020.01.13.18.23.36; Mon, 13 Jan 2020 18:23:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729522AbgANCJY (ORCPT + 99 others); Mon, 13 Jan 2020 21:09:24 -0500 Received: from mga09.intel.com ([134.134.136.24]:26863 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728641AbgANCJY (ORCPT ); Mon, 13 Jan 2020 21:09:24 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jan 2020 18:09:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,431,1571727600"; d="scan'208";a="422998128" Received: from unknown (HELO localhost) ([10.239.159.54]) by fmsmga005.fm.intel.com with ESMTP; 13 Jan 2020 18:09:21 -0800 Date: Tue, 14 Jan 2020 10:09:29 +0800 From: Wei Yang To: Konstantin Khlebnikov Cc: Wei Yang , Li Xinhai , "linux-mm@kvack.org" , akpm , "linux-kernel@vger.kernel.org" , Rik van Riel , "kirill.shutemov" Subject: Re: [PATCH v2 1/2] mm/rmap: fix and simplify reusing mergeable anon_vma as parent when fork Message-ID: <20200114020929.GA6889@richard> Reply-To: Wei Yang References: <20200109025240.GA2000@richard> <20200110023029.GB16823@richard> <20200110112357351531132@gmail.com> <20200110053442.GA27846@richard> <20200111223820.GA15506@richard> <20200113003343.GA27210@richard> <1cf002fa-a3cb-bcef-57dc-ac9c09dcf2eb@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1cf002fa-a3cb-bcef-57dc-ac9c09dcf2eb@yandex-team.ru> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 13, 2020 at 02:07:18PM +0300, Konstantin Khlebnikov wrote: >On 13/01/2020 03.33, Wei Yang wrote: >> On Sun, Jan 12, 2020 at 12:55:45PM +0300, Konstantin Khlebnikov wrote: >> > >> > >> > On 12/01/2020 01.38, Wei Yang wrote: >> > > On Fri, Jan 10, 2020 at 11:11:23AM +0300, Konstantin Khlebnikov wrote: >> > > [...] >> > > > > > > > >> > > > > > > > series of vma in parent with shared AV: >> > > > > > > > >> > > > > > > > SRC1 - AV0 >> > > > > > > > SRC2 - AV0 >> > > > > > > > SRC3 - AV0 >> > > > > > > > ... >> > > > > > > > SRCn - AV0 >> > > > > > > > >> > > > > > > > in child after fork >> > > > > > > > >> > > > > > > > DST1 - AV_OLD_1 (some old vma, picked by anon_vma_clone) plus DST1 is attached to same AVs as SRC1 >> > > > > > > > DST2 - AV_OLD_2 (other old vma) plus DST1 is attached to same AVs as SRC2 >> > > > > > > > DST2 - AV1 prev AV parent does not match AV0, no old vma found for reusing -> allocate new one (child of AV0) >> > > > > > > > DST3 - AV1 - DST2->AV->parent == SRC3->AV (AV0) -> share AV with prev >> > > > > > > > DST4 - AV1 - same thing >> > > > > > > > ... >> > > > > > > > DSTn - AV1 >> > > > > > > > >> > > >> > > To focus on the point, I rearranged the order a little. Suppose your following >> > > comments is explaining the above behavior. >> > > >> > > I've illustrated how two heuristics (reusing-old and sharing-prev) _could_ work together. >> > > But they both are optional. >> > > At cloning first vma SRC1 -> DST1 there is no prev to share anon vma, >> > > thus works common code which _could_ reuse old vma because it have to. >> > > If there is no old anon-vma which have to be reused then DST1 will allocate >> > > new anon-vma (AV1) and it will be used by DST2 and so on like on your picture. >> > > >> > > I agree with your 3rd paragraph, but confused with 2nd. >> > > >> > > At cloning first vma SRC1 -> DST1, there is no prev so anon_vma_clone() would >> > > pick up a reusable anon_vma. Here you named it AV_OLD_1. This looks good to >> > > me. But I am not sure why you would picked up AV_OLD_2 for DST2? In parent, >> > > SRC1 and SRC2 has the same anon_vma, AV0. So in child, DST1 and DST2 could >> > > also share the same anon_vma, AV_OLD_1. >> > > >> > > Sorry for my poor understanding, would you mind giving me more hint on this >> > > change? >> > >> > For DST2 heuristic "share-with-prev" will not work because if prev (DST1) >> > uses old AV (AV_OLD_1) and AV_OLD_1->parent isn't SRC2->AV (AV0). >> > So DST2 could only pick another old AV or allocate new. >> >> I know this behavior after your change, my question is why you want to do so. > >Because I want to keep both heuristics. >This seems most sane way of interaction between them. > I am not sure this is more sane. Still suggest to separate your idea into a new patch, so audience could analysis and notice the change clearly. Otherwise audience would be confused with this behavior. >Unfortunately even this patch is slightly broken. >Condition prev->anon_vma->parent == pvma->anon_vma doesn't guarantee that >prev vma has the same set of anon-vmas like current vma. >I.e. anon_vma_clone(vma, prev) might be not enough for keeping connectivity. >Building such case isn't trivial job but I see nothing that could prevent it. > >> >> > >> > My patch uses condition dst->prev->anon_vma->parent == src->anon_vma rather >> > than obvious src->prev->anon_vma == src->anon_vma because in this way it >> > eliminates all unwanted corner cases and explicitly verifies that we going to >> > share related anon-vma. >> > >> >> This do eliminates some corner case, but as you showed child and parent don't >> share the same AV topology. To keep the same AV topology is the purpose of my >> commit. >> >> I agree you found some bug that previous commit doesn't do it is expected. But >> since you change the design a little, I suggest you split this idea to a >> separate patch so that reviewer and audience in the future could understand >> your approach clearly. Otherwise audience would be confused and hard to track >> this change. >> >> For example, you describe the behavior after your change. The second vma would >> probably have a different AV from first vma. >> >> > Heuristic "reuse-old" uses fact that VMA links and AV parent chain are tracked >> > independently: when VMA reuses old AV it still links to all related AV even >> > if VMA->AV points into some old AV in the middle of inheritance chain. >> > >> > > >> > > > > > > >> > > > > > > Yes, your code works for DST3..DSTn. They will pick up AV1 since >> > > > > > > (DST2->AV->parent == SRC3->AV). >> > > > > > > >> > > > > > > My question is why DST1 and DST2 has different AV? The purpose of my patch >> > > > > > > tries to make child has the same topology and parent. So the ideal look of >> > > > > > > child is: >> > > > > > > >> > > > > > > DST1 - AV1 >> > > > > > > DST2 - AV1 >> > > > > > > DST2 - AV1 >> > > > > > > DST3 - AV1 >> > > > > > > DST4 - AV1 >> > > > > > > >> > > > > > > Would you mind putting more words on DST1 and DST2? I didn't fully understand >> > > > > > > the logic here. >> > > > > > > >> > > > > > > Thanks >> > > > > > > >> > > > > > >> > > > > > I think that the first version is doing the work as you expected, but been >> > > > > > revised in second version, to limits the number of users of reused old >> > > > > > anon(which?is picked?in anon_vma_clone() and keep the tree structure. >> > > > > > >> > > > > >> > > > > Any reason to reduce the reuse? Maybe I lost some point. >> > > > >> > > > > >> > > > > > > -- >> > > > > > > Wei Yang >> > > > > > > Help you, Help me >> > > > > >> > > >> -- Wei Yang Help you, Help me