Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp317016rdb; Fri, 6 Oct 2023 04:41:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaKdy778M9hRCHyimKpki9CEAEBR97LCBpfl4XfU3bllV1vKwd1XD1mXLr8fD4S+hcA6aC X-Received: by 2002:a05:6e02:164f:b0:351:57d5:51bb with SMTP id v15-20020a056e02164f00b0035157d551bbmr10249928ilu.16.1696592483028; Fri, 06 Oct 2023 04:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696592482; cv=none; d=google.com; s=arc-20160816; b=NFiR2AkRsn4lzepuLfMfUmsGpyEb07qEHHvt3NqtbDvoVbzYTflo0/i6Ayq1iUTGIM 7JHsEhL/GT9QkZsnJuwJgd1+OUk7w1syuOj4EuuYUn1UWN5UlesmUzADjXoCgl+dUa6i rnHKj82WJG5Kh1P8lDjOps9Fio7q9vUvY5t4jbj3cmHEd7aIyPomvHoa3UKWv5WCnIo1 0lCpzvt7Z9psGm9PCWUimU0eNNk07qT1y+ExzWy9brFAZ1bfiKj65iJ/ZZ9x2OE2pkoK FfGvpDeyaZ49iQuGkL9j0r22rn2yzjo9vewiE+sIbqTW5OEwOYoMtYhllGWfnYeLeF53 WVFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=HQUiHj6dje7lPqHjRDRBwEFbgBxgHOFLAxZg6oKVnSU=; fh=THVqzqKFh8b5nFt7lFbgY2frScbvAVG101yTqIPQL0U=; b=CN4i8t0hBi6toZkTmL+R3aFZWSlHWqNLIV5DcoP+FEGVhTye4JaDe0QtuCA+N1QO6A WNiGC00dgViGHS87Jl/nL3Qylu5RlB4EVVCdf4nWGngbBMrQlG8WttTnZ4/PzFF7YUt2 gFp043BL3RRDEDjTVOCn1m/nf+Mva8Zhr1Hzcw3PJ+t8JBi1CH+ZoqNWkCaiGFZLvKpN UbieeEl7z3IIv4CrkuOb7E8yc2J5U525qU7NYl9sByzvbkbaaY0kgLLAwoPsBkg9uC3V amdbxDpaj8eMehygDWTfOAszO5kI+Hxg138/O6tElZwojHh1mqUcUuujA55X/6W9o8zF VMEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hTcn1xm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00578a56baebesi1356014pgb.674.2023.10.06.04.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 04:41:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hTcn1xm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 574CC81552C4; Fri, 6 Oct 2023 04:41:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230503AbjJFLlF (ORCPT + 99 others); Fri, 6 Oct 2023 07:41:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232091AbjJFLlD (ORCPT ); Fri, 6 Oct 2023 07:41:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A11B5DB for ; Fri, 6 Oct 2023 04:41:00 -0700 (PDT) Received: from [192.168.100.7] (unknown [39.34.184.141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4D75C6612A7A; Fri, 6 Oct 2023 12:40:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1696592459; bh=ZDyYuG9iSvl4sm1CTET1n1lNwYdeHLIPj4SXX+NUK/4=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=hTcn1xm8hsOadKSXGJ7C16RQBesuRfTM+rbFhkg0MhpPV7TbjMG82uTihjmH4Iqmb wktBPSS7ZVIab05IHstdZaZCxO0HC+yV0VGAhknzWhXW/UHDe6dvHR75bgW4J0jsiQ DsfIahZU0ggwi1WUFXVgohISM4URzSgWLlT1P0JFIUXRQfhhAe2N1AJ9UlGeSeBJDG 0YxwHUYaDMxRTJA1EHeAUuIO2hgmyjcGBIraZcVtXz5KxMnZeDEKjho0e2dML78f3f fP2/Ggmzw8Fsyaz2b3i2UlWRCsyTQX/QkhdyOAbTrTU7Bwva98IQqTGjb5tNK2hVEl q5EkrWCFTkuQg== Message-ID: <6cee3838-1807-4983-9d7f-b3a30ee30563@collabora.com> Date: Fri, 6 Oct 2023 16:40:53 +0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel@collabora.com, Paul Gofman Subject: Re: [PATCH v33 3/6] fs/proc/task_mmu: Add fast paths to get/clear PAGE_IS_WRITTEN flag Content-Language: en-US To: Andrew Morton , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrei Vagin References: <20230821141518.870589-1-usama.anjum@collabora.com> <20230821141518.870589-4-usama.anjum@collabora.com> From: Muhammad Usama Anjum In-Reply-To: <20230821141518.870589-4-usama.anjum@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 06 Oct 2023 04:41:20 -0700 (PDT) X-Spam-Level: ** Hi Andrew, You picked up all the other patches in this series except this one. Thank you so much. I'm unable to find any comment on why this wasn't picked or maybe you missed it? Please let me know what you think. Regards, Usama On 8/21/23 7:15 PM, Muhammad Usama Anjum wrote: > Adding fast code paths to handle specifically only get and/or clear > operation of PAGE_IS_WRITTEN, increases its performance by 0-35%. > The results of some test cases are given below: > > Test-case-1 > t1 = (Get + WP) time > t2 = WP time > t1 t2 > Without this patch: 140-170mcs 90-115mcs > With this patch: 110mcs 80mcs > Worst case diff: 35% faster 30% faster > > Test-case-2 > t3 = atomic Get and WP > t3 > Without this patch: 120-140mcs > With this patch: 100-110mcs > Worst case diff: 21% faster > > Signed-off-by: Muhammad Usama Anjum > --- > The test to measure the performance can be found: https://is.gd/FtSKcD > 8 8192 3 1 0 and 8 8192 3 1 1 arguments have been used to produce the > above mentioned results. > > Changes in v29: > - Minor updates in flush logic following the original patch > --- > fs/proc/task_mmu.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 6e6261e8b91b1..79cf023148b28 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -2138,6 +2138,41 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start, > return 0; > } > > + if (!p->vec_out) { > + /* Fast path for performing exclusive WP */ > + for (addr = start; addr != end; pte++, addr += PAGE_SIZE) { > + if (pte_uffd_wp(ptep_get(pte))) > + continue; > + make_uffd_wp_pte(vma, addr, pte); > + if (!flush_end) > + start = addr; > + flush_end = addr + PAGE_SIZE; > + } > + goto flush_and_return; > + } > + > + if (!p->arg.category_anyof_mask && !p->arg.category_inverted && > + p->arg.category_mask == PAGE_IS_WRITTEN && > + p->arg.return_mask == PAGE_IS_WRITTEN) { > + for (addr = start; addr < end; pte++, addr += PAGE_SIZE) { > + unsigned long next = addr + PAGE_SIZE; > + > + if (pte_uffd_wp(ptep_get(pte))) > + continue; > + ret = pagemap_scan_output(p->cur_vma_category | PAGE_IS_WRITTEN, > + p, addr, &next); > + if (next == addr) > + break; > + if (~p->arg.flags & PM_SCAN_WP_MATCHING) > + continue; > + make_uffd_wp_pte(vma, addr, pte); > + if (!flush_end) > + start = addr; > + flush_end = next; > + } > + goto flush_and_return; > + } > + > for (addr = start; addr != end; pte++, addr += PAGE_SIZE) { > unsigned long categories = p->cur_vma_category | > pagemap_page_category(p, vma, addr, ptep_get(pte)); > @@ -2161,6 +2196,7 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start, > flush_end = next; > } > > +flush_and_return: > if (flush_end) > flush_tlb_range(vma, start, addr); > -- BR, Muhammad Usama Anjum