From patchwork Thu Mar 26 07:02:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11459387 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 A5545913 for ; Thu, 26 Mar 2020 07:02:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7235120719 for ; Thu, 26 Mar 2020 07:02:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="S+rb2gtq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7235120719 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 113996B000C; Thu, 26 Mar 2020 03:02:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0C6DB6B000D; Thu, 26 Mar 2020 03:02:43 -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 F1D166B000E; Thu, 26 Mar 2020 03:02:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org 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 D54196B000C for ; Thu, 26 Mar 2020 03:02:42 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C81F2824934B for ; Thu, 26 Mar 2020 07:02:42 +0000 (UTC) X-FDA: 76636620564.01.truck78_17a38d6ccc537 X-Spam-Summary: 2,0,0,61ed57e028c1d67a,d41d8cd98f00b204,3kvn8xgykccqwalkengoogle.comlinux-mmkvack.org@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.210.201:@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:22,LUA_SUMMARY:none X-HE-Tag: truck78_17a38d6ccc537 X-Filterd-Recvd-Size: 5579 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Mar 2020 07:02:42 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id s8so4374379pfd.23 for ; Thu, 26 Mar 2020 00:02:42 -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=xxvyxjj91melXa2f3O0p5YGO5yfdIf2InM2lDPE9tIk=; b=S+rb2gtqH3Mle1QzHX8tBmJKYQt8IOQhCKT8GNmojRB6bUWcTc2zCtEYWPPOXh3raR KfZuAnS5qLywjBjfFSZFvlD52vx1ktBHNB1BFhpeqkugFuvfrI16BTHF0FtoUHxZ0dVp TQE6+Lykq+FwLKbyOHFBMTwlVg6LYtJquwrx3qIGfrIBCU8YK9i/h0LiHp2l6wRGigxz u4N/9klDmr3UAS3arA9uDAqhoxX+eqe6xy6jeIKwbl5GBEmcAVfJ2hWexeJYL1YyJfsv wCmSV830WdwO6IkvYg1rF0EXNVgfBv1p4nzSZZoY7E9hn1SdoY4nSiy8A2oQc4AgD8dE gCXA== 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=xxvyxjj91melXa2f3O0p5YGO5yfdIf2InM2lDPE9tIk=; b=GjbxgtB1PcCBf39LbfIJHIlJMRFAhkGoKFafMMeAa5VW/JEWrgv8Xc7WTIy5EPpE0L fxHqZVB+w6/pTq9CUl7j4mwTAfXU8LaNjdsPMZVqE6OetlQAuma4R3HGPZ1mAFZtaoCF j5xyXoZGeNQxUp5wxJpONZ+kYTEGpTwXR/Fb6Dwfoy7LR1E6HBSPIYYTBdqiBst70LIF bax2kt+3XTyQenVUcbORXLB08Whfw3azIhnNMcEfPnF+L8GDmVmqwkZhj/MlV7KVnu1O B3bl/imsG//8Pw4T1YUohhel0WVMfGjnNInMyShpuItByiTxtpJkzdO6lo+ka4iNwUjv psAg== X-Gm-Message-State: ANhLgQ1QYbrFiGFFOegmfjFu3EYqQs7+iGG1oaV4/yulpeCn4QZmhlG2 duKv0v8BNwPhA2kmfAK99fMOohiyaQw= X-Google-Smtp-Source: ADFU+vtNeNSXu+zk+G9qTMevsl/EO/OZ7hP+2bvX9a40agCXFI6f7Ltq/McjSMLAed50Ejoy3tAOmtow6I0= X-Received: by 2002:a17:90a:5d16:: with SMTP id s22mr1610999pji.118.1585206161146; Thu, 26 Mar 2020 00:02:41 -0700 (PDT) Date: Thu, 26 Mar 2020 00:02:29 -0700 In-Reply-To: <20200326070236.235835-1-walken@google.com> Message-Id: <20200326070236.235835-2-walken@google.com> Mime-Version: 1.0 References: <20200326070236.235835-1-walken@google.com> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog Subject: [PATCH 1/8] 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 , 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 */