From patchwork Thu Jul 12 07:36:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 942835 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41R78p6kQYz9s19 for ; Thu, 12 Jul 2018 17:38:34 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="H2pgq8oF"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41R78p5D2mzF35T for ; Thu, 12 Jul 2018 17:38:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="H2pgq8oF"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c01::241; helo=mail-pl0-x241.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="H2pgq8oF"; dkim-atps=neutral Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41R76h4z6ZzF35P for ; Thu, 12 Jul 2018 17:36:43 +1000 (AEST) Received: by mail-pl0-x241.google.com with SMTP id 31-v6so10317811plc.4 for ; Thu, 12 Jul 2018 00:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ghUSxcLT8+56FiqKCN6Yqqgm6Xx8XeRTIoYlQ+pa4mY=; b=H2pgq8oFJfDQyh0uyKgOp4I661UDXI62fc9eeVUpHr9NqcOgYq7SQRjDwg8GcVSqyD 0ce8GHNUNvon1ZByLzbcfUsRIV/Qj+WIpvRPtgOqdE7DCwEBqPFmJB7cHbjDWQQJs9ff bof3MRBftnR0ynLBPa51wbqU8lSARhXyc0Z7IglrgAU50bEVZCklAxbnDmVDLf/gu+f4 ZIxGVoPN5Sgm3isjVeXS6GqK6VqiJ2uzUmvvTvyDwdBHKZcuEyJZL5xg8GK3Jv51HcNQ Ph0HC1+Ok92egp4pNkQ50SRHqWLYuSECsqfeUdgL/ZXuax0G/3Y8EM0G0maZNykTJD7J ABkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ghUSxcLT8+56FiqKCN6Yqqgm6Xx8XeRTIoYlQ+pa4mY=; b=TOBcNENgiqz+GcDrrvkbYxjQEERmQv59b8QzN+zJ8WOa+Aj5yErzKl8hPPjTZZEXeg H7hepZ1LSkBsQHUfgLToDK9CH3U2jcR2sLCJzPK9rjZphcqz3wu2ajodCHF/xCe9a028 I/hRIeHiH7yfDETrHZi6++b4IFGSFebY02T4gawke/+nk74zpMZoiSoMBgV8AD8vNQLS e65D1oyIR6ZZZxEws0lANUA98NMPnBr86zj0h57sgT2XzJPyJ9WkmUtSbao5D1vaDDJO XNb2+GeB/leisBHxpLUk42z5L5t+QNXPTwFRH0wesBaZq2mC3XfgpChIwSLRyCK0HvDZ A4DQ== X-Gm-Message-State: AOUpUlEZ4QVylX42lZ1BOezdgBvtvj7Ssw9zE7MinTKXO3ycFDlOEwSO JEB5JknfcPGGLsrQfga4LuM= X-Google-Smtp-Source: AAOMgpcNXAW3oIY9o0hvER5dVOGSsZUqpalYMgZEmlX/zAAcdHirMicnjA2Z0vPfYvKcCEkhYvYyHQ== X-Received: by 2002:a17:902:6845:: with SMTP id f5-v6mr1079611pln.173.1531381001534; Thu, 12 Jul 2018 00:36:41 -0700 (PDT) Received: from roar.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id z8-v6sm36143283pfg.24.2018.07.12.00.36.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 00:36:40 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Subject: [RFC PATCH] mm: optimise pte dirty/accessed bits handling in fork Date: Thu, 12 Jul 2018 17:36:33 +1000 Message-Id: <20180712073633.1702-1-npiggin@gmail.com> X-Mailer: git-send-email 2.17.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" fork clears dirty/accessed bits from new ptes in the child, even though the mapping allows such accesses. This logic has existed for ~ever, and certainly well before physical page reclaim and cleaning was not strongly tied to pte access state as it is today. Now that is the case, this access bit clearing logic does not do much. Other than this case, Linux is "eager" to set dirty/accessed bits when setting up mappings, which avoids micro-faults (and page faults on CPUs that implement these bits in software). With this patch, there are no cases I could instrument where dirty/accessed bits do not match the access permissions without memory pressure (and without more exotic things like migration). This speeds up a fork/exit microbenchmark by about 5% on POWER9 (which uses a software fault fallback mechanism to set these bits). I expect x86 CPUs will barely be noticable, but would be interesting to see. Other archs might care more, and anyway it's always good if we can remove code and make things a bit faster. I don't *think* I'm missing anything fundamental, but would be good to be sure. Comments? Thanks, Nick --- mm/huge_memory.c | 4 ++-- mm/memory.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 1cd7c1a57a14..c1d41cad9aad 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -974,7 +974,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, pgtable_trans_huge_deposit(dst_mm, dst_pmd, pgtable); pmdp_set_wrprotect(src_mm, addr, src_pmd); - pmd = pmd_mkold(pmd_wrprotect(pmd)); + pmd = pmd_wrprotect(pmd); set_pmd_at(dst_mm, addr, dst_pmd, pmd); ret = 0; @@ -1065,7 +1065,7 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, } pudp_set_wrprotect(src_mm, addr, src_pud); - pud = pud_mkold(pud_wrprotect(pud)); + pud = pud_wrprotect(pud); set_pud_at(dst_mm, addr, dst_pud, pud); ret = 0; diff --git a/mm/memory.c b/mm/memory.c index 7206a634270b..3fea40da3a58 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1023,12 +1023,12 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, } /* - * If it's a shared mapping, mark it clean in - * the child + * Child inherits dirty and young bits from parent. There is no + * point clearing them because any cleaning or aging has to walk + * all ptes anyway, and it will notice the bits set in the parent. + * Leaving them set avoids stalls and even page faults on CPUs that + * handle these bits in software. */ - if (vm_flags & VM_SHARED) - pte = pte_mkclean(pte); - pte = pte_mkold(pte); page = vm_normal_page(vma, addr, pte); if (page) {