From patchwork Wed Mar 27 09:08:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13605994 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 909ABC54E67 for ; Wed, 27 Mar 2024 09:08:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE1F66B0088; Wed, 27 Mar 2024 05:08:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D92116B0089; Wed, 27 Mar 2024 05:08:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C58C96B008A; Wed, 27 Mar 2024 05:08:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B35396B0088 for ; Wed, 27 Mar 2024 05:08:48 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76E1EC0B47 for ; Wed, 27 Mar 2024 09:08:48 +0000 (UTC) X-FDA: 81942243936.14.4E7D9EF Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf23.hostedemail.com (Postfix) with ESMTP id 4F7CF14001A for ; Wed, 27 Mar 2024 09:08:45 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711530526; 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: references; bh=XOJGcSTUE+NHqjyvKIF1rQ7JLjl43/BxOx6otz0ZCvo=; b=c7IKvkjg5HrweuCGnGHaL2EsvR8pW4J49egOuTEc19sEOzar28kKo3kXEjJCN6qE3lGXqa Sr9LhEg2spZnAtv5hzlQtHZPG3vVnFVJEa+u7f3K7ss63eIriRyXrN7j9qhMC/5qjzF5MS G4ZBTev1MXizTcBY8CYGLFvchN+NO2w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711530526; a=rsa-sha256; cv=none; b=friEW8uV+SY+gG5RZ8mJc9ruTDJbV/3nmDpZBXpktevjplWCso3072MtWoEuvo95qIq+2C MS51p9UEZIVQ23HoKwY76Gg/Dowcq+kMyh8MhBlELp3nJ7yB+SzQu+0L+T6lAgi/96jyYJ FtzOdjaxiVNMNfq9Afp9DbjbkP0bHAk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4V4LQB0LQgz1xsqX; Wed, 27 Mar 2024 17:06:42 +0800 (CST) Received: from kwepemm600020.china.huawei.com (unknown [7.193.23.147]) by mail.maildlp.com (Postfix) with ESMTPS id 69422180062; Wed, 27 Mar 2024 17:08:42 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 27 Mar 2024 17:08:41 +0800 From: Peng Zhang To: , CC: , , , , , , , , Subject: [PATCH] userfaultfd: early return in dup_userfaultfd() Date: Wed, 27 Mar 2024 17:08:35 +0800 Message-ID: <20240327090835.3232629-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600020.china.huawei.com (7.193.23.147) X-Rspamd-Queue-Id: 4F7CF14001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: wr7515un9ti8uu1wn71j6ggt9bhyowhk X-HE-Tag: 1711530525-70412 X-HE-Meta: U2FsdGVkX1/AC09R8WZJ18STOYafT0g0DlPup8GjDEDno4cJWmPzSewCGKW5flrt00Y833xxIdOUukDDescrj0EtoM4ax4jEwZSNJLrFNOqZBia4IQG9TQSJMTCqUuQAEEuTOEwselNNx/Wg+BEMrR6iYeLXe7F4P87ElEz01EicHduToun5mZpLDWPrlm+sa0iTonUesZx3yIcge3TkABFyTBIXIlzO+jqFboPXiOjg26pApmJtLBHDAPvsBcXFPD6klpz5E8gHO1qvm7ZpHusuGG/z69jr3qWyQHAKCxCMaNtQuAWmcsOAJUH8nc1QBTkfjN3MNjDJ3AHVOXJxL8EDvLCGf5Lq6IzqJOaAcW7+9i6va2a1k0TPSx1nVEFNR5RAi+sGPJw3PhYr30vuj4hU7TOyNlSe2smmj004JcVNblWtDBW6NtAeGejbcNdYG+1MZxD+X6XEGlSZscq08xUAY9RTMsomEGDQ+RMsjBnMt09xZ59Eh1gUrInH34jlzuEvnmmAZJ5K1RbJytQzlataVOGaSGENM/6AUYTFv22/bTgeZ4tBXxMdz2OxSiPQn7M4hyqUqJaORvnpRL9KkmRlLsOTI9XTcsNuec5oXUWK3oKrk0ku8A/xm6GYD3ZHV+oRJb+I0aUyuU75l5yz4hZpTdft9VvZOTi2NmCNqWQtFcc4y8LThjcGmd5uVvC0OWNgVbnthezvfYYt25LyI8B4OF/XenyoGkwIMJ4dfIwOmmwgIP8BWNufSX2GemWNxUIMVolEG6ANEd9LNehs72RF4MW9nzI34G798IrOlrnWbzslMOofTUlZs+ln/R2MockPjEb4G7vl3w9nE1SYiFxreQ32OP8VgPz6XxGSH3DNjOmdyen826Nnt2Md5VfXBLb+CdaRnQ+vE+nNY5NT3Q== 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: List-Subscribe: List-Unsubscribe: From: ZhangPeng When vma->vm_userfaultfd_ctx.ctx is NULL, vma->vm_flags should have cleared __VM_UFFD_FLAGS. Therefore, there is no need to down_write or clear the flag, which will affect fork performance. Fix this by returning early if octx is NULL in dup_userfaultfd(). By applying this patch we can get a 1.3% performance improvement for lmbench fork_prot. Results are as follows: base early return Process fork+exit: 419.1106 413.4804 Signed-off-by: ZhangPeng --- fs/userfaultfd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 60dcfafdc11a..3e6ddda6f159 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -657,7 +657,10 @@ int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs) struct userfaultfd_fork_ctx *fctx; octx = vma->vm_userfaultfd_ctx.ctx; - if (!octx || !(octx->features & UFFD_FEATURE_EVENT_FORK)) { + if (!octx) + return 0; + + if (!(octx->features & UFFD_FEATURE_EVENT_FORK)) { vma_start_write(vma); vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; userfaultfd_set_vm_flags(vma, vma->vm_flags & ~__VM_UFFD_FLAGS);