Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4312590pxj; Wed, 12 May 2021 02:51:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylZlBZimJM/cEKdPXVU1EjpTei80wlqgKvlKE9/IpvuvimqzI6TRMjcarujd+MaJSywQa6 X-Received: by 2002:a5e:a806:: with SMTP id c6mr12965125ioa.180.1620813065748; Wed, 12 May 2021 02:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620813065; cv=none; d=google.com; s=arc-20160816; b=zyKEsjZ4dw2xkdA/QOYMNTgzvn/1hSBUqMZmfErEy+qzjStWkfsF6ZerIy65A5jF4k pq57/Ibji2gjZfdrSqIIp9Xu6oMrrwUZfg3ypx9gYFnZCgW4Cn88OeegSdOJS/FRZvqe /hC30eh2sN/VbTUoa3zgwIx20QxEnI6wUV1BrtJmBXs3dHZmGfT2g9PIMP9YyFYeFD+9 Izo2LRhp8FWox0MaF9lDxG59Yh1wyeOc47MIlQErxW/dFtN7jCouu+6K+fxG4L2wHkCV FKlJLVh34uuFkOit9Otp0BYNr2XjS+vYoLnSgbIedPj0jcDWpjUenMb4DVhCfDjRY4qB nCMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GUt7kPgBJMN4yeVeOkrnQPhryLYrZDgrYjGs4lAolt0=; b=BpRPJa9vOI2fAX54fCgPgq6afvjPzFWXhRhqedhDGdoK6KfUly2AI6hFafnQzfCwmP vrSB2JMvy+c2yfFYuyaoNCJZE1w8jGp/Jjk2UfZg4kFNulGcl/mlnCht+fbF456TZLiG HzKqmrxM0ASdem5xESHHit5OsnRZB/WXq6xEYd/s2vgHy/kjTM5KTd7lh2m7s6NOwi/V coeKlKOG8iUcDinextJyhSb7VVdkpQc5MWP7h3exs22URI8nb2hmjRb889CVuQnklWX3 DVmG9mTdsG0MzWhI92srOuoUfNXkeHrkG9dVip39EUrbJYJGWaY477K3DgI6gYQYCdrt jSOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ny8mv3++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si2219110ili.90.2021.05.12.02.50.53; Wed, 12 May 2021 02:51:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ny8mv3++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbhELJvW (ORCPT + 99 others); Wed, 12 May 2021 05:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbhELJvT (ORCPT ); Wed, 12 May 2021 05:51:19 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92E62C061574 for ; Wed, 12 May 2021 02:50:09 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id k10so2838916ejj.8 for ; Wed, 12 May 2021 02:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GUt7kPgBJMN4yeVeOkrnQPhryLYrZDgrYjGs4lAolt0=; b=ny8mv3++m4i3B4RuxmYCDHFPZlicowKuAS8DYTUdpV+/w8b0YH+X604s0wwq/lCGyb DR8eoBJ0erFDUQLA3OXISUEEsuXm3Qn6YXjhTCR9ohPlny+kEmsvNAJoH0I2u/byDzPQ 1cSY5VjBECxKDVWnjy9nRoKB4cnb29GlY8tXoxiWTo+fai6eDqa8D5TiL7FfFE8tXE9c nbVvECz0MehXQkRQYmIoF6PlwprkF+LxUuReOEYb8HjkkxGSEMycPm1A2QSUSFSmusdu gDaoqJ4t9oDulXcRivGVbe7vO3W2gkOmCqV6bOi2QPctaaIzFy3z8GZpXikvFW9XOCcy isrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GUt7kPgBJMN4yeVeOkrnQPhryLYrZDgrYjGs4lAolt0=; b=bgtKperPderKjPVqzNbhe9FfrXOEWhn1d6qEmv1+jCitm/7g9Lyg/5VyJ8R2xP9xWW kPxbmc7TN79MrCKWXEprc3JlbpPJ1Ll1JfSswCV74qSkwRd2vkfTZtd4qs+6K4GPCmGC AIi+EnoPGZcB/bM2kSe503uvF6Akyy5WNjGoTAoUDt82EhVOxPBNdOqJw7RdGrcQHfKP CE3882jPu90UTcDJ3b6cngNW9Q8zH9vr4c51cbGvbHZddWLr0R6tI3Er6o+P16Mo1EtU gexetyUCrrZQI23Rqhl8xh+E+n4syR7N6A7EL4JIH7CsrgOjQDCWGDsYT3YVQcBJm7sF En2w== X-Gm-Message-State: AOAM53056Ey3DGctFkUwcEnO9m7+ef6J3AA2tcQzRaHlVd5Ee5Bxqu3t FINW61lPA+IbQweEDMOO1eXwnLznS9qfSEClYtJy7Q== X-Received: by 2002:a17:906:85da:: with SMTP id i26mr37086650ejy.287.1620813008025; Wed, 12 May 2021 02:50:08 -0700 (PDT) MIME-Version: 1.0 References: <20210507150553.208763-1-peterx@redhat.com> <20210507150553.208763-4-peterx@redhat.com> In-Reply-To: <20210507150553.208763-4-peterx@redhat.com> From: Naresh Kamboju Date: Wed, 12 May 2021 15:19:55 +0530 Message-ID: Subject: Re: [PATCH v2 3/3] mm: gup: pack has_pinned in MMF_HAS_PINNED To: Peter Xu , linux-mm , open list Cc: Jan Kara , John Hubbard , Linus Torvalds , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Oleg Nesterov , Andrew Morton , Jann Horn , Andrea Arcangeli , Jason Gunthorpe , Matthew Wilcox , Hugh Dickins , Linux-Next Mailing List , lkft-triage@lists.linaro.org, regressions@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 7 May 2021 at 20:36, Peter Xu wrote: > > From: Andrea Arcangeli > > has_pinned 32bit can be packed in the MMF_HAS_PINNED bit as a noop > cleanup. > > Any atomic_inc/dec to the mm cacheline shared by all threads in > pin-fast would reintroduce a loss of SMP scalability to pin-fast, so > there's no future potential usefulness to keep an atomic in the mm for > this. > > set_bit(MMF_HAS_PINNED) will be theoretically a bit slower than > WRITE_ONCE (atomic_set is equivalent to WRITE_ONCE), but the set_bit > (just like atomic_set after this commit) has to be still issued only > once per "mm", so the difference between the two will be lost in the > noise. > > will-it-scale "mmap2" shows no change in performance with enterprise > config as expected. > > will-it-scale "pin_fast" retains the > 4000% SMP scalability > performance improvement against upstream as expected. > > This is a noop as far as overall performance and SMP scalability are > concerned. > > Signed-off-by: Andrea Arcangeli > [peterx: Fix build for task_mmu.c, introduce mm_set_has_pinned_flag, fix > comment here and there] > Signed-off-by: Peter Xu > --- > fs/proc/task_mmu.c | 2 +- > include/linux/mm.h | 2 +- > include/linux/mm_types.h | 10 ---------- > include/linux/sched/coredump.h | 8 ++++++++ > kernel/fork.c | 1 - > mm/gup.c | 19 +++++++++++++++---- > 6 files changed, 25 insertions(+), 17 deletions(-) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 4c95cc57a66a8..6144571942db9 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -1049,7 +1049,7 @@ static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, > return false; > if (!is_cow_mapping(vma->vm_flags)) > return false; > - if (likely(!atomic_read(&vma->vm_mm->has_pinned))) > + if (likely(!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))) > return false; > page = vm_normal_page(vma, addr, pte); > if (!page) > diff --git a/include/linux/mm.h b/include/linux/mm.h > index d6790ab0cf575..94dc84f6d8658 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1331,7 +1331,7 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, > if (!is_cow_mapping(vma->vm_flags)) > return false; > > - if (!atomic_read(&vma->vm_mm->has_pinned)) > + if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags)) > return false; > > return page_maybe_dma_pinned(page); > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 6613b26a88946..15d79858fadbd 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -435,16 +435,6 @@ struct mm_struct { > */ > atomic_t mm_count; > > - /** > - * @has_pinned: Whether this mm has pinned any pages. This can > - * be either replaced in the future by @pinned_vm when it > - * becomes stable, or grow into a counter on its own. We're > - * aggresive on this bit now - even if the pinned pages were > - * unpinned later on, we'll still keep this bit set for the > - * lifecycle of this mm just for simplicity. > - */ > - atomic_t has_pinned; > - > /** > * @write_protect_seq: Locked when any thread is write > * protecting pages mapped by this mm to enforce a later COW, > diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h > index dfd82eab29025..4d9e3a6568758 100644 > --- a/include/linux/sched/coredump.h > +++ b/include/linux/sched/coredump.h > @@ -73,6 +73,14 @@ static inline int get_dumpable(struct mm_struct *mm) > #define MMF_OOM_VICTIM 25 /* mm is the oom victim */ > #define MMF_OOM_REAP_QUEUED 26 /* mm was queued for oom_reaper */ > #define MMF_MULTIPROCESS 27 /* mm is shared between processes */ > +/* > + * MMF_HAS_PINNED: Whether this mm has pinned any pages. This can be either > + * replaced in the future by mm.pinned_vm when it becomes stable, or grow into > + * a counter on its own. We're aggresive on this bit for now: even if the > + * pinned pages were unpinned later on, we'll still keep this bit set for the > + * lifecycle of this mm, just for simplicity. > + */ > +#define MMF_HAS_PINNED 28 /* FOLL_PIN has run, never cleared */ > #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) > > #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ > diff --git a/kernel/fork.c b/kernel/fork.c > index 502dc046fbc62..a71e73707ef59 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1026,7 +1026,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, > mm_pgtables_bytes_init(mm); > mm->map_count = 0; > mm->locked_vm = 0; > - atomic_set(&mm->has_pinned, 0); > atomic64_set(&mm->pinned_vm, 0); > memset(&mm->rss_stat, 0, sizeof(mm->rss_stat)); > spin_lock_init(&mm->page_table_lock); > diff --git a/mm/gup.c b/mm/gup.c > index 9933bc5c2eff2..bb130723a6717 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1270,6 +1270,17 @@ int fixup_user_fault(struct mm_struct *mm, > } > EXPORT_SYMBOL_GPL(fixup_user_fault); > > +/* > + * Set the MMF_HAS_PINNED if not set yet; after set it'll be there for the mm's > + * lifecycle. Avoid setting the bit unless necessary, or it might cause write > + * cache bouncing on large SMP machines for concurrent pinned gups. > + */ > +static inline void mm_set_has_pinned_flag(unsigned long *mm_flags) > +{ > + if (!test_bit(MMF_HAS_PINNED, mm_flags)) > + set_bit(MMF_HAS_PINNED, mm_flags); > +} > + > /* > * Please note that this function, unlike __get_user_pages will not > * return 0 for nr_pages > 0 without FOLL_NOWAIT > @@ -1292,8 +1303,8 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, > BUG_ON(*locked != 1); > } > > - if ((flags & FOLL_PIN) && !atomic_read(&mm->has_pinned)) > - atomic_set(&mm->has_pinned, 1); > + if (flags & FOLL_PIN) > + mm_set_has_pinned_flag(&mm->flags); > > /* > * FOLL_PIN and FOLL_GET are mutually exclusive. Traditional behavior > @@ -2617,8 +2628,8 @@ static int internal_get_user_pages_fast(unsigned long start, > FOLL_FAST_ONLY))) > return -EINVAL; > > - if ((gup_flags & FOLL_PIN) && !atomic_read(¤t->mm->has_pinned)) > - atomic_set(¤t->mm->has_pinned, 1); > + if (gup_flags & FOLL_PIN) > + mm_set_has_pinned_flag(¤t->mm->flags); Linux next tag next-20210512 builds failed on arm, riscv, mips and sh for the tinyconfig and allnoconfig due this patch. arm, mips, riscv and sh (tinyconfig) with gcc-8 arm, mips, riscv and sh (allnoconfig) with gcc-8 arm, mips, riscv and sh (tinyconfig) with gcc-9 arm, mips, riscv and sh (allnoconfig) with gcc-9 arm, mips, riscv and sh (tinyconfig) with gcc-10 arm, mips, riscv and sh (allnoconfig) with gcc-10 mm/gup.c: In function 'internal_get_user_pages_fast': mm/gup.c:2698:3: error: implicit declaration of function 'mm_set_has_pinned_flag' [-Werror=implicit-function-declaration] 2698 | mm_set_has_pinned_flag(¤t->mm->flags); | ^~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors make[2]: *** [/builds/linux/scripts/Makefile.build:273: mm/gup.o] Error 1 Reported-by: Naresh Kamboju #regzb introduced: 354a2e3604e2 ("mm: gup: pack has_pinned in MMF_HAS_PINNED") Build url: https://gitlab.com/Linaro/lkft/mirrors/next/linux-next/-/jobs/1255567072#L315 -- Linaro LKFT https://lkft.linaro.org