From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35A6BC4167B for ; Mon, 27 Nov 2023 09:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NO9psg8RWufpOec3wxCAlo9lFtmIkwj9yt7K+rXVWzE=; b=OrTmXVwMTpBMic g4i53O6ej9prKWgKtLbG1fQBQdbgnGs0tG0Qwfbl7n80cZT5+JEg5/TxuXDfQ55VEx7Pbtv3GvhyV FBYHyTjTmpLFkxec6F6JkDIJ47LHcodATHqLZbSQvvQk+t+A+6AACptSJxIxvDc0ko8xT/COQX2p6 zE2k1FTOQ9pvVyFn4d1BuEk3jndeHpGbBhM3pLI2nyHrjp/t6aYYJ9fOvVZOJJyqVfGqYq9dCty0L PpiwSgCqmDeOr0sZjliQWKP7APV6ssQLmYdcZTtCp6ZRtp5QPQBPHIVn2RSszBdBY3zA17IKDgC/e lbI8RUg1NV/epM7TIf1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7Y24-001zFA-2W; Mon, 27 Nov 2023 09:36:00 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7Y20-001zE3-2f for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 09:35:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 954202F4; Mon, 27 Nov 2023 01:36:41 -0800 (PST) Received: from [10.57.73.191] (unknown [10.57.73.191]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A92323F6C4; Mon, 27 Nov 2023 01:35:50 -0800 (PST) Message-ID: Date: Mon, 27 Nov 2023 09:35:49 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 01/14] mm: Batch-copy PTE ranges during fork() Content-Language: en-GB To: Barry Song <21cnbao@gmail.com>, david@redhat.com Cc: akpm@linux-foundation.org, andreyknvl@gmail.com, anshuman.khandual@arm.com, ardb@kernel.org, catalin.marinas@arm.com, dvyukov@google.com, glider@google.com, james.morse@arm.com, jhubbard@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, ryabinin.a.a@gmail.com, suzuki.poulose@arm.com, vincenzo.frascino@arm.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yuzenghui@huawei.com, yuzhao@google.com, ziy@nvidia.com References: <271f1e98-6217-4b40-bae0-0ac9fe5851cb@redhat.com> <20231127084217.13110-1-v-songbaohua@oppo.com> From: Ryan Roberts In-Reply-To: <20231127084217.13110-1-v-songbaohua@oppo.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231127_013556_957666_EF6CDF8E X-CRM114-Status: GOOD ( 25.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 27/11/2023 08:42, Barry Song wrote: >>> + for (i = 0; i < nr; i++, page++) { >>> + if (anon) { >>> + /* >>> + * If this page may have been pinned by the >>> + * parent process, copy the page immediately for >>> + * the child so that we'll always guarantee the >>> + * pinned page won't be randomly replaced in the >>> + * future. >>> + */ >>> + if (unlikely(page_try_dup_anon_rmap( >>> + page, false, src_vma))) { >>> + if (i != 0) >>> + break; >>> + /* Page may be pinned, we have to copy. */ >>> + return copy_present_page( >>> + dst_vma, src_vma, dst_pte, >>> + src_pte, addr, rss, prealloc, >>> + page); >>> + } >>> + rss[MM_ANONPAGES]++; >>> + VM_BUG_ON(PageAnonExclusive(page)); >>> + } else { >>> + page_dup_file_rmap(page, false); >>> + rss[mm_counter_file(page)]++; >>> + } >>> } >>> - rss[MM_ANONPAGES]++; >>> - } else if (page) { >>> - folio_get(folio); >>> - page_dup_file_rmap(page, false); >>> - rss[mm_counter_file(page)]++; >>> + >>> + nr = i; >>> + folio_ref_add(folio, nr); >> >> You're changing the order of mapcount vs. refcount increment. Don't. >> Make sure your refcount >= mapcount. >> >> You can do that easily by doing the folio_ref_add(folio, nr) first and >> then decrementing in case of error accordingly. Errors due to pinned >> pages are the corner case. >> >> I'll note that it will make a lot of sense to have batch variants of >> page_try_dup_anon_rmap() and page_dup_file_rmap(). >> > > i still don't understand why it is not a entire map+1, but an increment > in each basepage. Because we are PTE-mapping the folio, we have to account each individual page. If we accounted the entire folio, where would we unaccount it? Each page can be unmapped individually (e.g. munmap() part of the folio) so need to account each page. When PMD mapping, the whole thing is either mapped or unmapped, and its atomic, so we can account the entire thing. > > as long as it is a CONTPTE large folio, there is no much difference with > PMD-mapped large folio. it has all the chance to be DoubleMap and need > split. > > When A and B share a CONTPTE large folio, we do madvise(DONTNEED) or any > similar things on a part of the large folio in process A, > > this large folio will have partially mapped subpage in A (all CONTPE bits > in all subpages need to be removed though we only unmap a part of the > large folioas HW requires consistent CONTPTEs); and it has entire map in > process B(all PTEs are still CONPTES in process B). > > isn't it more sensible for this large folios to have entire_map = 0(for > process B), and subpages which are still mapped in process A has map_count > =0? (start from -1). > >> Especially, the batch variant of page_try_dup_anon_rmap() would only >> check once if the folio maybe pinned, and in that case, you can simply >> drop all references again. So you either have all or no ptes to process, >> which makes that code easier. I'm afraid this doesn't make sense to me. Perhaps I've misunderstood. But fundamentally you can only use entire_mapcount if its only possible to map and unmap the whole folio atomically. >> >> But that can be added on top, and I'll happily do that. >> >> -- >> Cheers, >> >> David / dhildenb > > Thanks > Barry > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel