From patchwork Fri May 7 15:05:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12244857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 212F7C433B4 for ; Fri, 7 May 2021 15:06:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 982E761415 for ; Fri, 7 May 2021 15:06:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 982E761415 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 202178D0018; Fri, 7 May 2021 11:06:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A5108D0014; Fri, 7 May 2021 11:06:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 007F98D0018; Fri, 7 May 2021 11:06:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id D3E3B8D0014 for ; Fri, 7 May 2021 11:06:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8786A62E8 for ; Fri, 7 May 2021 15:06:05 +0000 (UTC) X-FDA: 78114760290.12.2444F12 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf16.hostedemail.com (Postfix) with ESMTP id A17EA8019389 for ; Fri, 7 May 2021 15:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620399964; h=from:from: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:in-reply-to:references:references; bh=XI4rD6YmuMtYUwEz0cLMaw9lo4eF56mgullQHfANGQM=; b=QDyK1KS+lof3PPleaoGWQSLRv2fXydb6eMXj6Cfnxlq58E1ThjvitByBAhLctPffD/KZtB em376+cMh+1uzPv/zFJQsdLB5aZI6ggJOVTUx+0ji2r/dmCvlS3uQ5kqK3TenhDrpPVXoE 87bE+THuEf1DMXOODunRAxtGeoQ5QdA= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-485-OjWT8c9JNzCeA5K1gJbUhw-1; Fri, 07 May 2021 11:06:03 -0400 X-MC-Unique: OjWT8c9JNzCeA5K1gJbUhw-1 Received: by mail-qk1-f199.google.com with SMTP id c4-20020a3781040000b02902e46e29acf5so6309071qkd.22 for ; Fri, 07 May 2021 08:06:03 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=XI4rD6YmuMtYUwEz0cLMaw9lo4eF56mgullQHfANGQM=; b=ZiSjGzEb3dnr4Lj2EMhYsq7oatmrV9WvRDtFGFW/5/vM9Wzx/rzlg4H+6Etb9AITD5 p4gqbEq/Ce5gqLwDf8/9nbLOmhzEFytIsF/f8KuSycdy+ZMP6D9YaY5frEjjS/OHNN7/ 1q/V1O2xWX4AaV3g4vQLXcNt6wznLyq071OEBcnh9qW1RgDYrvhWI4+2TIPQjx/hXIud ISzZhd1OoYna1nqfSjOWJbniaRrkK2FBmVpQw6FT9xffoMEqJ5zuFSIpnANKtgqplK4w 9+m9MAt+6wZFCYWz9QRFpKtSXitKWPEFQKhqeYBhfNRu/N/sCePGsMqkPtFvBYNL5VZv u0NQ== X-Gm-Message-State: AOAM532oAmt+iGP1rMo0nmsSMJGzDSMlMHCQ7Ub8HiA2SADjUJ/ECFIF psJVEPZoZBG38GEm00D585jsHOhRJR7oHkgn9NCWhxQNlVpGXUPO9PIWNPwv8+t01S45kAj5L35 NzQPM5/lp8IzkGfz9gRejbPwfFo8MTklJ+bfnmcsGdZ4Chpt5znDFHa5sYs5Y X-Received: by 2002:a05:6214:248e:: with SMTP id gi14mr10461281qvb.7.1620399962255; Fri, 07 May 2021 08:06:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB55PqZ+EcRjTPmnEKYJdh2C7Wh9UTwfVjNOoEAdmIkbA9ceUr6vcr1sJBVKD90XDiauZoLA== X-Received: by 2002:a05:6214:248e:: with SMTP id gi14mr10461232qvb.7.1620399961952; Fri, 07 May 2021 08:06:01 -0700 (PDT) Received: from t490s.redhat.com (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id c141sm950456qke.12.2021.05.07.08.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 08:06:01 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jan Kara , John Hubbard , peterx@redhat.com, Linus Torvalds , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Oleg Nesterov , Andrew Morton , Jann Horn , Andrea Arcangeli , Jason Gunthorpe , Matthew Wilcox , Hugh Dickins Subject: [PATCH v2 2/3] mm: gup: allow FOLL_PIN to scale in SMP Date: Fri, 7 May 2021 11:05:52 -0400 Message-Id: <20210507150553.208763-3-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507150553.208763-1-peterx@redhat.com> References: <20210507150553.208763-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QDyK1KS+; spf=none (imf16.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A17EA8019389 X-Stat-Signature: ory84f3j76xgrzp7wq8m3uwu5751mf47 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620399955-902508 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: From: Andrea Arcangeli has_pinned cannot be written by each pin-fast or it won't scale in SMP. This isn't "false sharing" strictly speaking (it's more like "true non-sharing"), but it creates the same SMP scalability bottleneck of "false sharing". To verify the improvement, below test is done on 40 cpus host with Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz (must be with CONFIG_GUP_TEST=y): $ sudo chrt -f 1 ./gup_test -a -m 512 -j 40 Where we can get (average value for 40 threads): Old kernel: 477729.97 (+- 3.79%) New kernel: 89144.65 (+-11.76%) On a similar condition with 256 cpus, this commits increases the SMP scalability of pin_user_pages_fast() executed by different threads of the same process by more than 4000%. Signed-off-by: Andrea Arcangeli [peterx: rewrite commit message, add parentheses against "(A & B)"] Reviewed-by: John Hubbard Signed-off-by: Peter Xu --- mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 63a079e361a3d..9933bc5c2eff2 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1292,7 +1292,7 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, BUG_ON(*locked != 1); } - if (flags & FOLL_PIN) + if ((flags & FOLL_PIN) && !atomic_read(&mm->has_pinned)) atomic_set(&mm->has_pinned, 1); /* @@ -2617,7 +2617,7 @@ static int internal_get_user_pages_fast(unsigned long start, FOLL_FAST_ONLY))) return -EINVAL; - if (gup_flags & FOLL_PIN) + if ((gup_flags & FOLL_PIN) && !atomic_read(¤t->mm->has_pinned)) atomic_set(¤t->mm->has_pinned, 1); if (!(gup_flags & FOLL_FAST_ONLY))