From patchwork Fri Mar 27 02:10:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11461547 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 34F9815AB for ; Fri, 27 Mar 2020 02:11:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED49F2074D for ; Fri, 27 Mar 2020 02:11:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ctQS9IVG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED49F2074D 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 8881A6B0032; Thu, 26 Mar 2020 22:11:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 813D76B0036; Thu, 26 Mar 2020 22:11:05 -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 6B1DE6B0037; Thu, 26 Mar 2020 22:11:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id 53A0A6B0032 for ; Thu, 26 Mar 2020 22:11:05 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3DA23485C for ; Fri, 27 Mar 2020 02:11:05 +0000 (UTC) X-FDA: 76639514490.04.pear67_9762f823c71a X-Spam-Summary: 2,0,0,b254c9609fc5994d,d41d8cd98f00b204,3t2b9xgykcggcgrqktmuumrk.iusrotad-ssqbgiq.uxm@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:30070:30090,0,RBL:209.85.215.202:@flex--walken.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.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:24,LUA_SUMMARY:none X-HE-Tag: pear67_9762f823c71a X-Filterd-Recvd-Size: 5663 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 02:11:04 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id q15so6649247pgb.4 for ; Thu, 26 Mar 2020 19:11:04 -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=k3mg/Xv1vow8pC5LkbfxQBusgzgffIOWBI4VPXD50U0=; b=ctQS9IVGYiGEW7rl+HmsBcEN7a8KNQhybe0fatUUL80bnaVg07X0r4Z76JZLH6V0Mo XpfvBX77aacV8cFXAYg4+Enm8dakUMTe6Jv/0It0M5CK6Md1vNkyHlw0PYEOEhWdxQfz L8HIXNoIstB3xK67EM/3psplE6E57IGlmG8eGLyJ4HmPHXi978x5J1W/b+DOuhyajt3I FVyCRvmzmXKduPC4z/1rKsUD1MRGkDiPDkXBsjsNCOsGSQtBpZ+Piv47z+PRwUzDv4Go +wAIo9kqMzgIoh50ZgkmbqZSye8yDI8U/MrFVTzz+Ovs4miWa7OAzcBRRT1yYqsAdPXn ue+g== 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=k3mg/Xv1vow8pC5LkbfxQBusgzgffIOWBI4VPXD50U0=; b=Toq5YXH9/smr/tfP8kie+HbrXvxT22GNbHSvYu+Jqgmh5FYRN/1TCakjhGy28Gb1sf jHSFwJjMr7PB3yiIG7uLRboOWORDdrTEj1r77Qci+vBTrN1NibE2AeYiQQhPZorJ41yk zxhcd5GZDzpFGdLQ5JsXuCMJxnfQW1qM0TkjS/JIkK1rfBzaxrVMtaIPQM+V9vrUM7gW HjU/R0KMvBetsKl+Prnc1YF4yO+ChxTMwRpzyEfWK5aCqW4AcjW2/WifhcAhw/cqSQr6 n9ROH9Y7+eCVs8y7bR2HjZ2KxPYHiRR7Hk9rhLEWzYM5p7E44MX13eMSc1QfLI7WambC GUYw== X-Gm-Message-State: ANhLgQ2TIqTuuq2vGxbiPrwJ8Vszc2A7q4nI28C8k7sSj//hC8fly91h uCja9L2BHjhL18gJe4CHwCJDd4zcZ58= X-Google-Smtp-Source: ADFU+vsFGah9Sh4ZVgJlSbmDCL6eph1s6ibCkBkTza6XI3kWyCX6f4qL10bauS5CGXkC8UgYhDMAiiQFlwI= X-Received: by 2002:a65:4d09:: with SMTP id i9mr10912905pgt.403.1585275063502; Thu, 26 Mar 2020 19:11:03 -0700 (PDT) Date: Thu, 26 Mar 2020 19:10:49 -0700 In-Reply-To: <20200327021058.221911-1-walken@google.com> Message-Id: <20200327021058.221911-2-walken@google.com> Mime-Version: 1.0 References: <20200327021058.221911-1-walken@google.com> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH v2 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 , Markus Elfring , Michel Lespinasse 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 --- include/linux/mm.h | 1 + include/linux/mmap_lock.h | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 include/linux/mmap_lock.h diff --git a/include/linux/mm.h b/include/linux/mm.h index c54fb96cb1e6..2f13c9198999 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..cffd25afe92b --- /dev/null +++ b/include/linux/mmap_lock.h @@ -0,0 +1,59 @@ +#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_downgrade_write_lock(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); +} + +static inline bool mmap_is_locked(struct mm_struct *mm) +{ + return rwsem_is_locked(&mm->mmap_sem) != 0; +} + +#endif /* _LINUX_MMAP_LOCK_H */