Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp468037rdb; Sat, 19 Aug 2023 08:52:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbavEVVnEO3773q5RzKO6ob+O4JbVGHoTnDZRAkCqV5jihmgb87vcVF8J0Gmf7Sfc+oWbB X-Received: by 2002:a17:902:ec90:b0:1b8:95fc:cfe with SMTP id x16-20020a170902ec9000b001b895fc0cfemr2748547plg.3.1692460345691; Sat, 19 Aug 2023 08:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692460345; cv=none; d=google.com; s=arc-20160816; b=sLzem+bfuCKRgyCB7QM9eRwpswG+q31aiMmrnNNt2wQSZJGhmq+fqa8T3ax6YFjGhe zzmtMr4DqW4Vrq5iHPThVysfYzDUZ7cMX91zAsh9v5baB+vEsL3DxkUyv7BtLO6bTzZC UH8eF5N6IG7beZlkTgZeaQy6QTwDssz57Qe86ZV99FQiwRbmNbIvfaaibqovRwuENuSi Xfurci1fIZG7otPd//cTB1rN6DDyNod9FwgvIaKouSQz0yaWWEYm7BwIq3fe3MP3+dJh 9kkMEiunRJ6UYrCjHgPzEOnsPVebx0bcmE4gd3ap1JQDhzQgL66PtOIr6rPvZ7sTBl5a SelQ== 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=aupv4Osr23tQQq4NUI1NThpiJdDFUJxB8yneoQ8eK1s=; fh=olrCKEVUnBJ3kP9svP8S2bynd9m2cfHLySob6MO4J1w=; b=z2kiKmIpgNXXZTe6pjnZkB+bx6g6S3EpBJB2Uf08VJhzWZcB5S98iG4RmfWkfOSWF8 cl2aNq8ZJLuG4EQPvqjELoEEAQvuIku9K6Klh+ujEZofNvpYzrMxOqbuDmkyb7ZdskLe YxCrdlSGp0p7OnQxsvs5+YE5rfausl+mTD/1TGXGRlT8mPQ2NCx+kIr6iL58UVJR4Fpe xnP0imW2g2AxtmiI/NkDDuhnV5Tb4LBx9vQE5Kj9zXbZouQX5y6rjcvgQSmnRI/mwHtU dKtBp1y+dzITmE7G2P+Gl0ZLASQ4BwT85ReTqyyTtPqgIa5A+NTqzJGsCdvMfxWlacy8 qvmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oSNP7gKX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g20-20020a170902c99400b001bb7b3e607dsi3469027plc.21.2023.08.19.08.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 08:52:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oSNP7gKX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6FF0AF6FC3; Sat, 19 Aug 2023 01:49:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242273AbjHPHAd (ORCPT + 99 others); Wed, 16 Aug 2023 03:00:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242276AbjHPHAN (ORCPT ); Wed, 16 Aug 2023 03:00:13 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84A3D1FDE; Wed, 16 Aug 2023 00:00:11 -0700 (PDT) Received: from localhost.localdomain (unknown [59.103.216.185]) (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 806C866071EF; Wed, 16 Aug 2023 08:00:03 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1692169209; bh=GFsfhkI7UzF7ZObA4nY+Wso9xSyJvqRpJakdhSPHC9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oSNP7gKXWWaPuaJPO1LhtAFzHiavOK725v1n523UCGg8gd3uZt0E+w3lMWC/ALt/q 8jAMMwlOGLL7m4gTiqZ6Tq9jofOtsMeCxdJ1o7wBHogjwWhzoYce7v5HYzg/I05Cag 7NbZ90UDugQZIc809yVKTQ8WZt/dfj7BNrUMIrUFZhMgrgotwPEV6nAgXIa8hXzlpS k88XOFfJ7HeK8op61Yh6MV3uIbRqb0oc8kPN3x9lvH9ZqGwpFCu4cZ1YZt4JXbun0y WTeeJW4MuZHI7VBwRwaX1zS9kb5guLBCCyrDV8s2Ch3ETmegJ79Cebf4kKmGHOMC/T 1OGuC9T7DKGqA== From: Muhammad Usama Anjum To: Peter Xu , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andrei Vagin , Danylo Mocherniuk , Paul Gofman 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, Cyrill Gorcunov , Mike Rapoport , Nadav Amit , David Hildenbrand Subject: [PATCH v30 3/6] fs/proc/task_mmu: Add fast paths to get/clear PAGE_IS_WRITTEN flag Date: Wed, 16 Aug 2023 11:59:22 +0500 Message-Id: <20230816065925.850879-4-usama.anjum@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230816065925.850879-1-usama.anjum@collabora.com> References: <20230816065925.850879-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,RCVD_IN_DNSWL_BLOCKED, 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 5f073aea1fcfc..ebf26684cf28c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2121,6 +2121,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)); @@ -2144,6 +2179,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