Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2878034rdh; Mon, 27 Nov 2023 00:42:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFywm+Ziy3w4j9wdgsk0ImJ8PxH3qmmF5d7mdILpVErCXkBIM4/bHbij4RWw8AfIjM8Tyz8 X-Received: by 2002:a05:6a00:c94:b0:6cd:8436:dfc with SMTP id a20-20020a056a000c9400b006cd84360dfcmr7062620pfv.12.1701074576585; Mon, 27 Nov 2023 00:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701074576; cv=none; d=google.com; s=arc-20160816; b=e+mfrmselAJU7dKNT3q6fcU1AE0HWIoGtMEVifuAtjQ6EKy8HmK5rEt7dexTtQqa+9 BUyJhMMN40R9anLHyoPP5UyMLQB9DNc7lK6WaV8oMlnABWvR3o0lbtzJPX2jHFVJh8Pp wJTsyBy8qxX/p/1N52xmOqXAMqO5Qz+jHZ5AmKWxG8cgNiqPvoCdzPdiD+cFLsdh8aBQ 9HFARSo7UFi81mft/TqZyfO4Df6YqRKvmpNcwzhvIAJjnAzrgGfebVYERy6fV9EoMvSt aoSbZ4093ebiU6vt70I1gkUG+BfJr7OGQtK2br2PPbAvYXqFuAUKn+Awygs40LPSVfUN mhjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v7ud2f7/LRWS8b7jsTlmNHZSCAPClBeQfNhzDqsVBoE=; fh=OErSqA4TKixt+oewFKfUQJrDYCKlnRs2+2ZfLO4yS3M=; b=SdsXbDVkDN7OzrA+Fu3B4U7dmwzo86XdRn00R/B8isNkU5QApNkCiO/7ipSf0trKaP nlBb2cijYdyKuH22SriUTE1q18gT7mKuEMpI0xSX9pP1CtkBg8m/DWKuFv9lWrD0h0hu 7jdA69HF6+puiQ8zeHEFyv0gJwkG2Tn8p9sRl5GjJ6HuUXRiJRl0tUsZoRoJQcWMKi0E rNTNhoY9Us7M9DH18SSrtxNjEwHABMRbWJPCo+dRnV6VWEh6WGm4ClruZk8siuK2xIse /GUIdUu0HA3xwc0VVeUZ2eHOjld9DGkVJtTja4UnHa5ka0NXyE1JMvCG5eB7lPjp8EI6 uZDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BjI9HlXS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d5-20020a056a00244500b006cb88a16f29si9048461pfj.161.2023.11.27.00.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 00:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BjI9HlXS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 83A82806895F; Mon, 27 Nov 2023 00:42:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232433AbjK0Imf (ORCPT + 99 others); Mon, 27 Nov 2023 03:42:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbjK0Ime (ORCPT ); Mon, 27 Nov 2023 03:42:34 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87A85B8 for ; Mon, 27 Nov 2023 00:42:40 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1cfafe3d46bso16997625ad.0 for ; Mon, 27 Nov 2023 00:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701074560; x=1701679360; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v7ud2f7/LRWS8b7jsTlmNHZSCAPClBeQfNhzDqsVBoE=; b=BjI9HlXSXYW68RCUj8t97pWOIQT4m5Vwfm97/oy4jzUMWoJ5UlccYkKuwbaMaBWDYs 1/TwMbjXe/CBTox7i8MPtFE8a22y7Gh6Ocwuh1+EFXHnINk3uFfcvEhGhj976w5JMXhp owiccDhIBEFJYdpEUOTMxrlkFONkNcN+aXk2Zse67HRNr3ktMM7Fd2/NohcxPefzcHyC VhlgS3trRWyEKCden6r2PA57lnY6P36QmCcz4h36WAPYwFf+4FrwVKiVVTdsl+43w1Rs uI1fposNt1XST00KZwbmPS7gJ9eDcTkOM9tiCl8MNcsQTdIm7lAQHXVl01S8M4FcMU1/ yyHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701074560; x=1701679360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v7ud2f7/LRWS8b7jsTlmNHZSCAPClBeQfNhzDqsVBoE=; b=HH0/V7wB+oeiw18rUVI0HeAPeJRo7UdqlSy0N+48km7xrKm5NlfxSdSINcmC4PCjEs AoQxS+LLq/E7VqiKawYXWKBpqirGlojCHsjQtebEwHMIVGQeh10Mfk+hIA/pNxF8yLao CRUg+M6EixrZPoheHPPQZU50uIfmmWUCQxiUjFowvIWUBxqN2qJu7AD3NcHP5rOrx2Dk ouYBoSC+MuaZjGi9biM3sV4g7OSqLvS6zxW08fDOEsEDAHH1JI+48hsaAhe82ZEHntp5 AygvFFrVBClEAQqr8KhinAI1/YhrlJPvEHXioF+oQ1DsKhEBrMbCBCnEAI0NA3wlrfzp 5PTg== X-Gm-Message-State: AOJu0YwFR8afzdQwO+htmo2rqHBFjiE0l5ynkgwG5Fm34WpsZt3qxUJU ciMHUDF6GjQxjxOyzX0IOeA= X-Received: by 2002:a17:90a:195e:b0:285:2d62:84c4 with SMTP id 30-20020a17090a195e00b002852d6284c4mr12413569pjh.29.1701074559970; Mon, 27 Nov 2023 00:42:39 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:19a0:3eee:b37f:15f2]) by smtp.gmail.com with ESMTPSA id mp21-20020a17090b191500b002801ca4fad2sm7276883pjb.10.2023.11.27.00.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 00:42:39 -0800 (PST) From: Barry Song <21cnbao@gmail.com> X-Google-Original-From: Barry Song To: 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, ryan.roberts@arm.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 Subject: Re: Re: [PATCH v2 01/14] mm: Batch-copy PTE ranges during fork() Date: Mon, 27 Nov 2023 21:42:17 +1300 Message-Id: <20231127084217.13110-1-v-songbaohua@oppo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <271f1e98-6217-4b40-bae0-0ac9fe5851cb@redhat.com> References: <271f1e98-6217-4b40-bae0-0ac9fe5851cb@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 00:42:55 -0800 (PST) >> + 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. 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. > > But that can be added on top, and I'll happily do that. > > -- > Cheers, > > David / dhildenb Thanks Barry