Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1203903rdg; Fri, 11 Aug 2023 13:18:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEuHyNKXJog9WMdrZ650/B96FhTo8Opxkx7Ut+GfHGNzxHk2jNGUNnmAge/5Z0qFkZbQFf X-Received: by 2002:a05:6a20:6a27:b0:125:3445:8af0 with SMTP id p39-20020a056a206a2700b0012534458af0mr3930600pzk.7.1691785105996; Fri, 11 Aug 2023 13:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691785105; cv=none; d=google.com; s=arc-20160816; b=fIkxH58pTwF2e5ne4h+jQzBnPaG4BrS6bJnDjq5xxqvn0o2NWXZd7H5V2jgNkPgScK UXrySBBA8fUHwNpGkcN1qnn0+XnUFl68ReVvI3FlC+8bsNYyrNccELi/hteC6bVIsIyV nJHKpKpHhDZKAdetAsqzIEjRwNuMqh2svXeQCXqSRL+EZFVMDmdrQLQJVGcY+QmH3Bs0 c6CT7wMIEWUfEtu+VWJV6oJXP2Btcx6QSEaA/HACPVigs8K7ljjqWzqdHyKoNnFmj84U 6H7oW2pK8OwBVZGuQ7nCGeh2FXtxwnM8zWF0a2XSROyglQ3l3LKBkpuFabq6LdrZOLuR U36Q== 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=udOAodw9Sp/fQ0KA1HXOY7J2RZn1MApSNI+uu4NPPqA=; fh=oQJfh+Vr4T6Dbl3+mbv1Iadpbiax+AEVFgc4RYmtzn0=; b=l6J2uOVUajS7bles6BxXtV3/o36AytSyLwkaWcSEt7yG4PptV7NGjnWzMuQgADeqO2 FSyZSzP5vlCF/Xlj1pFI/UBS9MQDf6nw0lt2XfjSCuyZy/DriRZbYZTT0b0LG+QFb/PW nHx27JPMHkH0cM/I6qqc0PG21Zpu7WyeXspIchV6Jk1Hod+G8/GSaPRbFInp0LcSw2fk fj1YSOKlWPmc0Q4a2oqap9Pr5lGDgN4nFlasK4O/S9tBe4kUlKhHwstBu16PtDfq+eGA degwq0XsHqQcVn43vR1356Wo2zDYCVJ0TZEBfLkLJS6pvVaa4HdOUQWNEQ03E0b3803a EbYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Bi4s8ZUx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o6-20020a056a001bc600b0067ea74ba1fbsi3806142pfw.328.2023.08.11.13.18.14; Fri, 11 Aug 2023 13:18:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Bi4s8ZUx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237092AbjHKSJu (ORCPT + 99 others); Fri, 11 Aug 2023 14:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237055AbjHKSJa (ORCPT ); Fri, 11 Aug 2023 14:09:30 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10E4D3AAA; Fri, 11 Aug 2023 11:09:16 -0700 (PDT) Received: from localhost.localdomain (unknown [39.34.188.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 2486B6607241; Fri, 11 Aug 2023 19:09:08 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1691777354; bh=7wAlmE+MzDeaGz9osyt5wCh2xslRMfPiu1SThBUhQac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bi4s8ZUxD/XbLeOh9j9UWgYkVRqzpgRfLvJPObe5XKxLolN4+Xd0wR3M2ZUyjTB2g LTqv49r1PAZPB34452wFykeZPme1Vo74xr/xre7VH7bSo9vcIFUX+JzylihfsK3vij SYTT+XIuzBH7VFHOjDFe2SxAxXc/wRWdI8xsm6JetFL4j9cTGHhwe77LyRR1gpmFmI BaRPkcMn9WbY5ejCbcnGvKOv2a6fvMkS7mkoIUlpmGtRs9fEdPDN1sUh6ipledeT/0 DY7sIPOCRid91b+FABkbg5gGwU5IAgMh0zbZwFEpZOptzM8eiaHQ13g6XJySnNVUbs KRHOEpqxgivhg== From: Muhammad Usama Anjum To: Peter Xu , David Hildenbrand , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andrei Vagin , Danylo Mocherniuk , Paul Gofman , Cyrill Gorcunov , Mike Rapoport , Nadav Amit Cc: Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Suren Baghdasaryan , Alex Sierra , Muhammad Usama Anjum , Matthew Wilcox , Pasha Tatashin , Axel Rasmussen , "Gustavo A . R . Silva" , Dan Williams , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Greg KH , kernel@collabora.com Subject: [PATCH v29 3/6] fs/proc/task_mmu: Add fast paths to get/clear PAGE_IS_WRITTEN flag Date: Fri, 11 Aug 2023 23:08:39 +0500 Message-Id: <20230811180842.3141781-4-usama.anjum@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230811180842.3141781-1-usama.anjum@collabora.com> References: <20230811180842.3141781-1-usama.anjum@collabora.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,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 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 5271c634d2dc8..0ea0ed9ec704e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2113,6 +2113,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)); @@ -2136,6 +2171,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); -- 2.40.1