From patchwork Wed Apr 22 00:14:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11502543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23A5C13B2 for ; Wed, 22 Apr 2020 00:14:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB61320575 for ; Wed, 22 Apr 2020 00:14:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fmE/ZsCi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB61320575 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 146998E0006; Tue, 21 Apr 2020 20:14:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 11E488E0003; Tue, 21 Apr 2020 20:14:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00D0A8E0006; Tue, 21 Apr 2020 20:14:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id DE8228E0003 for ; Tue, 21 Apr 2020 20:14:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 943B4349B for ; Wed, 22 Apr 2020 00:14:28 +0000 (UTC) X-FDA: 76733569416.17.train51_44253e60fd014 X-Spam-Summary: 2,0,0,dde60d17105def64,d41d8cd98f00b204,3y4yfxgykcpqswhgajckkcha.ykihejqt-iigrwyg.knc@flex--walken.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3870:3872:4321:4605:5007:6261:6653:6742:9969:10004:10400:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12555:12683:12895:12986:13149:13230:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:21990:30054:30064:30070:30090,0,RBL:209.85.210.201:@flex--walken.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: train51_44253e60fd014 X-Filterd-Recvd-Size: 5682 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 00:14:28 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id i128so564445pfc.4 for ; Tue, 21 Apr 2020 17:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=nj5jjGLg8IOvfnegjPnvO+hyr9F+Q3RFMzb65ktIqNg=; b=fmE/ZsCi12txej32MKxq5Q/M7SA+tr6q8bMHrxgAjcjNoXH82uOrxQ9hl0ksM/ez4f NPLpdNrNChzGenZ8mx71A3vcq8jSr23SjXXSs5JSrE1GiF3Gsd6gEiJ2zvEY29rNj2ac xIllsk8xqc1Z6k8VjXIaMEhazT8cisE6MUOlrpJfwmVX+L6xMjPj9HolikYBgotuYvcW r0Xde8JijOIxT99M4Wus0Ohme4Xh2bv5zz0NuyF5tAK8i+s1Pn1Dh7mc5uPWIz7CSOik LwX9Fi9+pGvkXqovzI6v/aNLkyYs+BMwHT6PMjF03zESDlDCfQEAZ1wd/Mm8hiPnuzBI q6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nj5jjGLg8IOvfnegjPnvO+hyr9F+Q3RFMzb65ktIqNg=; b=j6a1bS4c8cPa3SIi/ZSBVgmA95A703jQkXjuPSo8A7P2Td8wtzQx3ffONeXetuSD4t fit7xSIc0NKysYfYSUhg3y4LMh6D5u8z275d2k/yB+FFkbr1CxOsh9GWF/91vZ9rwLXL lsfPDgNwctGiJ6LhCQhldW0+AMlGN/BkZqCTJsOusjvCE4+8TxmN1dmjCBo+vKpi9AiO xFYEnxGBlBBQLCqrmsaPt6Q11goS+FuHsNl3ETU2Qp5pIliibyab3XFmPX2dd9APTEW9 MRershNBZ8qeCrAZY+QvFijj+RMjOt8tWZShMm8zTs+tSdc0hOEuQ+Zi2hpk5xBGTPxr HIdg== X-Gm-Message-State: AGi0PubbFOvZdhFMEY2NB4qcyGylsJakQnjnWuemPql/q+VPH2eM4Oan DE2NrDGx3QeJNA3G/BGV1dxx854j2dQ= X-Google-Smtp-Source: APiQypKlcSekBVajTIOBnih7IYmBCRTnYXbk0AAJ5N3mmuCItzToA2KSG7ErlRz3OGA48q1hRqMoFhPcOY0= X-Received: by 2002:a17:90a:276a:: with SMTP id o97mr8625466pje.194.1587514467186; Tue, 21 Apr 2020 17:14:27 -0700 (PDT) Date: Tue, 21 Apr 2020 17:14:13 -0700 In-Reply-To: <20200422001422.232330-1-walken@google.com> Message-Id: <20200422001422.232330-2-walken@google.com> Mime-Version: 1.0 References: <20200422001422.232330-1-walken@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v5 01/10] mmap locking API: initial implementation as rwsem wrappers From: Michel Lespinasse To: Andrew Morton , linux-mm Cc: LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han , Jason Gunthorpe , Daniel Jordan , Michel Lespinasse , Davidlohr Bueso 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: This change wraps the existing mmap_sem related rwsem calls into a new mmap locking API. There are two justifications for the new API: - At first, it provides an easy hooking point to instrument mmap_sem locking latencies independently of any other rwsems. - In the future, it may be a starting point for replacing the rwsem implementation with a different one, such as range locks. Signed-off-by: Michel Lespinasse Reviewed-by: Daniel Jordan Reviewed-by: Davidlohr Bueso Reviewed-by: Vlastimil Babka Reviewed-by: Laurent Dufour --- include/linux/mm.h | 1 + include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 include/linux/mmap_lock.h diff --git a/include/linux/mm.h b/include/linux/mm.h index 5a323422d783..051ec782bdbb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h new file mode 100644 index 000000000000..97ac53b66052 --- /dev/null +++ b/include/linux/mmap_lock.h @@ -0,0 +1,54 @@ +#ifndef _LINUX_MMAP_LOCK_H +#define _LINUX_MMAP_LOCK_H + +static inline void mmap_init_lock(struct mm_struct *mm) +{ + init_rwsem(&mm->mmap_sem); +} + +static inline void mmap_write_lock(struct mm_struct *mm) +{ + down_write(&mm->mmap_sem); +} + +static inline int mmap_write_lock_killable(struct mm_struct *mm) +{ + return down_write_killable(&mm->mmap_sem); +} + +static inline bool mmap_write_trylock(struct mm_struct *mm) +{ + return down_write_trylock(&mm->mmap_sem) != 0; +} + +static inline void mmap_write_unlock(struct mm_struct *mm) +{ + up_write(&mm->mmap_sem); +} + +static inline void mmap_write_downgrade(struct mm_struct *mm) +{ + downgrade_write(&mm->mmap_sem); +} + +static inline void mmap_read_lock(struct mm_struct *mm) +{ + down_read(&mm->mmap_sem); +} + +static inline int mmap_read_lock_killable(struct mm_struct *mm) +{ + return down_read_killable(&mm->mmap_sem); +} + +static inline bool mmap_read_trylock(struct mm_struct *mm) +{ + return down_read_trylock(&mm->mmap_sem) != 0; +} + +static inline void mmap_read_unlock(struct mm_struct *mm) +{ + up_read(&mm->mmap_sem); +} + +#endif /* _LINUX_MMAP_LOCK_H */