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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF09C0015E for ; Fri, 28 Jul 2023 09:16:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 181D98D0002; Fri, 28 Jul 2023 05:16:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 131946B007B; Fri, 28 Jul 2023 05:16:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3B168D0002; Fri, 28 Jul 2023 05:16:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E34916B0078 for ; Fri, 28 Jul 2023 05:16:41 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A7DCC40385 for ; Fri, 28 Jul 2023 09:16:41 +0000 (UTC) X-FDA: 81060465402.20.0561640 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id A19B9180018 for ; Fri, 28 Jul 2023 09:16:39 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690535799; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=spvSSPujjhykQfRCGOgwTP3LB4gvdPkdL4dh2Z/YdbU=; b=tpKi+WV0E/ZBhXX6zb4UG9T94FZ7aOMAbYZmTWlWCwsVWmkcdUwCCaedbcYPs2KhBMf1z3 xtHzkmHEEv2UI71VoR9DyXOTz4/FF4j/31NFvXSanUbSXJXQ6AWOP5aajNk60/CawsOTy8 HUt2FVbTsjHcCoGcafBPep9T0C/LEUY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690535799; a=rsa-sha256; cv=none; b=oWoBP2xrN2Vmn9V5HEzToaxaiiGDu1t6DlhaYjrQnYdzJ7pyTJLIV70pUIFur9N1b8/jSN 4V9gdUtnVbzOwYDvgtZ+1Os3zZ6oFz2qCAmeTIUlwzsg6iQ5m1uKANpKlmJimwbqBqmQ4W FheYrueteveB2Xe0f1vvenB5V6qwhwQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com 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 B8B42D75; Fri, 28 Jul 2023 02:17:21 -0700 (PDT) Received: from [10.57.77.173] (unknown [10.57.77.173]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8985D3F67D; Fri, 28 Jul 2023 02:16:36 -0700 (PDT) Message-ID: <9b54e5af-af1a-6741-424b-6c667d0b405b@arm.com> Date: Fri, 28 Jul 2023 10:16:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4 3/3] mm: Batch-zap large anonymous folio PTE mappings To: Yu Zhao , Matthew Wilcox , David Hildenbrand Cc: Andrew Morton , Yin Fengwei , Yang Shi , "Huang, Ying" , Zi Yan , Nathan Chancellor , Alexander Gordeev , Gerald Schaefer , linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230727141837.3386072-1-ryan.roberts@arm.com> <20230727141837.3386072-4-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Stat-Signature: afqsbrho3zomqbyspo4aer914rini1k4 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A19B9180018 X-Rspam-User: X-HE-Tag: 1690535799-713565 X-HE-Meta: U2FsdGVkX1+0yjS5qQJxfI5p2wV0BLxlrlgenRUrTRvbcEwQoM4T54f7fuMWNumEBtJq7Kd5ys2dDmOCrPCLUTlf4DNQQkpU7HogPPqMJJYQGkpeYV5SyTnu6Tubrdfs0u+A2qIyvzuwUFFOuM4Bzo7ZDzKLqGarDvdcPFg4Aykcd8Lg+7TTh5imnLd0Z7ld0RSnFV9Tjz+qV0zOk0wi+WSMqowF/EXDSsmW33ZBpKaupATwI6xwPfr/BICh08S+sYgaDbAIeVaGWIyzbLeyatNLHQ1dLwqeuJfyg8AoxCcsb7+BUL56suELvS10nkofWMszcfRbu8W4PNgb/c6MrkGw45FsrvKjB6z4/AB10XnztokUNF1Enz/ZefHqtslRkl1/5TanOEPxB61mBS5QZKTJRBR5bHHE6Ipokr+IzGWd3ylK9ALjE4Xrficz0m97gdrk81yooLQpMFqqilIZnLzuW7owrXygxlTTSw6H/Sow7zA9Y8ZJeYt7qQuxHXwh2TxfO+X/FoRBitQ6/OYN354h55OwRozYnBv//cp0rAmA8Wl1RnZp8Z8tnyTq/aZ1AntdKMCfaHstM8VDqUnIujBdP+BodR6uppMfknUHNJ442VSvAz2/N/RIy1JKlc2JfK0veUcuQa+R9Xp2v+gfoWdRA/FgXPg41FogjvR0mqnhJ2Fwm36Ijk+KK23vtwwQN5/C2vkuJRPuhsjDufuw9I2ImTqEgI7O9SZPAAct7laZOl6wON2kelF82ZdoBZ7eUH0W1atfh//fZqBmJDbmxibZtVISTEFHBx2lD0oQpl7KhqgF0C+C08+BqPNrlrH3HeVHu4AGb4nW0ZwxopuaY45Mn87pBvWXzhFa7zy+RBHnD9zOWYyUPeT8jky+y8jqZffxUALBDTRAWXmKVOU+jDp93T79FKpUYDsUBr8TF3DjNP+1dYJfgxVAQiomOQYf6jTvwYp26QDohEU3WgO DEL4HhMw mq8vTVh8AkZwF2zfCW2lmWjUbNoJsLW9lSmapK1bc1jsWTp4ftZi4bGhzPrjFQU0/BneIakv7UJDtqqtV86K6TV+mmmKIekvtYZ5AQ4S/k5z72NkMGDQ+b4U0dTpZ0xZpSceTxvcsScnQsD+7vkt4xPt750ZQNQxm7oR87E9KcDGThVQ= 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: On 27/07/2023 18:22, Yu Zhao wrote: > On Thu, Jul 27, 2023 at 8:18 AM Ryan Roberts wrote: >> >> This allows batching the rmap removal with folio_remove_rmap_range(), >> which means we avoid spuriously adding a partially unmapped folio to the >> deferred split queue in the common case, which reduces split queue lock >> contention. >> >> Previously each page was removed from the rmap individually with >> page_remove_rmap(). If the first page belonged to a large folio, this >> would cause page_remove_rmap() to conclude that the folio was now >> partially mapped and add the folio to the deferred split queue. But >> subsequent calls would cause the folio to become fully unmapped, meaning >> there is no value to adding it to the split queue. >> >> A complicating factor is that for platforms where MMU_GATHER_NO_GATHER >> is enabled (e.g. s390), __tlb_remove_page() drops a reference to the >> page. This means that the folio reference count could drop to zero while >> still in use (i.e. before folio_remove_rmap_range() is called). This >> does not happen on other platforms because the actual page freeing is >> deferred. >> >> Solve this by appropriately getting/putting the folio to guarrantee it >> does not get freed early. Given the need to get/put the folio in the >> batch path, we stick to the non-batched path if the folio is not large. >> While the batched path is functionally correct for a folio with 1 page, >> it is unlikely to be as efficient as the existing non-batched path in >> this case. >> >> Signed-off-by: Ryan Roberts > > This ad hoc patch looks unacceptable to me: we can't afford to keep > adding special cases. > > I vote for completely converting zap_pte_range() to use > folio_remove_rmap_range(), and that includes tlb_flush_rmap_batch() > and other types of large folios, not just anon. The intent of the change is to avoid the deferred split queue lock contention, and this is only a problem for anon folios; page cache folios are never split in this way. My intention was to do the smallest change to solve the problem. I don't see the value in reworking a much bigger piece of the code, making it more complex, when its not going to give any clear perf benefits. Otherwise I'll leave > it to Matthew and David. If there is concensus that this is _required_ in order to merge this series, then I guess I'll bite the bullet and do it. But my preference is to leave it for if/when a reason is found that it is actually bringing benefit.